• Resolved saschapi

    (@saschapi)


    After updating to version 8 I got a fatal error in regards to a query in another plugin. That seems rather unexpected.
    Here the error:

    
    Fatal error: Uncaught Error: Call to a member function get() on null in /wp-includes/query.php:28 Stack trace: #0 /wp-content/plugins/mapper-plugin/inc/query.php(35): get_query_var('mlat', false) #1 /wp-includes/class-wp-hook.php(305): MapperPlugin\Query->posts_join(' INNER JOIN imL...') #2 /wp-includes/plugin.php(233): WP_Hook->apply_filters(' INNER JOIN imL...', Array) #3 /wp-includes/class-wp-query.php(2578): apply_filters_ref_array('posts_join', Array) #4 /wp-includes/class-wp-query.php(3465): WP_Query->get_posts() #5 /wp-includes/class-wp-query.php(3576): WP_Query->query(Array) #6 /wp-content/plugins/better-wp-security/core/modules/dashboard/setup.php(57): WP_Query->__construct(Array) #7 /wp-includes/query.php on line 28
    
    

    The Plugin code around line 35 is:

      public function posts_join($join) {
        global $wpdb;
        $lat = \get_query_var( 'mlat', false ); //line 35
        $lat = \get_query_var( 'mlng', false );
        if ($lat && $lng) {
          $join .= "LEFT JOIN {cache->table()} AS mapper_cache ON {$wpdb->posts}.ID = mapper_cache.post_id ";
        }
        return $join;
      }
    

    What is happening?

    Cheers Sascha

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Timothy Jacobs

    (@timothyblynjacobs)

    Hi @saschapi,

    I’m sorry you’re running into that error. The issue that is occurring is that during the upgrade process, iThemes Security is trying to run a database query to fetch certain posts from your website.

    It looks like the Mapper Plugins is running a filter to modify the query that gets generated by WordPress. Unfortunately, the way their code is setup, that filter will run for any query, not just the main query that runs “the loop” in WordPress.

    This is causing a fatal error when iThemes Security tries to run its query, but in other cases it can cause incorrect behavior.

    Their code should look something like this instead.

    public function posts_join( $join, $wp_query ) {
    	global $wpdb;
    	
    	if ( ! $wp_query->is_main_query() ) {
    		return $join;
    	}
    	
    	$lat = \get_query_var( 'mlat', false ); //line 35
    	$lng = \get_query_var( 'mlng', false );
    	if ( $lat && $lng ) {
    		$join .= "LEFT JOIN {cache->table()} AS mapper_cache ON {$wpdb->posts}.ID = mapper_cache.post_id ";
    	}
    
    	return $join;
    }

    If you make this adjustment yourself, you’ll need to look for their add_filter call as well and adjust it to pass two parameters to the callback function. Look for a line of code that is something like add_filter( 'posts_join', [ $this, 'posts_join' ] ); and change it to add_filter( 'posts_join', [ $this, 'posts_join' ], 10, 2 );

    Could you share details about that plugin? We can try to reach out to them to get it resolved.

    Thread Starter saschapi

    (@saschapi)

    Hi, I forwarded this issue to the plugin developer. They were able to fix it.
    Thanks for the super fast reply!
    Cheers Sascha

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘500 error regarding query after update’ is closed to new replies.