• Resolved Rasso Hilber

    (@nonverbla)


    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;
    }
    
    • This topic was modified 3 years, 10 months ago by Rasso Hilber.
    • This topic was modified 3 years, 10 months ago by Rasso Hilber.
Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Maybellyne

    (@maybellyne)

    Hello,

    We are sorry about the error.

    Can you confirm that you are running WordPress 5.6? If yes, we would like to rule out any plugin or theme conflicts that may occur. The fastest way to do this is to?deactivate all non-Yoast plugins and switch to a standard theme?like?Twenty Nineteen.?

    Test this on your development or staging site, if you have one. If not, we recommend using the?Health Check & Troubleshooting?plugin. This plugin allows you to run a conflict check?without affecting normal visitors to your site.

    As we can imagine that you’re unfamiliar with checking for conflicts, we’d like to point you to a step-by-step guide that will walk you through the process:?How to check for plugin conflicts.

    Thread Starter Rasso Hilber

    (@nonverbla)

    Thanks Maybellyne, I am a developer and I am sure that my issue lies somewhere inside Duplicate Post. I just switched to the standard theme twentynineteen, deactivated all plugins except “Duplicate Post” and included my code in the functions.php of the default theme, with the post type ‘post’:

    
    add_filter('add_menu_classes', 'my_add_menu_classes');
    /**
     * Show a 'pending'-batch for the post type 'post'
     *
     * @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' ) {
          $menu[$id][0] .= ' ' . my_get_pending_batch( 'post' );
        }
      }
      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 );
      $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;
    }
    

    Same error there.

    • This reply was modified 3 years, 10 months ago by Rasso Hilber.
    Plugin Support Maybellyne

    (@maybellyne)

    Thanks for getting back. We are currently looking into the issue and a patch will be released soon to fix this.

    We appreciate your patience.

    Hi,

    Same problem but with an admin impact.
    I also see :
    #0 /home/clch4709/public_html/wp-content/plugins/duplicate-post/src/ui/class-classic-editor.php(302): Yoast\WP\Duplicate_Post\Permissions_Helper->is_rewrite_and_republish_copy(false)
    #1 /home/clch4709/public_html/wp-content/plugins/duplicate-post/src/ui/class-classic-editor.php(210): Yoast\WP\Duplicate_Post\UI\Classic_Editor->should_change_rewrite_republish_copy(false)
    #2 /home/clch4709/public_html/wp-includes/class-wp-hook.php(289): Yoast\WP\Duplicate_Post\UI\Classic_Editor->change_republish_strings_classic_editor(‘Une erreur crit…’, ‘There has been …’)
    #3 /home/clch4709/public_html/wp-includes/plugin.php(212): in /home/clch4709/public_html/wp-content/plugins/duplicate-post/src/class-permissions-helper.php on line 57
    Using the Divi Theme (on a lot of sites) it blocks access to edit something in the Divi Library.
    Until the fix I deactivate the duplicate post plugin.

    Hopping a quick solution ??
    Kind regards;
    Philippe

    • This reply was modified 3 years, 10 months ago by plerix.
    Plugin Support Maybellyne

    (@maybellyne)

    @plerix We are currently looking into the issue and will communicate a resolution soon.

    Hi,

    Wonderful and … so quick !!!
    4.0.1 tested and all works perfectly

    Many thanks !
    Philippe

    Thanks for confirming @plerix. Does it also resolve the issue for you, @nonverbla?

    Thread Starter Rasso Hilber

    (@nonverbla)

    Yes, works with 4.0.1! Thanks.

    • This reply was modified 3 years, 10 months ago by Rasso Hilber.

    Thanks for the confirmation!

    Thread Starter Rasso Hilber

    (@nonverbla)

    @tacoverdo yes it does. Thank you!!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Error when using wp_count_posts’ is closed to new replies.