Plugin Directory

Changeset 1868734


Ignore:
Timestamp:
05/04/2018 02:51:09 PM (8 years ago)
Author:
vsteks
Message:

Wordpress Plugin specs

Modify based on review from wordpress.org

Location:
gmaps-google-maps-shortcode/trunk
Files:
1 edited
1 moved

Legend:

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

    r1868733 r1868734  
    3232 *  in the form of 'map_'.uniqid().
    3333 */
    34 function do_gmaps_maps($attrs, $content = null) {
     34function do_gmaps_maps_5ae9fcc8cf7e2($attrs, $content = null) {
    3535    $type = isset($attrs["type"]) ? $attrs["type"] : 'roadmap';
    3636    $lat = isset($attrs["lat"]) ? $attrs["lat"] : 0;
     
    7070
    7171    // Generate the map and push it onto the global maps array.
    72     array_push($GLOBALS["gmaps-maps"], "
     72    array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-maps"], "
    7373    var $mapId = new google.maps.Map(document.getElementById('$mapId'), {
    7474              center: {lat: $lat, lng: $lng},
     
    9393    // Create a global variable to store our map id,
    9494    // so any child element's will know what map they belong too.
    95     $GLOBALS["current-gmaps-map-id"] = $mapId;
     95    $GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"] = $mapId;
    9696
    9797    // Parse for nested shortcode.
     
    9999        do_shortcode($content);
    100100    }
    101     unset($GLOBALS["current-gmaps-map-id"]);
     101    unset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"]);
    102102    return $out."id='$mapId'></div>";
    103103}
     
    109109 *  format 'marker_'.uniqid().
    110110 */
    111 function do_gmaps_marker($attrs) {
     111function do_gmaps_marker_5ae9fcc8cf7e2($attrs) {
    112112  if(!isset($attrs["lng"]) || !isset($attrs['lat'])) {
    113113    echo "Google Maps Markers require Long & lang param's";
     
    115115  } else {
    116116
    117     if(isset($GLOBALS["current-gmaps-map-id"])) {
    118       $current_map = $GLOBALS["current-gmaps-map-id"];
     117    if(isset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"])) {
     118      $current_map = $GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"];
    119119    }
    120120
     
    139139    });";
    140140
    141     array_push($GLOBALS["gmaps-markers"], $marker);
     141    array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-markers"], $marker);
    142142  }
    143143}
     
    147147 *  The `path` attribute is required
    148148 */
    149 function do_gmaps_polygon($attrs) {
     149function do_gmaps_polygon_5ae9fcc8cf7e2($attrs) {
    150150    if(!isset($attrs["path"])) {
    151151      echo "gmaps-polygon requires the 'path' attribute";
     
    183183      }
    184184
    185       if(isset($GLOBALS["current-gmaps-map-id"])) {
     185      if(isset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"])) {
    186186        $out = $out."
    187187            strokeColor: '$stroke_color',
     
    197197            fillOpacity: $fill_opacity
    198198        });
    199         $gone_id.setMap(".$GLOBALS["current-gmaps-map-id"].");";
    200       }
    201 
    202       array_push($GLOBALS["gmaps-polygons"], $out);
     199        $gone_id.setMap(".$GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"].");";
     200      }
     201
     202      array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-polygons"], $out);
    203203    }
    204204}
     
    207207 * Generate a Polyline JavaScript Object, the  `path` attribute is required.
    208208 */
    209 function do_gmaps_polyline($attrs) {
     209function do_gmaps_polyline_5ae9fcc8cf7e2($attrs) {
    210210    if(!isset($attrs["path"])) {
    211211      echo "gmaps-polyline requires the 'path' attribute";
     
    232232
    233233      if(sizeof($points) <=1 ) {
    234         echo "gmaps-polyline requires more the one point";
     234        echo "gmaps-polyline requires more than one point";
    235235        return;
    236236      } else {
     
    244244          }
    245245        }
    246         if(isset($GLOBALS["current-gmaps-map-id"])) {
     246        if(isset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"])) {
    247247          $out = $out."
    248248              strokeColor: '$stroke_color',
     
    256256              clickable: $clickable
    257257          });
    258           $line_id.setMap(".$GLOBALS["current-gmaps-map-id"].");";
     258          $line_id.setMap(".$GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"].");";
     259          array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-polylines"], $out);
    259260        }
    260 
    261         array_push($GLOBALS["gmaps-polylines"], $out);
    262261      }
    263262    }
     
    269268 * pass the marker id in via the `marker` attribute.
    270269 */
    271 function do_gmaps_info_window($attrs, $content = null) {
     270function do_gmaps_info_window_5ae9fcc8cf7e2($attrs, $content = null) {
    272271  $winId = 'info_window_'.uniqid();
    273272  if(!isset($attrs["marker"])) {
     
    277276    $marker = $attrs["marker"];
    278277  }
    279   if(isset($GLOBALS["current-gmaps-map-id"])) {
    280     $current_map = $GLOBALS["current-gmaps-map-id"];
     278  if(isset($GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"])) {
     279    $current_map = $GLOBALS["5ae9fcc8cf7e2-current-gmaps-map-id"];
    281280  }
    282281
     
    293292  ";
    294293
    295   array_push($GLOBALS["gmaps-info-windows"], $out);
     294  array_push($GLOBALS["5ae9fcc8cf7e2-gmaps-info-windows"], $out);
    296295}
    297296
     
    302301 * google maps api.
    303302 */
    304 function include_google_maps() {
    305 
    306     $maps = implode('', $GLOBALS["gmaps-maps"]);
    307     $markers = implode('', $GLOBALS["gmaps-markers"]);
    308     $polylines = implode('', $GLOBALS["gmaps-polylines"]);
    309     $polygons = implode('', $GLOBALS["gmaps-polygons"]);
    310     $info_windows = implode('', $GLOBALS["gmaps-info-windows"]);
    311     $key = get_option("google_maps_api_key");
     303function include_google_maps_5ae9fcc8cf7e2() {
     304
     305    $maps = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-maps"]);
     306    $markers = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-markers"]);
     307    $polylines = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-polylines"]);
     308    $polygons = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-polygons"]);
     309    $info_windows = implode('', $GLOBALS["5ae9fcc8cf7e2-gmaps-info-windows"]);
     310    $key = get_option("google_maps_api_key_5ae9fcc8cf7e2");
    312311
    313312    if(!$key) {
    314313        echo "<div class='notice notice-error'>Google Maps Require an api key be set in Settings > General</div>";
    315314    }
    316 
    317     echo "
    318     <script>
    319       function gmaps_init() {
     315    $script = "
     316      function gmaps_init_5ae9fcc8cf7e2() {
    320317              $maps
    321318              $markers
     
    323320              $polygons
    324321              $info_windows
    325       }
    326     </script>
    327     <script src='https://maps.googleapis.com/maps/api/js?key=".$key."&callback=gmaps_init' async defer></script>";
    328 
     322      }";
     323    wp_enqueue_script('gmaps-includes-5ae9fcc8cf7e2', "https://maps.googleapis.com/maps/api/js?key=".$key."&callback=gmaps_init_5ae9fcc8cf7e2", array(), "1.0", false);
     324    wp_add_inline_script("gmaps-includes-5ae9fcc8cf7e2", $script, 'before');
    329325    // Unset Global variables.
    330     unset($GLOBALS["gmaps-maps"]);
    331     unset($GLOBALS["gmaps-markers"]);
    332     unset($GLOBALS["gmaps-polylines"]);
    333     unset($GLOBALS["gmaps-polygons"]);
     326    unset($GLOBALS["5ae9fcc8cf7e2-gmaps-maps"]);
     327    unset($GLOBALS["5ae9fcc8cf7e2-gmaps-markers"]);
     328    unset($GLOBALS["5ae9fcc8cf7e2-gmaps-polylines"]);
     329    unset($GLOBALS["5ae9fcc8cf7e2-gmaps-polygons"]);
    334330}
    335331
     
    337333 * Ensure global variables exist and are empty
    338334 */
    339 function create_gmaps_global_vars() {
    340   $GLOBALS["gmaps-maps"] = [];
    341   $GLOBALS["gmaps-markers"] = [];
    342   $GLOBALS["gmaps-polylines"] = [];
    343   $GLOBALS["gmaps-polygons"] = [];
    344   $GLOBALS["gmaps-info-windows"] = [];
     335function create_gmaps_global_vars_5ae9fcc8cf7e2() {
     336  $GLOBALS["5ae9fcc8cf7e2-gmaps-maps"] = [];
     337  $GLOBALS["5ae9fcc8cf7e2-gmaps-markers"] = [];
     338  $GLOBALS["5ae9fcc8cf7e2-gmaps-polylines"] = [];
     339  $GLOBALS["5ae9fcc8cf7e2-gmaps-polygons"] = [];
     340  $GLOBALS["5ae9fcc8cf7e2-gmaps-info-windows"] = [];
    345341}
    346342
     
    348344   Callback generate the GoogleMaps Api key input element.
    349345*/
    350 function generate_setting() {
    351   $value = get_option('google_maps_api_key');
    352   echo "<input type='text' name='google_maps_api_key' id='google_maps_api_key' style='width:25%' value='$value'/>";
     346function vstek_generate_gmaps_setting_5ae9fcc8cf7e2() {
     347  $value = get_option('google_maps_api_key_5ae9fcc8cf7e2');
     348  echo "<input type='text' name='google_maps_api_key_5ae9fcc8cf7e2' id='google_maps_api_key_5ae9fcc8cf7e2' style='width:25%' value='$value'/>";
    353349}
    354350
     
    356352    Register the GoogleMaps Api key setting to the 'General' settings page.
    357353*/
    358 function register_setting_field() {
     354function gmaps_register_setting_field_5ae9fcc8cf7e2() {
    359355  register_setting(
    360356      'general',
    361       'google_maps_api_key'
     357      'google_maps_api_key_5ae9fcc8cf7e2'
    362358  );
    363359  add_settings_field(
    364360      'html_guidelines_message',
    365361      'Google Maps Api Key',
    366       'generate_setting',
     362      'vstek_generate_gmaps_setting_5ae9fcc8cf7e2',
    367363      'general'
    368364  );
     
    370366
    371367// Add shortcode handlers
    372 add_shortcode('gmaps', 'do_gmaps_maps');
    373 add_shortcode('gmaps-marker', 'do_gmaps_marker');
    374 add_shortcode('gmaps-polyline', 'do_gmaps_polyline');
    375 add_shortcode('gmaps-polygon', 'do_gmaps_polygon');
    376 add_shortcode('gmaps-info-window', 'do_gmaps_info_window');
     368add_shortcode('gmaps', 'do_gmaps_maps_5ae9fcc8cf7e2');
     369add_shortcode('gmaps-marker', 'do_gmaps_marker_5ae9fcc8cf7e2');
     370add_shortcode('gmaps-polyline', 'do_gmaps_polyline_5ae9fcc8cf7e2');
     371add_shortcode('gmaps-polygon', 'do_gmaps_polygon_5ae9fcc8cf7e2');
     372add_shortcode('gmaps-info-window', 'do_gmaps_info_window_5ae9fcc8cf7e2');
    377373
    378374// Add request actions.
    379 add_action('wp_head', 'create_gmaps_global_vars');
    380 add_action('wp_footer', 'include_google_maps');
     375add_action('wp_head', 'create_gmaps_global_vars_5ae9fcc8cf7e2');
     376add_action('wp_footer', 'include_google_maps_5ae9fcc8cf7e2');
    381377
    382378// Add custom admin settings field.
    383 add_filter('admin_init', 'register_setting_field');
     379add_filter('admin_init', 'gmaps_register_setting_field_5ae9fcc8cf7e2');
  • gmaps-google-maps-shortcode/trunk/README.txt

    r1868733 r1868734  
    11# GMaps Google Maps Shortcode
     2Tags: maps, google
     3Contributors: vsteks
     4Requires at least: 4.0.0
     5Tested up to: 4.9.5
     6Requires PHP: 7.1
     7Stable tag: trunk
     8License: GPLv2
     9LICENSE URI: http://gnu.org/license/gpl-2.0.html
    210
    311A simple wordpress plugin to insert Google Maps into posts/pages using the javascript API. Can be used to create markers, lines, and arbitrary shapes.
     
    413421
    414422## Multi Marker
    415 Create a map showing
     423Create a map showing many markers connected by a Polyline.
     424
     425```
     426[gmaps lat=13.4125 lng=103.8670]
     427    [gmaps-marker lat=13.4125 lng=103.8670]
     428    [gmaps-marker lat=13.0 lng=103]
     429[/gmaps]
     430```
     431
     432# Changelog
     433
     434# Frequently Asked Questions
     435
     436# Upgrade Notice
     437
     438# Screenshots
    416439
    417440[google-api-key]:https://developers.google.com/maps/documentation/javascript/get-api-key
Note: See TracChangeset for help on using the changeset viewer.