Last active
August 29, 2015 13:58
-
-
Save GreggFranklin/10011709 to your computer and use it in GitHub Desktop.
This will add a Custom Post Type count to the At A Glance widget in the Dashboard including the icon
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
// Add Properties to At a Glance Widget | |
function custom_properties_glance_items( $items = array() ) { | |
$post_types = array( 'estate_property'); // Add your registered custom post type | |
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; | |
} | |
add_filter( 'dashboard_glance_items', 'custom_properties_glance_items', 10, 1 ); | |
// Change icons in At a glance, Map pointer Icon \f230 in Dashicons included in WordPress | |
function phb_custom_properties_icons() { | |
echo '<style type="text/css"> | |
#dashboard_right_now a.estate_property-count:before,#dashboard_right_now span.estate_property-count:before {content: "\f230";} | |
</style>'; | |
} | |
add_action('admin_head', 'phb_custom_properties_icons'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment