Non mi aspettavo una risposta, grazie davvero. Ho una funzione che guarda lo stato di pubblicazione di un post (wordpress) e mi avverte se è nello stato "pending". io vorrei estenderla alle altre possibilità (draft, pubished, etc.).
Posto l'intero codice, sono poche righe, nel caso dovessero essere aggiunte altre stringe di verifica.
Codice PHP:
function keha_pending_posts_indicator( $menu ) {
$post_types = get_post_types();
if ( empty( $post_types ) ) {
return;
}
foreach ( $post_types as $type ) {
$status = 'pending';
$num_posts = wp_count_posts( $type, 'readable' );
$pending_count = 0;
if ( ! empty( $num_posts->$status ) ) {
$pending_count = $num_posts->$status;
}
// Build string to match in $menu array
if ( $type == 'post' ) {
$menu_str = 'edit.php';
} else {
$menu_str = 'edit.php?post_type='.$type;
}
// Loop through $menu items, find match, add indicator
foreach ( $menu as $menu_key => $menu_data ) {
if ( $menu_str != $menu_data[ 2 ] ) {
continue;
} else {
// NOTE: Using the same CSS classes as the plugin updates count, it will match your admin color theme just fine.
$menu[ $menu_key ][0] .= " <span class='update-plugins count-$pending_count'><span class='plugin-count'>" . number_format_i18n( $pending_count ) . '</span></span>';
}
}
}
return $menu;
}
add_filter( 'add_menu_classes', 'keha_pending_posts_indicator' );