Loading the Google Maps API using wp_enqueue_script

I am trying to load the Google Maps API into the WordPress admin class using the following syntax:

add_action('admin_enqueue_scripts', array(&$this, 'load_google_maps'));

...

function load_google_maps()
{
  // The actual API key is configured in an options page
  $key = get_option('google_maps_api_key');
  $gmaps_url = 'http://maps.googleapis.com/maps/api/js?key=' . $key . '&sensor=false';
  wp_enqueue_script('google-maps', $gmaps_url, NULL, NULL);
}

WordPress eludes "&" on "& # 038". This actually causes the Google server to reject the request. When I enter it directly into the address bar of the browser with "& sensor = false" at the end, it loads fine.

I saw this type of error mentioned in the WordPress Trap system: http://core.trac.wordpress.org/ticket/9243 , but it was rejected as invalid and the administrator answered the request and it was shown that the & # 038 approach was okay. From a Google perspective, this is definitely not very good.

, , HTML script, wp_enqueue_script, .

- ?

,

+5
1

- , ( &). , , , &. :

$gmaps_url = 'http://maps.googleapis.com/maps/api/js?key=' . $key . '&sensor=false';

, () :

wp_register_script('googlemaps', 'http://maps.googleapis.com/maps/api/js?' . $locale . '&key=' . GOOGLE_MAPS_V3_API_KEY . '&sensor=false', false, '3');
wp_enqueue_script('googlemaps');

($locale hl=en)

Edit

, WordPress - ( ). , , script, - clean_url, - :

add_filter('clean_url', 'so_handle_038', 99, 3);
function so_handle_038($url, $original_url, $_context) {
    if (strstr($url, "googleapis.com") !== false) {
        $url = str_replace("&", "&", $url); // or $url = $original_url
    }

    return $url;
}

, , , , script, WordPress.

+7

All Articles