• Resolved mattf10

    (@mattf10)


    Your code is missing a check that $wp_query->posts is not empty. As a result, a warning is triggered when someone tries to to visit a page that doesn’t exist.

    The code in question is in the file ‘inc/class-registration.php’ line 315. Currently, this check doesn’t exist, which means an empty value is passed to wp_list_pluck, which generates the error in this post title. Adding a check that there are posts before calling this method will silence these warnings.

    Many thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Hardeep Asrani

    (@hardeepasrani)

    Hey @mattf10,

    We weren’t able to reproduce this issue but we have still added a check there to make sure this doesn’t happen under some other conditions. Thank you for the report!

    Thread Starter mattf10

    (@mattf10)

    Thanks a lot for the quick fix!

    The error was generated when accessing an author page via the query string, and the author doesn’t exist. For example:

    https://mywebsite.com/?author=333

    Plugin Author Hardeep Asrani

    (@hardeepasrani)

    Thanks for the details. The fix will be part of the next version of the plugin.

    Thread Starter mattf10

    (@mattf10)

    Hi – I see you made a change to address this in the latest version. However, the new code now generates a different error:

    count(): Parameter must be an array or an object that implements Countable in /wp-content/plugins/otter-blocks /inc/class-registration.php on line 317

    The problem is that $wp_query->posts is not set. So instead of checking the count, please change to isset($wp_query->posts).

    Thanks

    Thread Starter mattf10

    (@mattf10)

    In fact, isset won’t work since posts are set but null. So instead, add is_null check, making line 317:

    if ( ! is_null( $wp_query->posts ) && 0 < count( $wp_query->posts ) ) {

    I tested with this code, and it no longer throws errors.

    Thanks again.

    • This reply was modified 2 years, 10 months ago by mattf10.
    Plugin Author Hardeep Asrani

    (@hardeepasrani)

    Weird, we didn’t have this issue while testing. I’ll take a look again and implement better checks. Sorry for the issue.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Invalid argument supplied for foreach()’ is closed to new replies.