Title: Request for Added Cache Routine Check
Last modified: May 29, 2026

---

# Request for Added Cache Routine Check

 *  Resolved [HKP](https://wordpress.org/support/users/hiskingdomprophecy/)
 * (@hiskingdomprophecy)
 * [1 week, 2 days ago](https://wordpress.org/support/topic/request-for-added-cache-routine-check/)
 * Hi Folks,
 * Two days ago I noticed thousands of the following two Error Messages in my WP
   debug.log as follows. (My debug log is normally off, but I was working on some
   other issue when this came to light.)
 * `[27-May-2026 07:11:08 UTC] PHP Notice: Function is_search was called <strong
   >incorrectly</strong>. Conditional query tags do not work before the query is
   run. Before then, they always return false. Please see <a href="https://developer.
   wordpress.org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress
   </a> for more information. (This message was added in version 3.1.0.) in /xxx/
   wp-includes/functions.php on line 6170`
 * `[27-May-2026 07:11:08 UTC] PHP Notice: Function is_404 was called <strong>incorrectly
   </strong>. Conditional query tags do not work before the query is run. Before
   then, they always return false. Please see <a href="https://developer.wordpress.
   org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a
   > for more information. (This message was added in version 3.1.0.) in /xxx/wp-
   includes/functions.php on line 6170`
 * We have recently updated to WP7.0 and after checking we found the Kadence Security
   Basic (KSB) apparently related to the issue.
 * After further testing and exchanges with KSB, we obtained the following information
   on the issue which related to WP-Optimize :
 * `[28-May-2026 10:31:22 UTC] [conditional-tag-backtrace] is_search | shutdown_action_hook,
   do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, wp_ob_end_flush_all,
   ob_end_flush, WPO_Page_Optimizer->optimize, WPO_Page_Optimizer->maybe_cache_page,
   WPO_Page_Cache->should_cache_page, wpo_can_serve_from_cache, wpo_restricted_cache_page_type,
   wpo_is_search, is_search, _doing_it_wrong, do_action('doing_it_wrong_run'), WP_Hook-
   >do_action, WP_Hook->apply_filters, {closure}`
 * `[28-May-2026 10:31:22 UTC] PHP Notice: Function is_search was called <strong
   >incorrectly</strong>. Conditional query tags do not work before the query is
   run. Before then, they always return false. Please see <a href="https://developer.
   wordpress.org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress
   </a> for more information. (This message was added in version 3.1.0.) in /xxx/
   wp-includes/functions.php on line 6170`
 * `[28-May-2026 10:31:22 UTC] [conditional-tag-backtrace] is_404 | shutdown_action_hook,
   do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters, wp_ob_end_flush_all,
   ob_end_flush, WPO_Page_Optimizer->optimize, WPO_Page_Optimizer->maybe_cache_page,
   WPO_Page_Cache->should_cache_page, wpo_can_serve_from_cache, wpo_restricted_cache_page_type,
   is_404, _doing_it_wrong, do_action('doing_it_wrong_run'), WP_Hook->do_action,
   WP_Hook->apply_filters, {closure}`
 * `[28-May-2026 10:31:22 UTC] PHP Notice: Function is_404 was called <strong>incorrectly
   </strong>. Conditional query tags do not work before the query is run. Before
   then, they always return false. Please see <a href="https://developer.wordpress.
   org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a
   > for more information. (This message was added in version 3.1.0.) in /xxx/wp-
   includes/functions.php on line 6170`
 * `[28-May-2026 10:31:22 UTC] PHP Notice: Function is_feed was called <strong>incorrectly
   </strong>. Conditional query tags do not work before the query is run. Before
   then, they always return false. Please see <a href="https://developer.wordpress.
   org/advanced-administration/debug/debug-wordpress/">Debugging in WordPress</a
   > for more information. (This message was added in version 3.1.0.) in /xxx/functions.
   php on line 6170`
 * And finally from our Server Error Log:
 * `[Thu May 28 21:20:36.567391 2026] [proxy_fcgi:error] [pid 1078998:tid 1079117][
   client 144.76.23.106:50274] AH01071: Got error 'PHP message: [conditional-tag-
   backtrace] is_search | shutdown_action_hook, do_action('shutdown'), WP_Hook->
   do_action, WP_Hook->apply_filters, wp_ob_end_flush_all, ob_end_flush, WPO_Page_Optimizer-
   >optimize, WPO_Page_Optimizer->maybe_cache_page, WPO_Page_Cache->should_cache_page,
   wpo_can_serve_from_cache, wpo_restricted_cache_page_type, wpo_is_search, is_search,
   _doing_it_wrong, do_action('doing_it_wrong_run'), WP_Hook->do_action, WP_Hook-
   >apply_filters, {closure}; PHP message: [conditional-tag-backtrace] is_404 | 
   shutdown_action_hook, do_action('shutdown'), WP_Hook->do_action, WP_Hook->apply_filters,
   wp_ob_end_flush_all, ob_end_flush, WPO_Page_Optimizer->optimize, WPO_Page_Optimizer-
   >maybe_cache_page, WPO_Page_Cache->should_cache_page, wpo_can_serve_from_cache,
   wpo_restricted_cache_page_type, is_404, _doing_it_wrong, do_action('doing_it_wrong_run'),
   WP_Hook->do_action, WP_Hook->apply_filters, {closure}'`
 * KSB’s explanation of the situation was: “What is happening is that WP-Optimize,
   when it decides at the very end of the request whether the page is cacheable,
   calls is_search(), is_404() and is_feed() to rule out search/404/feed pages. 
   Those three core functions print the “called incorrectly” notice whenever they
   run before WordPress has built its main query object, and that is precisely the
   situation here.
 * Here is why Kadence Security flips it on and off for you, even though the plugin
   never calls those functions itself:
 * Your firewall is set to load early (it boots before the rest of WordPress so 
   it can stop attacks before they reach your site). When the firewall blocks a 
   request, or when a repeat-offender IP is already locked out, it ends that request
   immediately, before WordPress gets far enough to build its query object. WP-Optimize,
   however, opens its page-cache output buffer even earlier than that, so its end-
   of-request “should I cache this page?” check still runs on the way out. At that
   point the query never ran, so is_search()/is_404()/is_feed() correctly report
   that they were called too early, and the notice is logged. With Kadence Security
   switched off, nothing ends those requests early, the query always runs, and WP-
   Optimize’s check has no reason to complain. That is the whole interaction.”
 * The final comment from KSB suggests that your cache routine should check that
   the main query has actually run (did_action(‘wp’)) before calling those conditional
   tags. And this would permanently resolve the matter.
 * I leave this in your hands now and humble ask that you look at the suggestion
   from KSB.
 * If there is anything else you need from us to help resolve this issue, please
   do just ask. Always pleased to help.
 * For more information on our exchanges with KSB, please see: [https://wordpress.org/support/topic/wp7-0-issue-with-functions-php-line-6170/#post-18922870](https://wordpress.org/support/topic/wp7-0-issue-with-functions-php-line-6170/#post-18922870)
 * Regards and thanks,
   Angus
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Frequest-for-added-cache-routine-check%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Support [jbgupdraft](https://wordpress.org/support/users/jbgupdraft/)
 * (@jbgupdraft)
 * [1 week, 2 days ago](https://wordpress.org/support/topic/request-for-added-cache-routine-check/#post-18923236)
 * Hi Angus,
 * Thanks so much for contacting us and the very detailed report of this issue! 
   I’ll pass this up the chain so we can investigate and look into improving compatibility
   with KSB and resolving those PHP notices.
 * Thanks!

Viewing 1 replies (of 1 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Frequest-for-added-cache-routine-check%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/wp-optimize/assets/icon-256x256.png?rev=1552899)
 * [WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance](https://wordpress.org/plugins/wp-optimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-optimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-optimize/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-optimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-optimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-optimize/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [jbgupdraft](https://wordpress.org/support/users/jbgupdraft/)
 * Last activity: [1 week, 2 days ago](https://wordpress.org/support/topic/request-for-added-cache-routine-check/#post-18923236)
 * Status: resolved