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

  • Migração do WordPress: Movendo o WordPress com o PhpMyAdmin

    O WordPress tem um sistema bastante funcional de exportação/importação, mas quando usamos esse método para transportar nosso WordPress para uma nova hospedagem, por exemplo, importamos todos os posts e páginas com seus respectivos comentários, mas todo o resto (como plugins e configurações) é perdido. Entretanto, se temos o PhpMyAdmin instalado em ambos os servidores envolvidos…

  • Adicionando categorias, tags e taxonomias customizadas nas Mídias do WordPress

    Você já se sentiu frustrado pelo fato do WordPress não permitir que você especifique uma categoria ou uma tag nas imagens ou arquivos de mídia? Pois é, eu já, pois tive tal necessidade em um projeto, e me coloquei a pesquisas como resolver isso. Imagine como isso poder ser útil: criar uma galeria dinâmica de…

  • Temas Gratuitos X Temas Premium: Como escolher um tema WordPress?

    Escolher um tema para um site WordPress não é uma tarefa fácil. Há tantos temas bonitos, com descrições interessantes e características surpreendentes que escolher um pode ser uma tarefa complicada, mas é justamente esta liberdade e grande quantidade de opções de escolha que torna o WordPress uma opção das mais interessantes para usuários não-técnicos. No…

  • Como excluir uma categoria do feed RSS

    Temos o seguinte cenário: em um blog WordPress, temos uma categoria que não deve ser exibida via RSS.. como proceder para que tal categoria seja removida ? Simples ! Adicione a função abaixo no arquivo functions.php function myFilter($query) { if ($query->is_feed) {  $query->set(‘cat’,’-5′); } return $query; } add_filter(‘pre_get_posts’,’myFilter’); Lembre-se de alterar o id da categoria…

  • Mais cores para a seção administrativa do WordPress 3.8

    Uma das coisas que mais gostei no WordPress 3.8 foi o novo esquema de cores para a parte administrativa do WordPress. Não só das que vem como padrão, mas já vislumbrando a possibilidade de criar mais esquemas e dar uma cara diferente para cada projeto, os personalizando ainda mais. Se você não encontrar um esquema…

  • Opa, novo post para revisão!

    Acho que o WordPress já deveria vir com essa funcionalidade por padrão, mas não vem =\ Quando uma pessoa não tem permissão de publicar um post diretamente em um site/blog com WordPress, esse post precisa ir para revisão. Mas o administrador, ou a pessoa que deve aprovar o post não tem ideia que existe um…

Deixe um comentário

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