The sensor parameter must be set true o false issue


I came across an unusual situation when a Statcomm user stumbled upon an error on his multisite environment. Every time he wanted to check the Statcomm console the following annoying error came up to the screen:

The Google Maps API server rejected your request. The “sensor” parameter specified in the request must be set to either “true” or “false”.

or in Spanish:

El servidor API de Google Maps ha rechazado tu solicitud. El parámetro “sensor” especificado en la solicitud debe estar definido en “true” o “false”.

Needless to say the the Instant Spy feature was disabled err , corrupted.

This is what I’ve learned and might you’ll find useful:

Statcomm uses Google Maps for his Instant Spy feature.The following code does the magic:

wp_register_script('googlemaps', 'http://maps.google.com/maps/api/js?sensor=false', FALSE, TRUE);
wp_enqueue_script('googlemaps');

However, something was ‘cutting down’ the url to get only http://maps.google.com/maps/api/js and hence the error  came up. Parameter sensor has to be there and somehow it wasn’t.

After a thoroughly revision, I came with the conclusion there was no other plugin conflicting with Statcomm, so I ended up with the only possible suspect: a nice theme called  Choices was causing the strange effect.

This is what I found on functions.php:

function _remove_script_version( $src ){
	$parts = explode( '?', $src );
	return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

This code was removing every parameter from url. You’ll find some useful questions regarding this filter on StackExchange.

Workarounds

There are few ideas to put in motion. The simplest one is to disable both filter altogether, but that could be unwise, affecting the theme inner working.

Since the current filters are far too generic, mangling everything it encounters, another idea could be to improve the function and see what parameters we are handling before returning only the url ($parts[0]).

I discarded these previous ideas because it implied to modify the theme, but I think that would be valid too.

Finally, another idea came from the user itself, Brent Wallace from Best Mobile Web Site Designer : what if we simplify the Google Map url using bit.ly? The ability of bit.ly to compress urls including parameters was something I didn’t know at that time and it was interesting to try.

Here what I got:

function replace_url_google_maps()
{
    wp_deregister_script('googlemaps');
    wp_dequeue_script('googlemaps');

    wp_register_script('googlemaps', 'http://bit.ly/1aBzf3', FALSE, TRUE);
    wp_enqueue_script('googlemaps');
}

add_action('wp_print_scripts','replace_url_google_maps');

http://bit.ly/1aBzf3 is the equivalent of http://maps.google.com/maps/api/js?sensor=false but without using parameters.

The idea is very simple, to replace the original script url with parameters with another equivalente without any parameters. This only affect Statcomm plugin, leaving other themes an plugins untoched.

I hope you can apply this concepts in other situations.

Statcomm 1.7.50

1.7.5.0 introduces a few fixes, but internally we made some major changes toward the next releases, where we are currently building an Ajax console. Some news are: From now on, I (Fernando) will take care the entire plugin. Sergei will be … [Continue reading]

WpGetReady restored

We were down about two days, along the forum and other services. The reason behind was a massive movement to another server taking more time than we expected. We are working to improve the site's security and speed and also rearrange the Demo Site … [Continue reading]

Statcomm Demo Site

The Statcomm Demo Site is the place where you can taste the plugin without installing it. Some features are disabled or frozen. The site will work also a knowledge database for the plugin, where we will be adding more information. Give it a try! … [Continue reading]

Statcomm 1.7.41

Today we released a small patch solving a warning problem caused when Maxmind is not installed. Also we modified the Error Report to look more like the Overview Page. That is meaning we enabled icons and the Instant Spy feature. In following … [Continue reading]