Check if the global $wp_query is null before using get_query_var.... #59

Merged
merged 2 commits into from Jun 24, 2014

Projects

None yet

3 participants

@cmmarslender
Contributor

If wp_query is null, then get_query_var is trying to call $wp_query->get on a non-object, which causes a fatal error.

Some plugins setup a new WP_Query on the 'plugins_loaded' action, which looking in wp-settings.php is called before the global $wp_query object is set up. In cases like this, the fatal error just makes the site die.

@cmmarslender cmmarslender Check if the global $wp_query is null before using get_query_var. If …
…wp_query is null, then get_query_var is trying to call ->get on a non-object, which causes a fatal error. Some plugins perform a query on the 'plugins_loaded' action, which looking in wp-settings.php is called before the global wp_query object is set up. In cases like this (probably rare, but they happen), fatal errors cause the site to die.
183e5ea
@tlovett1

This looks good. Thoughts on using empty() instead of is_null()? Empty() would cover more edge cases.

Owner

I like it - Updating.....

@dendeffe

Any idea if this will this be merged in updates?

I often use this, which triggers this issue:
http://css-tricks.com/snippets/wordpress/paginate-custom-post-types/

@tlovett1
Owner

Yep, this looks good. Although it would be nice to see a unit test ;)

@tlovett1 tlovett1 merged commit 174c5cb into tlovett1:master Jun 24, 2014
@dendeffe

Great, tanks for the quick follow up.

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