Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Notice: is_offline was called incorrectly #538

Closed
Youdaman opened this issue Jun 15, 2021 · 4 comments · Fixed by #712
Closed

PHP Notice: is_offline was called incorrectly #538

Youdaman opened this issue Jun 15, 2021 · 4 comments · Fixed by #712

Comments

@Youdaman
Copy link

Youdaman commented Jun 15, 2021

Couple of intermittent errors/notices in debug.log:

PHP Notice: is_offline 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.

PHP Notice: is_500 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.

Line 98 of wp-content\plugins\pwa\wp-includes\general-template.php seems to be the problem?

/**
 * Add no-robots meta tag to error template.
 *
 * @todo Is this right? Should we add_action when we find out that the filter is present?
 * @see wp_no_robots()
 * @since 0.2
 */
function wp_add_error_template_no_robots() {
	if ( is_offline() || is_500() ) {
		wp_no_robots();
	}
}
@westonruter
Copy link
Collaborator

The wp_add_error_template_no_robots() function runs at wp_head and error_head:

add_action( 'wp_head', 'wp_add_error_template_no_robots' );
add_action( 'error_head', 'wp_add_error_template_no_robots' );

Perhaps you have a template that is calling wp_head() unexpectedly?

@westonruter
Copy link
Collaborator

@Youdaman Sorry for the delay on this. Another user reported the same issue in the support forums. I was able to reproduce the issue and I've submitted a fix: #712. Could you see if that fixes the issue for you if you're still using the plugin?

@pooja-muchandikar
Copy link

Hi @westonruter,

Me and @thelovekesh tried to reproduce the issue but we were not able to reproduce it. Can you please help us to QA this issue?

cc: @maitreyie-chavan

@westonruter
Copy link
Collaborator

QA Passed

This is how I could reproduce the issue by putting the following in a plugin:

add_action( 'plugin_loaded', function () {
	$query = new WP_Query();
	$query->parse_query( 's=test' );
} );

Before the change I would get errors like:

Notice: is_offline 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 /app/public/core-dev/src/wp-includes/functions.php on line 5775

After the change, the notices go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants