brasofilo

wp.org/support-4820935

Oct 30th, 2013
164
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action( 'admin_menu', 'pending_posts_bubble_wpse_89028', 999 );
  2. function pending_posts_bubble_wpse_89028()
  3. {
  4.     global $menu;
  5.     $args = array( 'public' => true );
  6.     $post_types = get_post_types( $args );
  7.     unset( $post_types['attachment'] );
  8.  
  9.     foreach( $post_types as $pt )
  10.     {
  11.         // count posts
  12.         $cpt_count = wp_count_posts( $pt );
  13.         if ( $cpt_count->pending )
  14.         {
  15.             $suffix = ( 'post' == $pt ) ? '' : "?post_type=$pt";
  16.             $key = recursive_array_search_php_91365( "edit.php$suffix", $menu );
  17.             if( !$key )
  18.                 return;
  19.             $menu[$key][0] .= sprintf(
  20.                 '<span class="update-plugins count-%1$s"><span class="plugin-count">%1$s</span></span>',
  21.                 $cpt_count->pending
  22.             );
  23.         }
  24.     }
  25. }
  26. function recursive_array_search_php_91365( $needle, $haystack )
  27. {
  28.     foreach( $haystack as $key => $value )
  29.     {
  30.         $current_key = $key;
  31.         if(
  32.             $needle === $value
  33.             OR (
  34.                 is_array( $value )
  35.                 && recursive_array_search_php_91365( $needle, $value ) !== false
  36.             )
  37.         )
  38.         {
  39.             return $current_key;
  40.         }
  41.     }
  42.     return false;
  43. }
RAW Paste Data