Permalink
Browse files

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.
  • Loading branch information...
1 parent f3f76e1 commit 183e5ea4d61edf728887ce7f8a36b31115393b46 @cmmarslender cmmarslender committed Jun 18, 2014
Showing with 9 additions and 3 deletions.
  1. +9 −3 safe-redirect-manager.php
View
12 safe-redirect-manager.php
@@ -107,7 +107,9 @@ public function action_init_load_textdomain() {
* @return string
*/
public function filter_search_join( $join ) {
- if ( $this->redirect_post_type != get_query_var( 'post_type' ) )
+ global $wp_query;
+
+ if ( is_null( $wp_query ) || $this->redirect_post_type != get_query_var( 'post_type' ) )
return $join;
global $wpdb;
@@ -128,7 +130,9 @@ public function filter_search_join( $join ) {
* @return string
*/
public function filter_search_distinct( $distinct ) {
- if ( $this->redirect_post_type != get_query_var( 'post_type' ) )
+ global $wp_query;
+
+ if ( is_null( $wp_query ) || $this->redirect_post_type != get_query_var( 'post_type' ) )
return $distinct;
return 'DISTINCT';
@@ -143,7 +147,9 @@ public function filter_search_distinct( $distinct ) {
* @return string
*/
public function filter_search_where( $where ) {
- if ( $this->redirect_post_type != get_query_var( 'post_type' ) || ! is_search() || empty( $where ) )
+ global $wp_query;
+
+ if ( is_null( $wp_query ) || $this->redirect_post_type != get_query_var( 'post_type' ) || ! is_search() || empty( $where ) )
return $where;
$exact = get_query_var( 'exact' );

0 comments on commit 183e5ea

Please sign in to comment.