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

  • Prós e contras de se utilizar um Tema Premium (pago) para WordPress

    Muitas pessoas na comunidade open source acreditam que os temas pagos para WordPress fazem uma cobrança desleal e são uma tentativa de pessoas gananciosas para alimentar a formação de suas empresas e negócios em projetos de código aberto. Temos outra visão por aqui, vamos a ela. Temas Premium são contribuições para um projeto de código…

  • Corrigindo o erro ‘Allowed memory size Exhausted’ no WordPress

    Um pequenho hackzinho que pode ajudar aqueles que passaram pelo mesmo problema que passamos por aqui. Ao atualizar nosso site para o WordPress 2.8 (após um lógico backup de tudo), a seção administrativa do site apresentava a seguinte mensagem de erro: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 2348617 bytes)…

  • 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…

  • Elimine ou altere o "\author\" da página de autores no WordPress

    Por padrão o WordPress cria uma URL para cada autor, seguindo a estrutura /author/nome-do-usuario. Alguns podem querer modificar esta palavra author, pois se pensarmos em sites em português a expressão não se encaixa muito bem. Teremos também aqueles que, de acordo com o projeto desenvolvido, poderão querer apagar esta palavra e deixar o site mostrando…

Deixe um comentário

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