Google_Maps_Builder_Core_Admin_Scripts

Load admin scripts.

Defined (1)

The class is defined in the following location(s).

/vendor/wordimpress/maps-builder-core/includes/class-gmc-admin-scripts.php  
  1. class Google_Maps_Builder_Core_Admin_Scripts extends Google_Maps_Builder_Core_Scripts { 
  2.  
  3. /** 
  4. */ 
  5. protected function hooks() { 
  6. add_action( 'admin_head', array( $this, 'icon_style' ) ); 
  7. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) ); 
  8. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); 
  9.  
  10.  
  11. /** 
  12. * Admin Dashicon. 
  13. * Displays a cute lil map dashicon on our CPT. 
  14. */ 
  15. function icon_style() { 
  16. ?> 
  17. <style rel="stylesheet" media="screen"> 
  18. #adminmenu #menu-posts-google_maps div.wp-menu-image:before { 
  19. font-family: 'dashicons' !important; 
  20. content: '\f231'; 
  21. </style> 
  22. <?php return; 
  23.  
  24. /** 
  25. * Register and enqueue admin-specific style sheet. 
  26. * Return early if no settings page is registered. 
  27. * @since 2.0 
  28. * @param $hook 
  29. * @return null 
  30. */ 
  31. function enqueue_admin_styles( $hook ) { 
  32.  
  33. global $post; 
  34. $suffix = $this->paths->suffix(); 
  35.  
  36. //Only enqueue scripts for CPT on post type screen 
  37. if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'google_maps' === $post->post_type || $hook == 'google_maps_page_gmb_settings' || $hook == 'google_maps_page_gmb_import_export' ) { 
  38.  
  39. wp_register_style( 'google-maps-builder-admin-styles', GMB_CORE_URL . 'assets/css/gmb-admin' . $suffix . '.css', array(), GMB_VERSION ); 
  40. wp_enqueue_style( 'google-maps-builder-admin-styles' ); 
  41.  
  42. wp_register_style( 'google-maps-builder-map-icons', GMB_CORE_URL . 'includes/libraries/map-icons/css/map-icons.css', array(), GMB_VERSION ); 
  43. wp_enqueue_style( 'google-maps-builder-map-icons' ); 
  44.  
  45.  
  46.  
  47. /** 
  48. * Register and enqueue admin-specific JavaScript. 
  49. * @since 2.0 
  50. * @param $hook 
  51. * @return null Return early if no settings page is registered. 
  52. */ 
  53. function enqueue_admin_scripts( $hook ) { 
  54. global $post; 
  55. $suffix = $this->paths->suffix(); 
  56. $js_dir = $this->paths->admin_js_dir(); 
  57. $js_plugins = $this->paths->admin_js_url(); 
  58.  
  59. //Builder Google Maps API URL 
  60. $signed_in_option = gmb_get_option( 'gmb_signed_in' ); 
  61. $google_maps_api_url = $this->google_maps_url( $signed_in_option ); 
  62.  
  63. //Only enqueue scripts for CPT on post type screen 
  64. if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'google_maps' === $post->post_type ) { 
  65.  
  66. $this->admin_scripts( $js_plugins, $suffix, $google_maps_api_url, $js_dir, $post, $signed_in_option ); 
  67.  
  68. //Setting Scripts 
  69. if ( $hook == 'google_maps_page_gmb_settings' ) { 
  70. wp_register_script( 'google-maps-builder-admin-settings', $js_dir . 'admin-settings' . $suffix . '.js', array( 'jquery' ), GMB_VERSION ); 
  71. wp_enqueue_script( 'google-maps-builder-admin-settings' ); 
  72.  
  73. wp_enqueue_style( 'dashicons' ); 
  74.  
  75.  
  76.  
  77. /** 
  78. * Load admin scripts 
  79. * @since 1.0 
  80. * @param string $js_plugins 
  81. * @param string $suffix 
  82. * @param string $google_maps_api_url 
  83. * @param string $js_dir 
  84. * @param WP_Post $post 
  85. * @param bool|string $signed_in_option 
  86. */ 
  87. protected function admin_scripts( $js_plugins, $suffix, $google_maps_api_url, $js_dir, $post, $signed_in_option ) { 
  88.  
  89. wp_enqueue_style( 'wp-color-picker' ); 
  90.  
  91. //Magnific popup 
  92. wp_register_script( 'google-maps-builder-admin-magnific-popup', $js_plugins . 'gmb-magnific' . $suffix . '.js', array( 'jquery' ), GMB_VERSION ); 
  93. wp_enqueue_script( 'google-maps-builder-admin-magnific-popup' ); 
  94.  
  95. //Core plugin scripts. 
  96. wp_register_script( 'google-maps-builder-admin-gmaps', $google_maps_api_url, array( 'jquery' ) ); 
  97. wp_enqueue_script( 'google-maps-builder-admin-gmaps' ); 
  98.  
  99. //Maps icons 
  100. wp_register_script( 'google-maps-builder-map-icons', GMB_CORE_URL . 'includes/libraries/map-icons/js/map-icons.js', array( 'jquery' ) ); 
  101. wp_enqueue_script( 'google-maps-builder-map-icons' ); 
  102.  
  103. //Qtip 
  104. wp_register_script( 'google-maps-builder-admin-qtip', $js_plugins . 'jquery.qtip' . $suffix . '.js', array( 'jquery' ), GMB_VERSION, true ); 
  105. wp_enqueue_script( 'google-maps-builder-admin-qtip' ); 
  106.  
  107. //Map base 
  108. wp_register_script( 'google-maps-builder-admin-map-builder', $js_dir . 'admin-google-map' . $suffix . '.js', array( 
  109. 'jquery',  
  110. 'wp-color-picker' 
  111. ), GMB_VERSION ); 
  112. wp_enqueue_script( 'google-maps-builder-admin-map-builder' ); 
  113.  
  114. //Modal magnific builder 
  115. wp_register_script( 'google-maps-builder-admin-magnific-builder', $js_dir . 'admin-maps-magnific' . $suffix . '.js', array( 
  116. 'jquery',  
  117. 'wp-color-picker' 
  118. ), GMB_VERSION ); 
  119. wp_enqueue_script( 'google-maps-builder-admin-magnific-builder' ); 
  120.  
  121. //Map Controls 
  122. wp_register_script( 'google-maps-builder-admin-map-controls', $js_dir . 'admin-maps-controls' . $suffix . '.js', array( 'jquery' ), GMB_VERSION ); 
  123. wp_enqueue_script( 'google-maps-builder-admin-map-controls' ); 
  124.  
  125. $api_key = gmb_get_option( 'gmb_maps_api_key' ); 
  126. $geolocate = gmb_get_option( 'gmb_lat_lng' ); 
  127. $post_status = get_post_status( $post->ID ); 
  128.  
  129. $maps_data = array( 
  130. 'api_key' => $api_key,  
  131. 'geolocate_setting' => isset( $geolocate['geolocate_map'] ) ? $geolocate['geolocate_map'] : 'yes',  
  132. 'default_lat' => isset( $geolocate['latitude'] ) ? $geolocate['latitude'] : '32.715738',  
  133. 'default_lng' => isset( $geolocate['longitude'] ) ? $geolocate['longitude'] : '-117.16108380000003',  
  134. 'plugin_url' => GMB_PLUGIN_URL,  
  135. 'default_marker' => apply_filters( 'gmb_default_marker', GMB_PLUGIN_URL . 'assets/img/spotlight-poi.png' ),  
  136. 'ajax_loader' => set_url_scheme( apply_filters( 'gmb_ajax_preloader_img', GMB_PLUGIN_URL . 'assets/images/spinner.gif' ), 'relative' ),  
  137. 'snazzy' => GMB_PLUGIN_URL . 'assets/js/admin/snazzy.json',  
  138. 'modal_default' => gmb_get_option( 'gmb_open_builder' ),  
  139. 'post_status' => $post_status,  
  140. 'signed_in_option' => $signed_in_option,  
  141. 'site_name' => get_bloginfo( 'name' ),  
  142. 'site_url' => get_bloginfo( 'url' ),  
  143. 'i18n' => array( 
  144. 'update_map' => $post_status == 'publish' ? __( 'Update Map', 'google-maps-builder' ) : __( 'Publish Map', 'google-maps-builder' ),  
  145. 'set_place_types' => __( 'Update Map', 'google-maps-builder' ),  
  146. 'places_selection_changed' => __( 'Place selections have changed.', 'google-maps-builder' ),  
  147. 'multiple_places' => __( 'Hmm, it looks like there are multiple places in this area. Please confirm which place you would like this marker to display:', 'google-maps-builder' ),  
  148. 'btn_drop_marker' => '<span class="dashicons dashicons-location"></span>' . __( 'Drop a Marker', 'google-maps-builder' ),  
  149. 'btn_drop_marker_click' => __( 'Click on the Map', 'google-maps-builder' ),  
  150. 'btn_edit_marker' => __( 'Edit Marker', 'google-maps-builder' ),  
  151. 'btn_delete_marker' => __( 'Delete Marker', 'google-maps-builder' ),  
  152. 'visit_website' => __( 'Visit Website', 'google-maps-builder' ),  
  153. 'get_directions' => __( 'Get Directions', 'google-maps-builder' ),  
  154. 'api_key_required' => sprintf( __( '%1$sGoogle API Error:%2$s Please include your Google Maps API key in the %3$splugin settings%5$s to start using the plugin. An valid API key with Google Maps and Places API access to your website is now required due to recent changes by Google. Getting an API key is free and easy. %4$sLearn how to obtain a Google Maps API key%5$s', 'google-maps-builder' ), '<strong>', '</strong>', '<a href="' . esc_url( admin_url( 'edit.php?post_type=google_maps&page=gmb_settings' ) ) . '">', '<a href="https://wordimpress.com/documentation/maps-builder-pro/creating-maps-api-key/" target="_blank" class="new-window">', '</a>' ) 
  155. ); 
  156.  
  157. wp_localize_script( 'google-maps-builder-admin-map-builder', 'gmb_data', $maps_data ); 
  158.  
  159.  
  160.