×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Web Designer
Added: Nov 8, 2017 9:28 AM
Views: 9
Add custom posts type to admin dashboard
  1.  
  2.     /**
  3.      * Add custom posts type to admin dashboard
  4.      *
  5.      * add_filter( 'dashboard_glance_items', array( $this, 'custom_dashboard_glance_items' ), 10, 1 );
  6.      *
  7.      * @param array $items
  8.      * @return array
  9.      */
  10.     function custom_dashboard_glance_items( $items = array() ) {
  11.         $post_types = array( 'news','event', 'product','job','spare_parts','accessory' );
  12.         foreach ( $post_types as $type ) {
  13.             if ( !post_type_exists( $type ) ) continue;
  14.             $num_posts = wp_count_posts( $type );
  15.             if ( $num_posts ) {
  16.                 $published = intval( $num_posts->publish );
  17.                 $post_type = get_post_type_object( $type );
  18.                 $text = _n( '%s ' . $post_type->labels->singular_name, '%s ' . $post_type->labels->name, $published, SYSTEMA_PLUGIN_DOMAIN );
  19.                 $text = sprintf( $text, number_format_i18n( $published ) );
  20.                 if ( current_user_can( $post_type->cap->edit_posts ) ) {
  21.                     $items[] = sprintf( '%2$s', $type, $text ) . "\n";
  22.                 } else {
  23.                     $items[] = sprintf( '<span class="%1$s-count">%2$s</span>', $type, $text ) . "\n";
  24.                 }
  25.             }
  26.         }
  27.         return $items;
  28.  
  29.     }