Advertisement
marjwyatt

Add At a Glance items to WordPress Dashboard

Dec 20th, 2013
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.87 KB | None | 0 0
  1. <?php
  2. // Add Custom Post Type to WP-ADMIN Right Now Widget
  3. // Ref Link: http://wpsnipp.com/index.php/functions-php/include-custom-post-types-in-right-now-admin-dashboard-widget/
  4. // http://wordpress.org/support/topic/dashboard-at-a-glance-custom-post-types
  5. // http://halfelf.org/2012/my-custom-posttypes-live-in-mu/
  6. function vm_right_now_content_table_end() {
  7.     $args = array(
  8.         'public' => true ,
  9.         '_builtin' => false
  10.     );
  11.     $output = 'object';
  12.     $operator = 'and';
  13.     $post_types = get_post_types( $args , $output , $operator );
  14.     foreach( $post_types as $post_type ) {
  15.         $num_posts = wp_count_posts( $post_type->name );
  16.         $num = number_format_i18n( $num_posts->publish );
  17.         $text = _n( $post_type->labels->name, $post_type->labels->name , intval( $num_posts->publish ) );
  18.         if ( current_user_can( 'edit_posts' ) ) {
  19.             $cpt_name = $post_type->name;
  20.         }
  21.         echo '<li class="post-count"><tr><a href="edit.php?post_type='.$cpt_name.'"><td class="first b b-' . $post_type->name . '"></td>' . $num . '&nbsp;<td class="t ' . $post_type->name . '">' . $text . '</td></a></tr></li>';
  22.     }
  23.     $taxonomies = get_taxonomies( $args , $output , $operator );
  24.     foreach( $taxonomies as $taxonomy ) {
  25.         $num_terms  = wp_count_terms( $taxonomy->name );
  26.         $num = number_format_i18n( $num_terms );
  27.         $text = _n( $taxonomy->labels->name, $taxonomy->labels->name , intval( $num_terms ));
  28.         if ( current_user_can( 'manage_categories' ) ) {
  29.             $cpt_tax = $taxonomy->name;
  30.         }
  31.         echo '<li class="post-count"><tr><a href="edit-tags.php?taxonomy='.$cpt_tax.'"><td class="first b b-' . $taxonomy->name . '"></td>' . $num . '&nbsp;<td class="t ' . $taxonomy->name . '">' . $text . '</td></a></tr></li>';
  32.     }
  33. }
  34. add_action( 'dashboard_glance_items' , 'vm_right_now_content_table_end' );
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement