Changeset 1596720
- Timestamp:
- 02/15/2017 05:43:36 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
scale-lite-tools/trunk/inc/sl-google-maps/render-cpt.php
r1596719 r1596720 6 6 */ 7 7 8 // Register Google Maps callback function for the backend 8 9 function scale_lite_admin_google_maps() { 9 10 global $scale_lite_tools, $scale_lite_root_path, $scale_lite_url_path; 10 11 wp_enqueue_script( 11 12 'scale-lite-google-maps-admin-js', 12 $scale_lite_url_path. '/assets/js/admin.sl-maps.js',13 array( 'jquery'),13 $scale_lite_url_path.'/assets/js/admin.sl-maps.js', 14 array(), 14 15 '1.0.5', 15 16 1 … … 18 19 add_action('admin_enqueue_scripts', 'scale_lite_admin_google_maps'); 19 20 20 // Register Google Maps callback function 21 // Register Google maps JS v3 for the backend 22 function scale_lite_load_gmaps_v3() { 23 global $scale_lite_url_path; 24 wp_enqueue_script( 25 'scale-lite-google-maps-js', 26 "https://maps.googleapis.com/maps/api/js", 27 array(), 28 '', 29 true 30 ); 31 wp_enqueue_style( 32 'scale_lite_google_maps_css', 33 $scale_lite_url_path . 'assets/css/fronted.google-maps.css', 34 array(), 35 '1.0.5', 36 'all' 37 ); 38 } 39 add_action('admin_enqueue_scripts', 'scale_lite_load_gmaps_v3', 50 ); 40 41 // Register Google Maps callback function for the frontend 21 42 function scale_lite_load_sl_maps_js() { 22 43 global $scale_lite_tools, $scale_lite_root_path, $scale_lite_url_path; … … 29 50 } 30 51 31 32 // store all the maps data 52 // store all the markers in an array 33 53 $markersArray = array(); 34 function scale_lite_build_markers_array() 35 { 54 function scale_lite_build_markers_array() { 36 55 $args = array( 37 // Select maps that are assigned to category slug my-locations56 // Fetch all markers 38 57 'post_type' => 'slt_gmap_marker' 39 58 ); … … 60 79 endwhile; wp_reset_postdata(); // Restore original post data. 61 80 else: 62 echo 'No postfoundd!';81 echo 'No marker foundd!'; 63 82 endif; 83 } 64 84 85 // Save all markers in JS var and pass it to sl-google-maps-frontend 86 function register_markers_array() { 87 global $markersArray; 88 wp_localize_script('sl-google-maps-frontend', 'scaleLiteMarkersBuffer',$markersArray); 89 } 90 91 // add async and defer attributs to google maps script google maps JS 92 add_filter('clean_url','unclean_url',10,3); 93 function unclean_url( $good_protocol_url, $original_url, $_context){ 94 $slt_gmaps_settings_options = get_option( 'slt_gmaps_settings_option_name' ); // Array of All Options 95 $google_maps_api_key_0 = $slt_gmaps_settings_options['google_maps_api_key_0']; // Google Maps API Key 96 if (false !== strpos($original_url, 'maps.googleapis.com/maps/api/js')){ 97 remove_filter('clean_url','unclean_url',10,3); 98 return wp_specialchars_decode($good_protocol_url). 99 '?key='.$google_maps_api_key_0."&callback=slt_gmaps_init' async='async' defer='defer"; 100 } 101 return $good_protocol_url; 65 102 } 66 103 67 104 68 function register_markers_array() { 69 global $markersArray; 70 wp_localize_script('sl-google-maps-frontend', 'scaleLiteMarkersBuffer', 71 $markersArray 72 ); 73 105 // Enque scripts only if shortcode is used 106 function scale_lite_load_maps_if_shortcode() { 107 global $post; 108 if(has_shortcode($post->post_content,'sl_gmaps')) { 109 // execute code only if there is a sl_gmaps shortcode on the page 110 add_action('wp_enqueue_scripts', 'scale_lite_build_markers_array', 9 ); 111 add_action('wp_enqueue_scripts', 'register_markers_array', 10 ); 112 add_action('wp_enqueue_scripts', 'scale_lite_load_gmaps_v3', 50 ); 113 add_action('wp_enqueue_scripts', 'scale_lite_load_sl_maps_js', 9 ); 114 } 74 115 } 116 add_action('wp_enqueue_scripts','scale_lite_load_maps_if_shortcode',0); 75 117 76 118 … … 145 187 $o = ob_get_contents(); 146 188 ob_end_clean(); 147 148 189 return $o; 149 190 } 150 191 // Register google_maps shortcode 151 192 add_shortcode('sl_gmaps', 'scale_lite_google_maps_shortcode'); 152 153 // Register Google maps JS v3154 function scale_lite_load_gmaps_v3() {155 global $scale_lite_url_path;156 wp_enqueue_script(157 'scale-lite-google-maps-js',158 "https://maps.googleapis.com/maps/api/js",159 array(),160 '',161 true162 );163 wp_enqueue_style(164 'scale_lite_google_maps_css',165 $scale_lite_url_path . 'assets/css/fronted.google-maps.css',166 array(),167 '1.0.5',168 'all'169 );170 171 }172 add_action('admin_enqueue_scripts', 'scale_lite_load_gmaps_v3', 50 );173 174 175 // add async and defer attributs to google maps script google maps JS176 add_filter('clean_url','unclean_url',10,3);177 function unclean_url( $good_protocol_url, $original_url, $_context){178 $slt_gmaps_settings_options = get_option( 'slt_gmaps_settings_option_name' ); // Array of All Options179 $google_maps_api_key_0 = $slt_gmaps_settings_options['google_maps_api_key_0']; // Google Maps API Key180 if (false !== strpos($original_url, 'maps.googleapis.com/maps/api/js')){181 remove_filter('clean_url','unclean_url',10,3);182 return wp_specialchars_decode($good_protocol_url).'?key='.$google_maps_api_key_0."&callback=slt_gmaps_init' async='async' defer='defer";183 }184 return $good_protocol_url;185 }186 187 188 189 function scale_lite_load_maps_if_shortcode() {190 global $post;191 if(has_shortcode($post->post_content,'sl_gmaps')) {192 // execute code only if there is a sl_gmaps shortcode on the page193 add_action('wp_enqueue_scripts', 'scale_lite_build_markers_array', 9 );194 add_action('wp_enqueue_scripts', 'register_markers_array', 10 );195 add_action('wp_enqueue_scripts', 'scale_lite_load_gmaps_v3', 50 );196 add_action('wp_enqueue_scripts', 'scale_lite_load_sl_maps_js', 9 );197 }198 }199 add_action('wp_enqueue_scripts','scale_lite_load_maps_if_shortcode',0);200 201 202 203
Note: See TracChangeset
for help on using the changeset viewer.