Error when using wp_count_posts
-
Hi there!
After the update to 4.0 I encountered an error in my admin. I am using
wp_count_posts
, which leads to this error when your plugin is active:Notice: Trying to get property 'base' of non-object in wp-content/plugins/duplicate-post/src/ui/class-post-list.php on line 135
This is my code
add_filter('add_menu_classes', 'my_add_menu_classes'); /** * Show a 'pending'-batch for the post type 'music' * * @param Array $menu * @return Array */ function my_add_menu_classes( $menu ) { if( !current_user_can('edit_others_posts') ) return $menu; foreach( $menu as $id => $item ) { if( $item[2] === 'edit.php?post_type=music' ) { $menu[$id][0] .= ' ' . get_pending_batch( 'music' ); } } return $menu; } /** * Create a 'pending' batch for a certain post type's count, just like in plugins * * @param string $post_type * @return string */ function my_get_pending_batch( $post_type ) { $count_posts = wp_count_posts( $post_type ); // this causes issues with Duplicate Posts Version 4.0 $counter = sprintf( '<span class="update-plugins count-%1$d"><span class="plugin-count" aria-hidden="true">%1$d</span><span class="screen-reader-text">%2$s</span></span>', $count_posts->pending, 'new drafts' ); return $counter; }
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Error when using wp_count_posts’ is closed to new replies.