Last active
February 27, 2017 01:01
-
-
Save 5A5K1A/9039356de94a28d23224d46143ab6ac0 to your computer and use it in GitHub Desktop.
WordPress Add all CPT (& tax) to WP Dashboard Right Now Widget
This file contains hidden or 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 Custom Post Type to WP-ADMIN Right Now Widget | |
/* ------------------------------------ */ | |
add_action( 'dashboard_glance_items', function() { ?> | |
<style> | |
#dashboard_right_now a.post_type_name-count:before { content: "\f473"; } | |
</style> | |
<?php | |
$args = array( | |
'public' => true , | |
'_builtin' => false | |
); | |
$arr_posttypes = get_post_types( $args, 'object', 'and' ); | |
foreach( $arr_posttypes as $obj_posttype ) { | |
$int_total = number_format_i18n( wp_count_posts($obj_posttype->name)->publish ); | |
$str_output = _n( $obj_posttype->labels->name, $obj_posttype->labels->name , intval(wp_count_posts($obj_posttype->name)->publish) ); | |
$str_posttype_name = $obj_posttype->name; | |
if( current_user_can('edit_posts') ) { | |
echo '<li class="'.$str_posttype_name.'-count"><a href="edit.php?post_type='.$str_posttype_name.'" class="'.$str_posttype_name.'-count">'.$int_total.' '.$str_output.'</a></li>'; | |
} | |
} | |
$arr_taxonomies = get_taxonomies( $args , 'object' , 'and' ); | |
foreach( $arr_taxonomies as $obj_tax ) { | |
$int_total = number_format_i18n( wp_count_terms( $obj_tax->name ) ); | |
$str_output = _n( $obj_tax->labels->name, $obj_tax->labels->name , intval( wp_count_terms( $obj_tax->name ) )); | |
$str_tax_name = $obj_tax->name; | |
if( current_user_can('manage_categories') ) { | |
echo '<li class="'.$str_tax_name.'-count"><a href="edit-tags.php?taxonomy='.$str_tax_name.'" class="'.$str_tax_name.'-count">'.$int_total.' '.$str_output.'</a></li>'; | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment