[Autoblog] Autoblog Errors: Parameter must be an Array…

This is happening on *all* my websites that have Autoblog, not just this one – it is filling up error logs to hundreds of megs over the course of a week.

WordPress, all plugins, and all themes are up to date. PHP Version is 7.3. This error also occurred in 7.2 and 7.1. I am getting pretty tired of having to delete error logs on every site every week.

I have enabled Troubleshooting Support access.

I have deleted part of the full path below for security, but that is the only edit I have done to the errors.

[25-Apr-2019 16:07:54 UTC] PHP Warning: count(): Parameter must be an array or an object that implements Countable in /home/public_html/wp-content/plugins/autoblog/autoblogincludes/addons/cacheimages.php on line 41

[25-Apr-2019 16:07:54 UTC] PHP Warning: count(): Parameter must be an array or an object that implements Countable in /home/public_html/wp-content/plugins/autoblog/autoblogincludes/addons/cacheimages.php on line 48

  • Ash
    • WordPress Hacker

    Hello Myke

    I have just tried the plugin on my test site and I can’t replicate the issue. Though looking at your error log, I am suggesting a fix and if it works for you, I will send that to the developer.

    Please go to /wp-content/plugins/autoblog/autoblogincludes/addons/cacheimages.php line no 40 and replace

    $new_images = $this->_import_post_images( $post->post_content, $details, $post_id );

    with

    $new_images = (array) $this->_import_post_images( $post->post_content, $details, $post_id );

    Please let us know if that eliminates those warnings.

    Have a nice day!

    Cheers,

    Ash

  • Myke
    • Flash Drive

    Yep, though I also had to add (array) to the next instance as well, after } else {.

    Here is what the function looks like now:

    public function import_post_images( $post_id, $details, $item ) {
    $post = get_post( $post_id );
    /*Temporarily replaced for troubleshooting the below line
    $new_images = $this->_import_post_images( $post->post_content, $details, $post_id );
    End Temporarily replaced */
    $new_images = (array) $this->_import_post_images( $post->post_content, $details, $post_id );
    if ( count( $new_images ) ) {
    $post->post_content = str_replace( array_keys( $new_images ), array_values( $new_images ), $post->post_content );
    wp_update_post( $post->to_array() );
    } else {
    //something happen, we will need to use the raw content, please note that simplepie will
    //sanitize content, this is the most case cause google news image don't display
    /*Temporarily replaced for troubleshooting the below line
    $new_images = $this->_import_post_images( $this->get_simplepie_item_raw( $item ), $details, $post_id );
    End Temporarily replaced */
    $new_images = (array) $this->_import_post_images( $this->get_simplepie_item_raw( $item ), $details, $post_id );
    if ( count( $new_images ) ) {
    $replaced_content = $this->_replace_content_with_new_images( $new_images, $post->post_content );
    $post->post_content = $replaced_content;
    wp_update_post( $post->to_array() );
    }
    }
    }

    Newer versions of PHP just do not like the old way it was being handled.This has been an issue for Autoblog and other WPMUdev plugins for a while (Defender). I always thought this would have been patched within a few months of PHP 7.2 coming out.

    So, now that this is working, should I put these lines back the way they were in the core plugin, and make a hook in functions.php (on all of my sites), or should I just save that time and expect this to be a part of AutoBlog 4.1.2 … maybe 4.1.3?

  • Ash
    • WordPress Hacker

    Hello Myke

    For now, please add it to the core plugin until next update is released. I have marked as a bug and reported to the developer. So, hopefully, very soon the issue will be resolved and an update will be released. We appreciate your patience on this.

    Have a nice day!

    Cheers,

    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.