Support » Plugin: WooCommerce Search, eCommerce Merchandising and Navigation » is_search was called incorrectly

  • Resolved scmsteve

    (@scmsteve)


    I have seen this for quite a while, but the error was not helpful in finding the source:

    PHP Notice: is_search was called incorrectly. Conditional query tags do not work before the query is run. Before then, they always return false. Please see Debugging in WordPress for more information. (This message was added in version 3.1.0.) in /home/webuser/public_html/wp-includes/functions.php on line 4773

    I finally was motivated enough to find it that I modified functions.php to log a backtrace when this happened, it it seems it is something your plugin is doing:

    #0 /home/webuser/public_html/wp-includes/query.php(662): _doing_it_wrong(‘is_search’, ‘Conditional que…’, ‘(This message w…’)
    #1 /home/webuser/public_html/wp-content/plugins/instantsearch-for-woocommerce/public/wcis_plugin.php(3885): is_search()
    #2 /home/webuser/public_html/wp-includes/class-wp-hook.php(286): WCISPlugin->pre_get_posts_handler(Object(WP_Query))
    #3 /home/webuser/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
    #4 /home/webuser/public_html/wp-includes/plugin.php(531): WP_Hook->do_action(Array)
    #5 /home/webuser/public_html/wp-includes/class-wp-query.php(1753): do_action_ref_array(‘pre_get_posts’, Array)
    #6 /home/webuser/public_html/wp-includes/class-wp-query.php(3404): WP_Query->get_posts()
    #7 /home/webuser/public_html/wp-includes/post.php(1961): WP_Query->query(Array)
    #8 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships/includes/class-wc-memberships-user-memberships.php(322): get_posts(Array)
    #9 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships/includes/functions/wc-memberships-functions-user-memberships.php(56): WC_Memberships_User_Memberships->get_user_memberships(105430, Array)
    #10 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships/includes/functions/wc-memberships-functions-members-area.php(93): wc_memberships_get_user_memberships()
    #11 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships/includes/frontend/class-wc-memberships-members-area.php(66): wc_memberships_get_members_area_endpoint()
    #12 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships-for-teams/vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php(755): WC_Memberships_Members_Area->__construct()
    #13 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships/includes/frontend/class-wc-memberships-frontend.php(54): SkyVerge\WooCommerce\PluginFramework\v5_4_1\SV_WC_Plugin->load_class(‘/includes/front…’, ‘WC_Memberships_…’)
    #14 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships-for-teams/vendor/skyverge/wc-plugin-framework/woocommerce/class-sv-wc-plugin.php(755): WC_Memberships_Frontend->__construct()
    #15 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships/class-wc-memberships.php(328): SkyVerge\WooCommerce\PluginFramework\v5_4_1\SV_WC_Plugin->load_class(‘/includes/front…’, ‘WC_Memberships_…’)
    #16 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships/class-wc-memberships.php(258): WC_Memberships->frontend_includes()
    #17 /home/webuser/public_html/wp-content/plugins/woocommerce-memberships/class-wc-memberships.php(153): WC_Memberships->includes()
    #18 /home/webuser/public_html/wp-includes/class-wp-hook.php(286): WC_Memberships->init_plugin(”)
    #19 /home/webuser/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
    #20 /home/webuser/public_html/wp-includes/plugin.php(465): WP_Hook->do_action(Array)
    #21 /home/webuser/public_html/wp-settings.php(394): do_action(‘plugins_loaded’)
    #22 /home/webuser/wp-config.php(196): require_once(‘/home/webuser/…’)
    #23 /home/webuser/public_html/wp-load.php(42): require_once(‘/home/webuser/…’)
    #24 /home/webuser/public_html/wp-blog-header.php(13): require_once(‘/home/webuser/…’)
    #25 /home/webuser/public_html/index.php(17): require(‘/home/webuser/…’)
    #26 {main}

Viewing 7 replies - 1 through 7 (of 7 total)
  • By the way, this seems to be because while $wp_query is passed to you as an argument, which you are checking, the problem is that global $wp_query is not set which is why the “doing it wrong” is being called. So it seems if you tested for the global $wp_query being set before calling is_search() it would fix the problem.

    • This reply was modified 1 year, 2 months ago by scmsteve.
    Plugin Author Instant Search +

    (@instantsearchplus)

    Hi Steve
    Thanks for the remark. Can you confirm that you are seeing it using the latest version of the plugin?

    It was the latest version as of today when I was testing. I did resolve it locally by doing the check for the global $wp_query being defined when is_search was tested for, but it will of course be overwritten by the next update. The message only shows up when WP_DEBUG is on, but it is quite frequent when it is on, filling up a log file rather quickly and making it hard to find the other things you are looking for.

    Plugin Author Instant Search +

    (@instantsearchplus)

    Thanks
    We will check it.

    I have reported a similar issue to some other plugins, but they are being triggered by something JetPack is doing. This one seems to be triggered by something WooCommerce Memberships is doing if you follow the backtrace. So if you don’t have that installed you probably won’t duplicate the problem.

    Or, as another approach, maybe I can just hook into the ‘doing_it_wrong_trigger_error’ filter and have it not log them at all since I can’t fix them. 🙂

    • This reply was modified 1 year, 2 months ago by scmsteve.

    I will say the same thing I said to the other developers, though… And, as a side note, your plugin is causing a considerably larger number of these messages than the other plugins just because it is called much more frequently. The other ones are called by JetPack’s protect module when it blocks a login, yours is being called by the WooCommerce Memberships plugin on a much more frequent basis.

    Yes, WordPress calls doing_it_wrong to tell you that you shouldn’t be calling them in such a case. I believe you should be checking first for sanity, that WordPress warning is only there to tell you that you haven’t done that. If all things are written properly, that warning should never happen. It should not be normal that a debug log is getting a lot of those warnings if all the code is written to watch for proper use, but we can agree to disagree on that point. That is sort of like saying that PHP will complain if you call a method on a null object. Yes, it will, but with bad side effects and a much harsher result. That is why you should check for yourself before letting that happen. 🙂

    In this case, it is WooCommerce memberships perhaps doing something that is forcing those action/filter calls in a time when nobody else is expecting them to happen. But I would contend that if you are hooking into an action or filter, it is up to you to ensure a sane state of conditions when you then act. People just have WP_DEBUG off by default and/or are not paying attention, so they don’t see this. Plus, the default logging will not tell you why it is happening because it provides no backtrace. That frustrated me for quite a while before I was motivated to find which plugins were doing it.

    I am not trying to cause a problem, I was simply trying to report that the code was causing an warning message. As I said, I found that I can disable them from our logs and just pretend that everything is right in the world. 🙂

    Plugin Author Instant Search +

    (@instantsearchplus)

    Hi Steve,
    We are checking this issue.
    Please contact our support at support@instantsearchplus.com to continue the dialogue.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘is_search was called incorrectly’ is closed to new replies.