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.

Comments

  1. Cant get information from wensite it says set sinsor parmeter to chose trur or false please walk me through this process thank you

Speak Your Mind

*