admin管理员组文章数量:1122832
I've been getting the below errors for quite some time now, but I haven't been able to figure out the root cause.
Notice: Function is_embed 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 C:\xampp\htdocs\wordpress\wp-includes\functions.php on line 6077
Notice: Function 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 C:\xampp\htdocs\wordpress\wp-includes\functions.php on line 6077
I am aware that both are due to $wp_query
not being set before the functions got called. However, I'm having trouble tracking down what is calling them.
The is_embed
error is triggered by way of the _doing_it_wrong
function in query.php
.
If I place debug_print_backtrace()
into query.php
just before _doing_it_wrong
is called, I get the following:
#0 C:\xampp\htdocs\wordpress\wp-includes\robots-template.php(93): is_embed()
#1 C:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(324): wp_robots_noindex_embeds(Array)
#2 C:\xampp\htdocs\wordpress\wp-includes\plugin.php(205): WP_Hook->apply_filters(Array, Array)
#3 C:\xampp\htdocs\wordpress\wp-includes\robots-template.php(32): apply_filters('wp_robots', Array)
#4 C:\xampp\htdocs\wordpress\wp-includes\functions.php(3863): wp_robots()
#5 C:\xampp\htdocs\wordpress\wp-includes\functions.php(3785): _default_wp_die_handler(...)
And similarly, for is_search
:
#0 C:\xampp\htdocs\wordpress\wp-includes\robots-template.php(119): is_search()
#1 C:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(324): wp_robots_noindex_search(Array)
#2 C:\xampp\htdocs\wordpress\wp-includes\plugin.php(205): WP_Hook->apply_filters(Array, Array)
#3 C:\xampp\htdocs\wordpress\wp-includes\robots-template.php(32): apply_filters('wp_robots', Array)
#4 C:\xampp\htdocs\wordpress\wp-includes\functions.php(3863): wp_robots()
#5 C:\xampp\htdocs\wordpress\wp-includes\functions.php(3785): _default_wp_die_handler(...)
It goes away when I comment out the following lines in default-filters.php
:
add_filter( 'wp_robots', 'wp_robots_noindex_embeds' );
add_filter( 'wp_robots', 'wp_robots_noindex_search' );
Oddly, this error occurs even regardless of which plugins are active, but I've only been able to reproduce it by making a plugin throw an Exception first (such as adding throw new \Exception('test');
to "Hello Dolly" with that being the only active plugin).
Is this a bug in WordPress Core?
Update: This also happens regardless of which theme is active. I haven't been able to reproduce it by having the theme trigger the exception yet, just a plugin.
Related Posts: PHP is_embed error showing up (unsolved)
I've been getting the below errors for quite some time now, but I haven't been able to figure out the root cause.
Notice: Function is_embed 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 C:\xampp\htdocs\wordpress\wp-includes\functions.php on line 6077
Notice: Function 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 C:\xampp\htdocs\wordpress\wp-includes\functions.php on line 6077
I am aware that both are due to $wp_query
not being set before the functions got called. However, I'm having trouble tracking down what is calling them.
The is_embed
error is triggered by way of the _doing_it_wrong
function in query.php
.
If I place debug_print_backtrace()
into query.php
just before _doing_it_wrong
is called, I get the following:
#0 C:\xampp\htdocs\wordpress\wp-includes\robots-template.php(93): is_embed()
#1 C:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(324): wp_robots_noindex_embeds(Array)
#2 C:\xampp\htdocs\wordpress\wp-includes\plugin.php(205): WP_Hook->apply_filters(Array, Array)
#3 C:\xampp\htdocs\wordpress\wp-includes\robots-template.php(32): apply_filters('wp_robots', Array)
#4 C:\xampp\htdocs\wordpress\wp-includes\functions.php(3863): wp_robots()
#5 C:\xampp\htdocs\wordpress\wp-includes\functions.php(3785): _default_wp_die_handler(...)
And similarly, for is_search
:
#0 C:\xampp\htdocs\wordpress\wp-includes\robots-template.php(119): is_search()
#1 C:\xampp\htdocs\wordpress\wp-includes\class-wp-hook.php(324): wp_robots_noindex_search(Array)
#2 C:\xampp\htdocs\wordpress\wp-includes\plugin.php(205): WP_Hook->apply_filters(Array, Array)
#3 C:\xampp\htdocs\wordpress\wp-includes\robots-template.php(32): apply_filters('wp_robots', Array)
#4 C:\xampp\htdocs\wordpress\wp-includes\functions.php(3863): wp_robots()
#5 C:\xampp\htdocs\wordpress\wp-includes\functions.php(3785): _default_wp_die_handler(...)
It goes away when I comment out the following lines in default-filters.php
:
add_filter( 'wp_robots', 'wp_robots_noindex_embeds' );
add_filter( 'wp_robots', 'wp_robots_noindex_search' );
Oddly, this error occurs even regardless of which plugins are active, but I've only been able to reproduce it by making a plugin throw an Exception first (such as adding throw new \Exception('test');
to "Hello Dolly" with that being the only active plugin).
Is this a bug in WordPress Core?
Update: This also happens regardless of which theme is active. I haven't been able to reproduce it by having the theme trigger the exception yet, just a plugin.
Related Posts: PHP is_embed error showing up (unsolved)
Share Improve this question edited Jun 19, 2024 at 9:17 cjbj 15k16 gold badges42 silver badges89 bronze badges asked Jun 18, 2024 at 23:16 CragMonkeyCragMonkey 1012 bronze badges1 Answer
Reset to default 1Most likely this problem is caused by a plugin calling wp_die
too early. For instance, if a plugin would decide something is wrong at the init
stage and call wp_die
then, the query would not have been set yet, resulting in this error (see the action reference for the order in which things happen).
You do not mention how you threw that error in "Hello Dolly", but I assume you did it early enough to reproduce the error.
The problem with exceptions is, of course, that they occur under very specific circumstances. It could be one plugin or the interplay between several. Or even specific user input. Hunting the root cause down could indeed be complicated.
I do think this is a bug in core, more specifically in those two filter functions that call is_embed
and is_search
. Those should check for the availability of the functions they call. You could replace them with a filter of your own that does. Something like this (untested):
function wp_robots_noindex_embeds( array $robots ) {
if (did_action ('parse_query') {
if ( is_embed() ) {
return wp_robots_no_robots( $robots );
}
}
return $robots;
}
本文标签: errorsisembed and issearch called incorrectly by wprobots filter
版权声明:本文标题:errors - is_embed and is_search called incorrectly by wp_robots filter 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303351a1931855.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论