Plugin Directory

Changeset 1870007


Ignore:
Timestamp:
05/07/2018 01:06:55 PM (8 years ago)
Author:
vsteks
Message:

Performance: Only enqueue scripts when shortcode is present.

As was written the googlemaps javascript script was always included
now it only gets included when the shortcode is present

Location:
gmaps-google-maps-shortcode/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gmaps-google-maps-shortcode/trunk/GMaps.php

    r1868734 r1870007  
    44Plugin URI:   https://github.com/VSTeks/GMapsGoogleMapsShortcode
    55Description:  Adds shortcode's to insert Google Maps via the javascript API.
    6 Version:      1.0.0
     6Version:      1.0.1
    77Author:       VSteks
    88Author URI:   http://vsteks.com/
     
    100100    }
    101101    unset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"]);
     102    wp_enqueue_script('gmaps-includes-5ae9fcc8cf7e2', "https://maps.googleapis.com/maps/api/js?key=".get_option('google_maps_api_key_5ae9fcc8cf7e2')."&callback=gmaps_init_5ae9fcc8cf7e2", array(), "1.0", false);
    102103    return $out."id='$mapId'></div>";
    103104}
     
    308309    $polygons = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-polygons"]);
    309310    $info_windows = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-info-windows"]);
    310     $key = get_option("google_maps_api_key_5ae9fcc8cf7e2");
    311 
    312     if(!$key) {
    313         echo "<div class='notice notice-error'>Google Maps Require an api key be set in Settings > General</div>";
    314     }
    315311    $script = "
    316312      function gmaps_init_5ae9fcc8cf7e2() {
     
    321317              $info_windows
    322318      }";
    323     wp_enqueue_script('gmaps-includes-5ae9fcc8cf7e2', "https://maps.googleapis.com/maps/api/js?key=".$key."&callback=gmaps_init_5ae9fcc8cf7e2", array(), "1.0", false);
    324319    wp_add_inline_script("gmaps-includes-5ae9fcc8cf7e2", $script, 'before');
    325320    // Unset Global variables.
  • gmaps-google-maps-shortcode/trunk/README.txt

    r1868737 r1870007  
    1414== Changelog ==
    1515
     16 v1.0.1 [5-5-2018]
     17 Only enqueue Google maps javascript if shortcode is present on page.
     18
    1619== Frequently Asked Questions ==
    1720
Note: See TracChangeset for help on using the changeset viewer.