Veja todas as novas funções do WordPress 3.7
A cada nova versão do WordPress, novas funções interessantes vão surgindo. Vamos ver TODAS as novas funções do WordPress?
A explicação de cada uma está em inglês, mas aos poucos vamos traduzindo para vocês 😉
find_core_auto_updates
Gets the best available (and enabled) Auto-Update for WordPress Core.
If there’s 1.2.3 and 1.3 on offer, it’ll choose 1.3 if the install allows it, else, 1.2.3
Retorno
(boolean|array) False on failure, otherwise the core update offering.
Função no Core
function find_core_auto_update() {
$updates = get_site_transient( ‘update_core’ );
if ( ! $updates || empty( $updates->updates ) )
return false;include_once ABSPATH . ‘wp-admin/includes/class-wp-upgrader.php’;
$auto_update = false;
$upgrader = new WP_Automatic_Updater;
foreach ( $updates->updates as $update ) {
if ( ‘autoupdate’ != $update->response )
continue;if ( ! $upgrader->should_update( ‘core’, $update, ABSPATH ) )
continue;if ( ! $auto_update || version_compare( $update->current, $auto_update->current, ‘>’ ) )
$auto_update = $update;
}
return $auto_update;
}
Localização no Core
get_adjacent_post_link
Get adjacent post link.
Can be either next post link or previous.
Argumentos
(string) $format
(string) $link
(bool) $in_same_cat = false
(array|string) $excluded_categories = ”
(bool) $previous = true
Retorno
(string)
Função no Core
function get_adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = ”, $previous = true ) {
if ( $previous && is_attachment() )
$post = get_post( get_post()->post_parent );
else
$post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous );if ( ! $post ) {
$output = ”;
} else {
$title = $post->post_title;if ( empty( $post->post_title ) )
$title = $previous ? __( ‘Previous Post’ ) : __( ‘Next Post’ );/** This filter is documented in wp-includes/post-template.php */
$title = apply_filters( ‘the_title’, $title, $post->ID );
$date = mysql2date( get_option( ‘date_format’ ), $post->post_date );
$rel = $previous ? ‘prev’ : ‘next’;$string = ”;
$inlink = str_replace( ‘%title’, $title, $link );
$inlink = str_replace( ‘%date’, $date, $inlink );
$inlink = $string . $inlink . ”;$output = str_replace( ‘%link’, $inlink, $format );
}$adjacent = $previous ? ‘previous’ : ‘next’;
return apply_filters( “{$adjacent}_post_link”, $output, $format, $link, $post );
}
Localização no Core
get_core_checksums
Gets and caches the checksums for the given version of WordPress.
Argumentos
(string) $version
(string) $locale
Retorno
(boolean|array) False on failure. An array of checksums on success.
Função no Core
function get_core_checksums( $version, $locale ) {
$return = array();$url = $http_url = ‘https://api.wordpress.org/core/checksums/1.0/?’ . http_build_query( compact( ‘version’, ‘locale’ ), null, ‘&’ );
if ( $ssl = wp_http_supports( array( ‘ssl’ ) ) )
$url = set_url_scheme( $url, ‘https’ );$options = array(
‘timeout’ => ( ( defined(‘DOING_CRON’) && DOING_CRON ) ? 30 : 3 ),
);$response = wp_remote_get( $url, $options );
if ( $ssl && is_wp_error( $response ) ) {
trigger_error( __( ‘An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.’ ) . ‘ ‘ . ‘(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)’, headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE );
$response = wp_remote_get( $http_url, $options );
}if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
return false;$body = trim( wp_remote_retrieve_body( $response ) );
$body = json_decode( $body, true );if ( ! is_array( $body ) || ! isset( $body[‘checksums’] ) || ! is_array( $body[‘checksums’] ) )
return false;return $body[‘checksums’];
}
Localização no Core
get_next_post_link
Get previous post link that is adjacent to the current post.
Argumentos
(string) $format = ‘« %link’
(string) $link = ‘%title’
(bool) $in_same_cat = false
(string) $excluded_categories = ”
Retorno
(string)
Função no Core
function get_next_post_link( $format = ‘« %link’, $link = ‘%title’, $in_same_cat = false, $excluded_categories = ” ) {
return get_adjacent_post_link( $format, $link, $in_same_cat, $excluded_categories, false );
}
Localização no Core
get_post_type_archive_template
Retrieve path of post type archive template in current or parent template.
Retorno
(string)
Função no Core
function get_post_type_archive_template() {
$post_type = get_query_var( ‘post_type’ );
if ( is_array( $post_type ) )
$post_type = reset( $post_type );$obj = get_post_type_object( $post_type );
if ( ! $obj->has_archive )
return ”;return get_archive_template();
}
Localização no Core
got_url_rewrite
Returns whether the server supports URL rewriting.
Detects Apache’s mod_rewrite, IIS 7.0+ permalink support, and nginx.
Retorno
(boolean) Whether the server supports URL rewriting.
Função no Core
function got_url_rewrite() {
$got_url_rewrite = ( got_mod_rewrite() || $GLOBALS[‘is_nginx’] || iis7_supports_permalinks() );/**
* Filter whether URL rewriting is available.
*
* @since 3.7.0
* @param bool $got_url_rewrite Whether URL rewriting is available.
*/
return apply_filters( ‘got_url_rewrite’, $got_url_rewrite );
}
Localização no Core
is_main_network
Argumentos
(int) $network_id = null
Retorno
(boolean) True if $network_id is the main network, or if not running multisite.
Função no Core
function is_main_network( $network_id = null ) {
global $current_site, $wpdb;if ( ! is_multisite() )
return true;$current_network_id = (int) $current_site->id;
if ( ! $network_id )
$network_id = $current_network_id;
$network_id = (int) $network_id;if ( defined( ‘PRIMARY_NETWORK_ID’ ) )
return $network_id === (int) PRIMARY_NETWORK_ID;if ( 1 === $current_network_id )
return $network_id === $current_network_id;$primary_network_id = (int) wp_cache_get( ‘primary_network_id’, ‘site-options’ );
if ( $primary_network_id )
return $network_id === $primary_network_id;$primary_network_id = (int) $wpdb->get_var( “SELECT id FROM $wpdb->site ORDER BY id LIMIT 1” );
wp_cache_add( ‘primary_network_id’, $primary_network_id, ‘site-options’ );return $network_id === $primary_network_id;
}
Localização no Core
mbstring_binary_safe_encoding
Sets the mbstring internal encoding to a binary safe encoding whne func_overload is enabled.
When mbstring.func_overload is in use for multi-byte encodings, the results from strlen() and similar functions respect the utf8 characters, causing binary data to return incorrect lengths.
This function overrides the mbstring encoding to a binary-safe encoding, and resets it to the users expected encoding afterwards through the `reset_mbstring_encoding` function.
It is safe to recursively call this function, however each `mbstring_binary_safe_encoding()` call must be followed up with an equal number of `reset_mbstring_encoding()` calls.
Argumentos
(bool) $reset = false
Retorno
(void)
Função no Core
function mbstring_binary_safe_encoding( $reset = false ) {
static $encodings = array();
static $overloaded = null;if ( is_null( $overloaded ) )
$overloaded = function_exists( ‘mb_internal_encoding’ ) && ( ini_get( ‘mbstring.func_overload’ ) & 2 );if ( false === $overloaded )
return;if ( ! $reset ) {
$encoding = mb_internal_encoding();
array_push( $encodings, $encoding );
mb_internal_encoding( ‘ISO-8859-1’ );
}if ( $reset && $encodings ) {
$encoding = array_pop( $encodings );
mb_internal_encoding( $encoding );
}
}
Localização no Core
reset_mbstring_encoding
Resets the mbstring internal encoding to a users previously set encoding.
Retorno
(void)
Função no Core
function reset_mbstring_encoding() {
mbstring_binary_safe_encoding( true );
}
Localização no Core
unregister_taxonomy_for_object_type
Remove an already registered taxonomy from an object type.
Argumentos
(string) $taxonomy
(string) $object_type
Retorno
(boolean) True if successful, false if not.
Função no Core
function unregister_taxonomy_for_object_type( $taxonomy, $object_type ) {
global $wp_taxonomies;if ( ! isset( $wp_taxonomies[ $taxonomy ] ) )
return false;if ( ! get_post_type_object( $object_type ) )
return false;$key = array_search( $object_type, $wp_taxonomies[ $taxonomy ]->object_type, true );
if ( false === $key )
return false;unset( $wp_taxonomies[ $taxonomy ]->object_type[ $key ] );
return true;
}
Localização no Core
verify_file_md5
Calculates and compares the MD5 of a file to it’s expected value.
Argumentos
(string) $filename
(string) $expected_md5
Retorno
(boolean|object) WP_Error on failure, true on success, false when the MD5 format is unknown/unexpected
Função no Core
function verify_file_md5( $filename, $expected_md5 ) {
if ( 32 == strlen( $expected_md5 ) )
$expected_raw_md5 = pack( ‘H*’, $expected_md5 );
elseif ( 24 == strlen( $expected_md5 ) )
$expected_raw_md5 = base64_decode( $expected_md5 );
else
return false; // unknown format$file_md5 = md5_file( $filename, true );
if ( $file_md5 === $expected_raw_md5 )
return true;return new WP_Error( ‘md5_mismatch’, sprintf( __( ‘The checksum of the file (%1$s) does not match the expected checksum value (%2$s).’ ), bin2hex( $file_md5 ), bin2hex( $expected_raw_md5 ) ) );
}
Localização no Core
wp_authenticate_spam_check
For multisite blogs, check if the authenticated user has been marked as a spammer, or if the user’s primary blog has been marked as spam.
Argumentos
$user
Retorno
(void))
Função no Core
function wp_authenticate_spam_check( $user ) {
if ( $user && is_a( $user, ‘WP_User’ ) && is_multisite() ) {
$spammed = apply_filters( ‘check_is_user_spammed’, is_user_spammy(), $user );if ( $spammed )
return new WP_Error( ‘spammer_account’, __( ‘ERROR: Your account has been marked as a spammer.’ ) );
}
return $user;
}
Localização no Core
wp_clean_plugins_cache
Clears the Plugins cache used by get_plugins() and by default, the Plugin Update cache.
Argumentos
(bool) $clear_update_cache = true
Retorno
(void)
Função no Core
function wp_clean_plugins_cache( $clear_update_cache = true ) {
if ( $clear_update_cache )
delete_site_transient( ‘update_plugins’ );
wp_cache_delete( ‘plugins’, ‘plugins’ );
}
Localização no Core
wp_extract_urls
Use RegEx to extract URLs from arbitrary content
Argumentos
(string) $content
Retorno
(array) URLs found in passed string
Função no Core
function wp_extract_urls( $content ) {
preg_match_all(
“#((?:[\w-]+://?|[\w\d]+[.])[^\s()<>]+[.](?:\([\w\d]+\)|(?:[^`!()\[\]{};:’\”.,<>?«»“”‘’\s]|(?:[:]\d+)?/?)+))#”,
$content,
$post_links
);$post_links = array_unique( array_map( ‘html_entity_decode’, $post_links[0] ) );
return array_values( $post_links );
}
Localização no Core
wp_get_installed_translations
Get installed translations.
Argumentos
(string) $type
Retorno
(array) Array of language data.
Função no Core
function wp_get_installed_translations( $type ) {
if ( $type !== ‘themes’ && $type !== ‘plugins’ && $type !== ‘core’ )
return array();$dir = ‘core’ === $type ? ” : “/$type”;
if ( ! is_dir( WP_LANG_DIR ) )
return array();if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) )
return array();$files = scandir( WP_LANG_DIR . $dir );
if ( ! $files )
return array();$language_data = array();
foreach ( $files as $file ) {
if ( ‘.’ === $file[0] || is_dir( $file ) )
continue;
if ( substr( $file, -3 ) !== ‘.po’ )
continue;
if ( ! preg_match( ‘/(?:(.+)-)?([A-Za-z_]{2,6}).po/’, $file, $match ) )
continue;list( , $textdomain, $language ) = $match;
if ( ” === $textdomain )
$textdomain = ‘default’;
$language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . “$dir/$file” );
}
return $language_data;
}
Localização no Core
wp_get_pomo_file_data
Extract headers from a PO file.
Argumentos
(string) $po_file
Retorno
(array) PO file headers.
Função no Core
function wp_get_pomo_file_data( $po_file ) {
$headers = get_file_data( $po_file, array(
‘POT-Creation-Date’ => ‘”POT-Creation-Date’,
‘PO-Revision-Date’ => ‘”PO-Revision-Date’,
‘Project-Id-Version’ => ‘”Project-Id-Version’,
‘X-Generator’ => ‘”X-Generator’,
) );
foreach ( $headers as $header => $value ) {
// Remove possible contextual ‘\n’ and closing double quote.
$headers[ $header ] = preg_replace( ‘~(\\\n)?”$~’, ”, $value );
}
return $headers;
}
Localização no Core
wp_get_translation_updates
Retrieves a list of all language updates available.
Retorno
(void)
Função no Core
function wp_get_translation_updates() {
$updates = array();
$transients = array( ‘update_core’ => ‘core’, ‘update_plugins’ => ‘plugin’, ‘update_themes’ => ‘theme’ );
foreach ( $transients as $transient => $type ) {$transient = get_site_transient( $transient );
if ( empty( $transient->translations ) )
continue;foreach ( $transient->translations as $translation ) {
$updates[] = (object) $translation;
}
}return $updates;
}
Localização no Core
wp_get_user_contact_methods
Set up the user contact methods.
Default contact methods were removed in 3.6. A filter dictates contact methods.
Argumentos
(WP_User) $user = null
Retorno
(array) Array of contact methods and their labels.
Função no Core
function wp_get_user_contact_methods( $user = null ) {
$methods = array();
if ( get_site_option( ‘initial_db_version’ ) < 23588 ) { $methods = array( ‘aim’ => __( ‘AIM’ ),
‘yim’ => __( ‘Yahoo IM’ ),
‘jabber’ => __( ‘Jabber / Google Talk’ )
);
}/**
* Filter the user contact methods.
*
* @since 2.9.0
*
* @param array $methods Array of contact methods and their labels.
* @param WP_User $user Optional. WP_User object.
*/
return apply_filters( ‘user_contactmethods’, $methods, $user );
}
Localização no Core
wp_maybe_auto_update
Performs WordPress automatic background updates.
Retorno
(void)
Função no Core
function wp_maybe_auto_update() {
include_once ABSPATH . ‘/wp-admin/includes/admin.php’;
include_once ABSPATH . ‘/wp-admin/includes/class-wp-upgrader.php’;$upgrader = new WP_Automatic_Updater;
$upgrader->run();
}
Localização no Core
wp_using_ext_object_cache
Access/Modify private global variable $_wp_using_ext_object_cache
Toggle $_wp_using_ext_object_cache on and off without directly touching global
Argumentos
(bool) $using = null
Retorno
(boolean) The current ‘using’ setting
Função no Core
function wp_using_ext_object_cache( $using = null ) {
global $_wp_using_ext_object_cache;
$current_using = $_wp_using_ext_object_cache;
if ( null !== $using )
$_wp_using_ext_object_cache = $using;
return $current_using;
}
Localização no Core
_reset_front_page_setting_for_post
Resets the page_on_front, show_on_front, and page_for_post settings when a linked page is deleted or trashed.
Also ensures the post is no longer sticky.
Argumentos
$post_id
Retorno
(void)
Função no Core
function _reset_front_page_settings_for_post( $post_id ) {
$post = get_post( $post_id );
if ( ‘page’ == $post->post_type ) {
// If the page is defined in option page_on_front or post_for_posts,
// adjust the corresponding options
if ( get_option( ‘page_on_front’ ) == $post->ID ) {
update_option( ‘show_on_front’, ‘posts’ );
update_option( ‘page_on_front’, 0 );
}
if ( get_option( ‘page_for_posts’ ) == $post->ID ) {
delete_option( ‘page_for_posts’, 0 );
}
}
unstick_post( $post->ID );
}
Localização no Core
_return_empty_string
Returns an empty string.
Useful for returning an empty string to filters easily.
Retorno
(string) Empty string
Função no Core
function __return_empty_string() {
return ”;
}
Excelente artigo , são muito boas as dicas. Parabéns.