Non sapendo nè leggere né scrivere, dovrei combinare due funzioni:
La prima crea un widget
Codice PHP:
add_action('wp_dashboard_setup', 'my_custom_dashboard_widgets');
function my_custom_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget('custom_help_widget', 'Diario', 'custom_dashboard_help');
}
function custom_dashboard_help() { echo '<p>conteggio dei CPTs, degli utenti registrati, etc</p>'; }
Al posto dell'echo (quindi come contenuto del widget) dovrei mostrare il risultato di questa funzione
Codice PHP:
add_filter( 'dashboard_glance_items', 'custom_glance_items', 10, 1 );
function custom_glance_items( $items = array() ) {
$post_types = array( 'company', 'portfolios', 'events', 'deals', 'blog' );
foreach( $post_types as $type ) {
if( ! post_type_exists( $type ) ) continue;
$num_posts = wp_count_posts( $type );
if( $num_posts ) {
$published = intval( $num_posts->publish );
$post_type = get_post_type_object( $type );
$text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, 'your_textdomain' );
$text = sprintf( $text, number_format_i18n( $published ) );
if ( current_user_can( $post_type->cap->edit_posts ) ) {
$items[] = sprintf( '%2$s', $type, $text ) . "\n";
} else {
$items[] = sprintf( '<span class="%1$s-count">%2$s</span>', $type, $text ) . "\n";
}
}
}
return $items;
}
E' ovvio che non le ho scritte io, ma sono due tutorial separati ed immagino non si possa buttare lì una funzione all'interno di un echo. Come si risolve in questi casi?