Created
February 28, 2014 08:41
-
-
Save hlashbrooke/9267519 to your computer and use it in GitHub Desktop.
WordPress: Add post types to the 'At a glance' widget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'dashboard_glance_items', 'custom_glance_items', 10, 1 ); | |
function custom_glance_items( $items = array() ) { | |
$post_types = array( 'post_type_1', 'post_type_2' ); | |
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( '<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $type, $text ) . "\n"; | |
} else { | |
$items[] = sprintf( '<span class="%1$s-count">%2$s</span>', $type, $text ) . "\n"; | |
} | |
} | |
} | |
return $items; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#dashboard_right_now a.post_type-count:before, | |
#dashboard_right_now span.post_type-count:before { | |
content: "\f109"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment