Veja todas as novas funções do WordPress 3.8

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 😉


get_theme_update_available

Retrieve the update link if there is a theme update available.

Will return a link if there is an update available.

Argumentos

(WP_Theme) $theme

Retorno

(string|boolean) HTML for the update link, or false if invalid info was passed.

Função no Core

function get_theme_update_available( $theme ) {
static $themes_update;

if ( !current_user_can('update_themes' ) )
return false;

if ( !isset($themes_update) )
$themes_update = get_site_transient('update_themes');

if ( ! is_a( $theme, 'WP_Theme' ) )
return false;

$stylesheet = $theme->get_stylesheet();

$html = '';

if ( isset($themes_update->response[ $stylesheet ]) ) {
$update = $themes_update->response[ $stylesheet ];
$theme_name = $theme->display('Name');
$details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
$update_url = wp_nonce_url( admin_url( 'update.php?action=upgrade-theme&theme=' . urlencode( $stylesheet ) ), 'upgrade-theme_' . $stylesheet );
$update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Updating this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to update.") ) . '\') ) {return true;}return false;"';

if ( !is_multisite() ) {
if ( ! current_user_can('update_themes') ) {
$html = sprintf( '

' . __('There is a new version of %1$s available. View version %3$s details.') . '

', $theme_name, $details_url, $update['new_version']);
} else if ( empty( $update['package'] ) ) {
$html = sprintf( '

' . __('There is a new version of %1$s available. View version %3$s details. Automatic update is unavailable for this theme.') . '

', $theme_name, $details_url, $update['new_version']);
} else {
$html = sprintf( '

' . __('There is a new version of %1$s available. View version %3$s details or update now.') . '

', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
}
}
}

return $html;
}
}

Localização no Core

wp-admin/includes/theme.php


 

wp_admin_bar_sidebar_toggle

Add the sidebar toggle button.

Argumentos

(WP_Admin_Bar) $wp_admin_bar

Retorno

(void)

Função no Core

function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) {
if ( is_admin() ) {
$wp_admin_bar->add_menu( array(
'id' => 'menu-toggle',
'title' => '',
'href' => '#',
'meta' => array(
'title' => __( 'Menu' ),
),
) );
}
}

Localização no Core

wp-includes/admin-bar.php


 

wp_heartbeat_set_suspension

Disable suspension of Heartbeat on the Add/Edit Post screens.

Argumentos

(array) $settings

Retorno

(array) Filtered Heartbeat settings.

Função no Core

function wp_heartbeat_set_suspension( $settings ) {
global $pagenow;

if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) {
$settings['suspension'] = 'disable';
}

return $settings;
}

Localização no Core

wp-admin/includes/misc.php


 

wp_prepare_themes_for_js()

Prepare themes for JavaScript.

Argumentos

(array) $themes = null

Retorno

(array) An associative array of theme data, sorted by name.

Função no Core

function wp_prepare_themes_for_js( $themes = null ) {
$current_theme = get_stylesheet();

// Make sure the current theme is listed first.
$prepared_themes = array( $current_theme => array() );

if ( null === $themes ) {
$themes = wp_get_themes( array( 'allowed' => true ) );
if ( ! isset( $themes[ $current_theme ] ) ) {
$themes[ $current_theme ] = wp_get_theme();
}
}

$updates = array();
if ( current_user_can( 'update_themes' ) ) {
$updates_transient = get_site_transient( 'update_themes' );
if ( isset( $updates_transient->response ) ) {
$updates = $updates_transient->response;
}
}

WP_Theme::sort_by_name( $themes );
foreach ( $themes as $theme ) {
$parent = false;
if ( $theme->parent() ) {
$parent = $theme->parent()->display( 'Name' );
}

$slug = $theme->get_stylesheet();
$encoded_slug = urlencode( $slug );

$prepared_themes[ $slug ] = array(
'id' => $slug,
'name' => $theme->display( 'Name' ),
'screenshot' => array( $theme->get_screenshot() ), // @todo multiple
'description' => $theme->display( 'Description' ),
'author' => $theme->display( 'Author', false, true ),
'authorAndUri' => $theme->display( 'Author' ),
'version' => $theme->display( 'Version' ),
'tags' => $theme->display( 'Tags' ),
'parent' => $parent,
'active' => $slug === $current_theme,
'hasUpdate' => isset( $updates[ $slug ] ),
'update' => get_theme_update_available( $theme ),
'actions' => array(
'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
'customize'=> current_user_can( 'edit_theme_options' ) ? wp_customize_url( $slug ) : null,
'preview' => add_query_arg( array(
'preview' => 1,
'template' => urlencode( $theme->get_template() ),
'stylesheet' => urlencode( $slug ),
'preview_iframe' => true,
'TB_iframe' => true,
), home_url( '/' ) ),
'delete' => current_user_can( 'delete_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null,
),
);
}

/**
* Filter the themes prepared for JavaScript, for themes.php.
*
* Could be useful for changing the order, which is by name by default.
*
* @since 3.8.0
*
* @param array $prepared_themes Array of themes.
*/
$prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes );
return array_values( $prepared_themes );
}

Localização no Core

wp-admin/includes/theme.php


 

wp_star_rating

Output a HTML element with a star rating for a given rating.

Outputs a HTML element with the star rating exposed on a 0..5 scale in half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the number of ratings may also be displayed by passing the $number parameter.

Argumentos

(array) $args = array()

Retorno

(void)

Função no Core

function wp_star_rating( $args = array() ) {
$defaults = array(
'rating' => 0,
'type' => 'rating',
'number' => 0,
);
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );

// Non-english decimal places when the $rating is coming from a string
$rating = str_replace( ',', '.', $rating );

// Convert Percentage to star rating, 0..5 in .5 increments
if ( 'percent' == $type ) {
$rating = round( $rating / 10, 0 ) / 2;
}

// Calculate the number of each type of star needed
$full_stars = floor( $rating );
$half_stars = ceil( $rating - $full_stars );
$empty_stars = 5 - $full_stars - $half_stars;

if ( $number ) {
/* translators: 1: The rating, 2: The number of ratings */
$title = _n( '%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $number );
$title = sprintf( $title, number_format_i18n( $rating, 1 ), number_format_i18n( $number ) );
} else {
/* translators: 1: The rating */
$title = sprintf( __( '%s rating' ), number_format_i18n( $rating, 1 ) );
}

echo '
;'; echo str_repeat( '
;', $full_stars ); echo str_repeat( '
;', $half_stars ); echo str_repeat( '
;', $empty_stars); echo '
'; }

Localização no Core

wp-admin/includes/template.php

Posts Similares

  • Erro Warning: sprintf() nos menus da atualização do 3.6

    Quem atualizou o WordPress semana passada, usando a linguagem pt_BR, com certeza viu o erro “Warning: sprintf(): Argument number must be greater than zero in …….\wp-admin\nav-menus.php on line 478” na tela de administração de menus. Após algumas horas de luta, consegui achar o problema que era um arquivo corrompido pela tradução do WordPress para português do Brasil. Esse erro…

  • Como alterar link e tooltip da logo na página de login do WP

    Ao entrar na página de login de um site WordPress, a logo exibida é a do WordPress, e por muitas vezes, para personalizar a página de login para nossos clientes, trocamos esta logo pela logo do cliente, conforme explicado no post ‘Como alterar o logotipo da página de login do WordPress‘. Isso já dá o…

  • Como colocar Gravatar nos comentários do WordPress 2.7

    Como vi que algumas pessoas tem chegado ao blog através de buscas, tentando descobrir como adicionar as imagens de Gravatar ao seu blog WordPress, resolvi escrever esta dica. Pra começo de conversa, o Gravatar só irá aparecer em seu site se este estiver corretamente configurado para isso. Para tal, vá em wp-admin -> Configurações ->…

  • Utilizando o operador de módulo no loop

    Na maior parte das linguagens de programação existe um operador específico, por vezes esquecido pelos programadores, para operações de módulo. Seu símbolo, na maioria das linguagens, é a % (o que pode causar alguma confusão para os novatos). O PHP não foge à regra e também possui este operador de módulo, sendo o seu símbolo…

  • Veja o novo design do Dashboard do WordPress

    Embora nada fique parado por muito tempo no WordPress, o design do painel do seu blog não mudou muito ultimamente. Enquanto foram adicionadas novas funcionalidades e feitos alguns ajustes ao longo do caminho, o dashboard tem esperado por uma atualização por algum tempo. Com isso em mente, há sete semanas, um grupo desconexo de web…

  • Como customizar a mensagem Leia Mais, exibida pela tag more

    Como todos nós já sabemos, a tag <!–more–> funciona para quebrarmos a exibição de uma postagem na página inicial… tudo o que estiver acima dela será exibido, e em seu lugar teremos a exibição de uma mensagem padrão, como ‘Leia Mais’ , ‘Read More’, ‘Read This Article’, ou algo neste sentido. Na minha humilde concepção,…

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *