| @@ -23,1461 +23,1455 @@ | ||
| 23 | 23 | |
| 24 | 24 | namespace Cbx\Googlemap; |
| 25 | 25 | |
| 26 | 26 | // If this file is called directly, abort. |
| 27 | -if ( ! defined('WPINC')) { | |
| 28 | - die; | |
| 27 | +if ( ! defined( 'WPINC' ) ) { | |
| 28 | + die; | |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | use Cbx\Googlemap\Helpers\CBXGooglemapHelper; |
| 32 | 32 | use Cbx\Googlemap\Helpers\CBXGooglemapMetaHelper; |
| 33 | 33 | |
| 34 | -final class CBXGoogleMapAdmin | |
| 35 | -{ | |
| 34 | +final class CBXGoogleMapAdmin { | |
| 36 | 35 | |
| 37 | - /** | |
| 38 | - * The ID of this plugin. | |
| 39 | - * | |
| 40 | - * @since 1.0.0 | |
| 41 | - * @access private | |
| 42 | - * @var string $plugin_name The ID of this plugin. | |
| 43 | - */ | |
| 44 | - private $plugin_name; | |
| 36 | + /** | |
| 37 | + * The ID of this plugin. | |
| 38 | + * | |
| 39 | + * @since 1.0.0 | |
| 40 | + * @access private | |
| 41 | + * @var string $plugin_name The ID of this plugin. | |
| 42 | + */ | |
| 43 | + private $plugin_name; | |
| 45 | 44 | |
| 46 | - /** | |
| 47 | - * The version of this plugin. | |
| 48 | - * | |
| 49 | - * @since 1.0.0 | |
| 50 | - * @access private | |
| 51 | - * @var string $version The current version of this plugin. | |
| 52 | - */ | |
| 53 | - private $version; | |
| 45 | + /** | |
| 46 | + * The version of this plugin. | |
| 47 | + * | |
| 48 | + * @since 1.0.0 | |
| 49 | + * @access private | |
| 50 | + * @var string $version The current version of this plugin. | |
| 51 | + */ | |
| 52 | + private $version; | |
| 54 | 53 | |
| 55 | - /** | |
| 56 | - * The ID of this plugin. | |
| 57 | - * | |
| 58 | - * @since 1.1.12 | |
| 59 | - * @access private | |
| 60 | - * @var string $settings The ID of this plugin. | |
| 61 | - */ | |
| 62 | - public $settings; | |
| 54 | + /** | |
| 55 | + * The ID of this plugin. | |
| 56 | + * | |
| 57 | + * @since 1.1.12 | |
| 58 | + * @access private | |
| 59 | + * @var string $settings The ID of this plugin. | |
| 60 | + */ | |
| 61 | + public $settings; | |
| 63 | 62 | |
| 64 | - /** | |
| 65 | - * Initialize the class and set its properties. | |
| 66 | - * | |
| 67 | - * | |
| 68 | - * @since 1.0.0 | |
| 69 | - */ | |
| 70 | - public function __construct() | |
| 71 | - { | |
| 72 | - $this->plugin_name = CBXGOOGLEMAP_PLUGIN_NAME; | |
| 73 | - $this->version = CBXGOOGLEMAP_PLUGIN_VERSION; | |
| 63 | + /** | |
| 64 | + * Initialize the class and set its properties. | |
| 65 | + * | |
| 66 | + * | |
| 67 | + * @since 1.0.0 | |
| 68 | + */ | |
| 69 | + public function __construct() { | |
| 70 | + $this->plugin_name = CBXGOOGLEMAP_PLUGIN_NAME; | |
| 71 | + $this->version = CBXGOOGLEMAP_PLUGIN_VERSION; | |
| 74 | 72 | |
| 75 | - //get instance of setting api | |
| 76 | - $this->settings = new CBXGooglemapSettings(); | |
| 77 | - }//end of construtor | |
| 73 | + //get instance of setting api | |
| 74 | + $this->settings = new CBXGooglemapSettings(); | |
| 75 | + }//end of construtor | |
| 78 | 76 | |
| 79 | - /** | |
| 80 | - * Initialize setting | |
| 81 | - */ | |
| 82 | - public function setting_init() | |
| 83 | - { | |
| 84 | - //set the settings | |
| 85 | - $this->settings->set_sections($this->get_settings_sections()); | |
| 86 | - $this->settings->set_fields($this->get_settings_fields()); | |
| 87 | - //initialize settings | |
| 88 | - $this->settings->admin_init(); | |
| 89 | - }//end setting_init | |
| 77 | + /** | |
| 78 | + * Initialize setting | |
| 79 | + */ | |
| 80 | + public function setting_init() { | |
| 81 | + //set the settings | |
| 82 | + $this->settings->set_sections( $this->get_settings_sections() ); | |
| 83 | + $this->settings->set_fields( $this->get_settings_fields() ); | |
| 84 | + //initialize settings | |
| 85 | + $this->settings->admin_init(); | |
| 86 | + }//end setting_init | |
| 90 | 87 | |
| 91 | - /** | |
| 92 | - * Global Setting Sections | |
| 93 | - * | |
| 94 | - * | |
| 95 | - * @return array | |
| 96 | - */ | |
| 97 | - public function get_settings_sections() | |
| 98 | - { | |
| 99 | - return apply_filters( | |
| 100 | - 'cbxgooglemap_setting_sections', [ | |
| 101 | - [ | |
| 102 | - 'id' => 'cbxgooglemap_general', | |
| 103 | - 'title' => esc_html__('Default Config', 'cbxgooglemap') | |
| 104 | - ], | |
| 105 | - [ | |
| 106 | - 'id' => 'cbxgooglemap_demo', | |
| 107 | - 'title' => esc_html__('Demo & Shortcodes', 'cbxgooglemap') | |
| 108 | - ], | |
| 109 | - [ | |
| 110 | - 'id' => 'cbxgooglemap_tools', | |
| 111 | - 'title' => esc_html__('Tools', 'cbxgooglemap'), | |
| 112 | - ] | |
| 113 | - ] | |
| 114 | - ); | |
| 115 | - }//end get_settings_sections | |
| 88 | + /** | |
| 89 | + * Global Setting Sections | |
| 90 | + * | |
| 91 | + * | |
| 92 | + * @return array | |
| 93 | + */ | |
| 94 | + public function get_settings_sections() { | |
| 95 | + return apply_filters( | |
| 96 | + 'cbxgooglemap_setting_sections', [ | |
| 97 | + [ | |
| 98 | + 'id' => 'cbxgooglemap_general', | |
| 99 | + 'title' => esc_html__( 'Default Config', 'cbxgooglemap' ) | |
| 100 | + ], | |
| 101 | + [ | |
| 102 | + 'id' => 'cbxgooglemap_demo', | |
| 103 | + 'title' => esc_html__( 'Demo & Shortcodes', 'cbxgooglemap' ) | |
| 104 | + ], | |
| 105 | + [ | |
| 106 | + 'id' => 'cbxgooglemap_tools', | |
| 107 | + 'title' => esc_html__( 'Tools', 'cbxgooglemap' ), | |
| 108 | + ] | |
| 109 | + ] | |
| 110 | + ); | |
| 111 | + }//end get_settings_sections | |
| 116 | 112 | |
| 117 | - /** | |
| 118 | - * Returns all the settings fields | |
| 119 | - * | |
| 120 | - * @return array settings fields | |
| 121 | - */ | |
| 122 | - public function get_settings_fields() | |
| 123 | - { | |
| 124 | - $general_settings = get_option('cbxgooglemap_general', []); | |
| 113 | + /** | |
| 114 | + * Returns all the settings fields | |
| 115 | + * | |
| 116 | + * @return array settings fields | |
| 117 | + */ | |
| 118 | + public function get_settings_fields() { | |
| 119 | + $general_settings = get_option( 'cbxgooglemap_general', [] ); | |
| 125 | 120 | |
| 126 | - $tools_delete_table_html = '<div id="setting_resetinfo">'.esc_html__('Loading ...', 'cbxgooglemap').'</div>'; | |
| 121 | + $tools_delete_table_html = '<div id="setting_resetinfo">' . esc_html__( 'Loading ...', 'cbxgooglemap' ) . '</div>'; | |
| 127 | 122 | |
| 128 | - $settings_builtin_fields = [ | |
| 129 | - 'cbxgooglemap_general' => [ | |
| 130 | - 'general_heading' => [ | |
| 131 | - 'name' => 'general_heading', | |
| 132 | - 'label' => esc_html__('Default Config', 'cbxgooglemap'), | |
| 133 | - 'type' => 'heading', | |
| 134 | - 'default' => '', | |
| 135 | - ], | |
| 136 | - 'mapsource' => [ | |
| 137 | - 'name' => 'mapsource', | |
| 138 | - 'label' => esc_html__('Map Source', 'cbxgooglemap'), | |
| 139 | - 'type' => 'radio', | |
| 140 | - 'default' => 1, | |
| 141 | - 'options' => [ | |
| 142 | - 0 => esc_html__('Openstreet Map(leafletjs)', 'cbxgooglemap'), | |
| 143 | - 1 => esc_html__('Google Map', 'cbxgooglemap') | |
| 144 | - ], | |
| 145 | - 'inline' => 1, | |
| 146 | - 'sanitize_callback' => 'absint' | |
| 147 | - ], | |
| 148 | - 'apikey' => [ | |
| 149 | - 'name' => 'apikey', | |
| 150 | - 'label' => esc_html__('Api Key', 'cbxgooglemap'), | |
| 151 | - 'desc' => esc_html__('Google map api key', 'cbxgooglemap'), | |
| 152 | - 'type' => 'text' | |
| 123 | + $settings_builtin_fields = [ | |
| 124 | + 'cbxgooglemap_general' => [ | |
| 125 | + 'general_heading' => [ | |
| 126 | + 'name' => 'general_heading', | |
| 127 | + 'label' => esc_html__( 'Default Config', 'cbxgooglemap' ), | |
| 128 | + 'type' => 'heading', | |
| 129 | + 'default' => '', | |
| 130 | + ], | |
| 131 | + 'mapsource' => [ | |
| 132 | + 'name' => 'mapsource', | |
| 133 | + 'label' => esc_html__( 'Map Source', 'cbxgooglemap' ), | |
| 134 | + 'type' => 'radio', | |
| 135 | + 'default' => 1, | |
| 136 | + 'options' => [ | |
| 137 | + 0 => esc_html__( 'Openstreet Map(leafletjs)', 'cbxgooglemap' ), | |
| 138 | + 1 => esc_html__( 'Google Map', 'cbxgooglemap' ) | |
| 139 | + ], | |
| 140 | + 'inline' => 1, | |
| 141 | + 'sanitize_callback' => 'absint' | |
| 142 | + ], | |
| 143 | + 'apikey' => [ | |
| 144 | + 'name' => 'apikey', | |
| 145 | + 'label' => esc_html__( 'Api Key', 'cbxgooglemap' ), | |
| 146 | + 'desc' => esc_html__( 'Google map api key', 'cbxgooglemap' ), | |
| 147 | + 'type' => 'text' | |
| 153 | 148 | |
| 154 | - ], | |
| 155 | - 'maptype' => [ | |
| 156 | - 'name' => 'maptype', | |
| 157 | - 'label' => esc_html__('Map Type', 'cbxgooglemap'), | |
| 158 | - 'type' => 'select', | |
| 159 | - 'default' => 'roadmap', | |
| 160 | - 'options' => [ | |
| 161 | - 'roadmap' => esc_html__('Road Map', 'cbxgooglemap'), | |
| 162 | - 'satellite' => esc_html__('Satellite Map', 'cbxgooglemap'), | |
| 163 | - 'hybrid' => esc_html__('Hybrid Map', 'cbxgooglemap'), | |
| 164 | - 'terrain' => esc_html__('Terrain Map', 'cbxgooglemap'), | |
| 165 | - ], | |
| 166 | - 'desc' => esc_html__('Google Map only', 'cbxgooglemap'), | |
| 167 | - 'sanitize_callback' => 'sanitize_text_field' | |
| 168 | - ], | |
| 169 | - 'zoom' => [ | |
| 170 | - 'name' => 'zoom', | |
| 171 | - 'label' => esc_html__('Zoom Level', 'cbxgooglemap'), | |
| 172 | - 'desc' => esc_html__('Default Zoom Level', 'cbxgooglemap'), | |
| 173 | - 'type' => 'number', | |
| 174 | - 'step' => 1, | |
| 175 | - 'default' => 8, | |
| 176 | - 'sanitize_callback' => 'absint' | |
| 149 | + ], | |
| 150 | + 'maptype' => [ | |
| 151 | + 'name' => 'maptype', | |
| 152 | + 'label' => esc_html__( 'Map Type', 'cbxgooglemap' ), | |
| 153 | + 'type' => 'select', | |
| 154 | + 'default' => 'roadmap', | |
| 155 | + 'options' => [ | |
| 156 | + 'roadmap' => esc_html__( 'Road Map', 'cbxgooglemap' ), | |
| 157 | + 'satellite' => esc_html__( 'Satellite Map', 'cbxgooglemap' ), | |
| 158 | + 'hybrid' => esc_html__( 'Hybrid Map', 'cbxgooglemap' ), | |
| 159 | + 'terrain' => esc_html__( 'Terrain Map', 'cbxgooglemap' ), | |
| 160 | + ], | |
| 161 | + 'desc' => esc_html__( 'Google Map only', 'cbxgooglemap' ), | |
| 162 | + 'sanitize_callback' => 'sanitize_text_field' | |
| 163 | + ], | |
| 164 | + 'zoom' => [ | |
| 165 | + 'name' => 'zoom', | |
| 166 | + 'label' => esc_html__( 'Zoom Level', 'cbxgooglemap' ), | |
| 167 | + 'desc' => esc_html__( 'Default Zoom Level', 'cbxgooglemap' ), | |
| 168 | + 'type' => 'number', | |
| 169 | + 'step' => 1, | |
| 170 | + 'default' => 8, | |
| 171 | + 'sanitize_callback' => 'absint' | |
| 177 | 172 | |
| 178 | - ], | |
| 179 | - 'width' => [ | |
| 180 | - 'name' => 'with', | |
| 181 | - 'label' => esc_html__('Width', 'cbxgooglemap'), | |
| 182 | - 'desc' => esc_html__('Default is 100% to make the map responsive, if you want any fixed width then don\'t put, % or just put numeric value, don\'t px with numeric value', 'cbxgooglemap'), | |
| 183 | - 'type' => 'text', | |
| 184 | - 'default' => '100%', | |
| 173 | + ], | |
| 174 | + 'width' => [ | |
| 175 | + 'name' => 'with', | |
| 176 | + 'label' => esc_html__( 'Width', 'cbxgooglemap' ), | |
| 177 | + 'desc' => esc_html__( 'Default is 100% to make the map responsive, if you want any fixed width then don\'t put, % or just put numeric value, don\'t px with numeric value', | |
| 178 | + 'cbxgooglemap' ), | |
| 179 | + 'type' => 'text', | |
| 180 | + 'default' => '100%', | |
| 185 | 181 | |
| 186 | - ], | |
| 187 | - 'height' => [ | |
| 188 | - 'name' => 'height', | |
| 189 | - 'label' => esc_html__('Height', 'cbxgooglemap'), | |
| 190 | - 'desc' => esc_html__('Default height 300 as px, put any numeric value.', 'cbxgooglemap'), | |
| 191 | - 'type' => 'number', | |
| 192 | - 'default' => '300', | |
| 193 | - 'sanitize_callback' => 'floatval' | |
| 194 | - ], | |
| 195 | - 'scrollwheel' => [ | |
| 196 | - 'name' => 'scrollwheel', | |
| 197 | - 'label' => esc_html__('Mouse Scroll Wheel', 'cbxgooglemap'), | |
| 198 | - 'desc' => esc_html__('Enable/disable mouse scroll whell', 'cbxgooglemap'), | |
| 199 | - 'type' => 'radio', | |
| 200 | - 'default' => 1, | |
| 201 | - 'options' => [ | |
| 202 | - '0' => esc_html__('Disable', 'cbxgooglemap'), | |
| 203 | - '1' => esc_html__('Enable', 'cbxgooglemap') | |
| 204 | - ], | |
| 205 | - 'inline' => 1, | |
| 206 | - 'sanitize_callback' => 'absint' | |
| 207 | - ], | |
| 208 | - 'showinfo' => [ | |
| 209 | - 'name' => 'showinfo', | |
| 210 | - 'label' => esc_html__('Show Info window', 'cbxgooglemap'), | |
| 211 | - 'desc' => esc_html__('Show information on click of marker', 'cbxgooglemap'), | |
| 212 | - 'type' => 'radio', | |
| 213 | - 'default' => 1, | |
| 214 | - 'options' => [ | |
| 215 | - '0' => esc_html__('Disable', 'cbxgooglemap'), | |
| 216 | - '1' => esc_html__('Enable', 'cbxgooglemap') | |
| 217 | - ], | |
| 218 | - 'inline' => 1, | |
| 219 | - 'sanitize_callback' => 'absint' | |
| 220 | - ], | |
| 221 | - 'infow_open' => [ | |
| 222 | - 'name' => 'infow_open', | |
| 223 | - 'label' => esc_html__('Info/Popup Window', 'cbxgooglemap'), | |
| 224 | - 'type' => 'radio', | |
| 225 | - 'default' => 1, | |
| 226 | - 'options' => [ | |
| 227 | - '0' => esc_html__('On Click', 'cbxgooglemap'), | |
| 228 | - '1' => esc_html__('Open(Default)', 'cbxgooglemap'), | |
| 229 | - ], | |
| 230 | - 'inline' => 1, | |
| 231 | - 'sanitize_callback' => 'absint' | |
| 232 | - ], | |
| 233 | - 'mapicon' => [ | |
| 234 | - 'name' => 'mapicon', | |
| 235 | - 'label' => esc_html__('Map Icon', 'cbxgooglemap'), | |
| 236 | - 'type' => 'file', | |
| 237 | - 'default' => '' | |
| 238 | - ], | |
| 239 | - 'hide_leaflet' => [ | |
| 240 | - 'name' => 'hide_leaflet', | |
| 241 | - 'label' => esc_html__('Hide Leaflet Branding', 'cbxgooglemap'), | |
| 242 | - 'type' => 'radio', | |
| 243 | - 'default' => 0, | |
| 244 | - 'options' => [ | |
| 245 | - 0 => esc_html__('Show/Default', 'cbxgooglemap'), | |
| 246 | - 1 => esc_html__('Hide', 'cbxgooglemap'), | |
| 247 | - ], | |
| 248 | - 'inline' => 1, | |
| 249 | - 'sanitize_callback' => 'absint' | |
| 250 | - ], | |
| 182 | + ], | |
| 183 | + 'height' => [ | |
| 184 | + 'name' => 'height', | |
| 185 | + 'label' => esc_html__( 'Height', 'cbxgooglemap' ), | |
| 186 | + 'desc' => esc_html__( 'Default height 300 as px, put any numeric value.', 'cbxgooglemap' ), | |
| 187 | + 'type' => 'number', | |
| 188 | + 'default' => '300', | |
| 189 | + 'sanitize_callback' => 'floatval' | |
| 190 | + ], | |
| 191 | + 'scrollwheel' => [ | |
| 192 | + 'name' => 'scrollwheel', | |
| 193 | + 'label' => esc_html__( 'Mouse Scroll Wheel', 'cbxgooglemap' ), | |
| 194 | + 'desc' => esc_html__( 'Enable/disable mouse scroll whell', 'cbxgooglemap' ), | |
| 195 | + 'type' => 'radio', | |
| 196 | + 'default' => 1, | |
| 197 | + 'options' => [ | |
| 198 | + '0' => esc_html__( 'Disable', 'cbxgooglemap' ), | |
| 199 | + '1' => esc_html__( 'Enable', 'cbxgooglemap' ) | |
| 200 | + ], | |
| 201 | + 'inline' => 1, | |
| 202 | + 'sanitize_callback' => 'absint' | |
| 203 | + ], | |
| 204 | + 'showinfo' => [ | |
| 205 | + 'name' => 'showinfo', | |
| 206 | + 'label' => esc_html__( 'Show Info window', 'cbxgooglemap' ), | |
| 207 | + 'desc' => esc_html__( 'Show information on click of marker', 'cbxgooglemap' ), | |
| 208 | + 'type' => 'radio', | |
| 209 | + 'default' => 1, | |
| 210 | + 'options' => [ | |
| 211 | + '0' => esc_html__( 'Disable', 'cbxgooglemap' ), | |
| 212 | + '1' => esc_html__( 'Enable', 'cbxgooglemap' ) | |
| 213 | + ], | |
| 214 | + 'inline' => 1, | |
| 215 | + 'sanitize_callback' => 'absint' | |
| 216 | + ], | |
| 217 | + 'infow_open' => [ | |
| 218 | + 'name' => 'infow_open', | |
| 219 | + 'label' => esc_html__( 'Info/Popup Window', 'cbxgooglemap' ), | |
| 220 | + 'type' => 'radio', | |
| 221 | + 'default' => 1, | |
| 222 | + 'options' => [ | |
| 223 | + '0' => esc_html__( 'On Click', 'cbxgooglemap' ), | |
| 224 | + '1' => esc_html__( 'Open(Default)', 'cbxgooglemap' ), | |
| 225 | + ], | |
| 226 | + 'inline' => 1, | |
| 227 | + 'sanitize_callback' => 'absint' | |
| 228 | + ], | |
| 229 | + 'mapicon' => [ | |
| 230 | + 'name' => 'mapicon', | |
| 231 | + 'label' => esc_html__( 'Map Icon', 'cbxgooglemap' ), | |
| 232 | + 'type' => 'file', | |
| 233 | + 'default' => '' | |
| 234 | + ], | |
| 235 | + 'hide_leaflet' => [ | |
| 236 | + 'name' => 'hide_leaflet', | |
| 237 | + 'label' => esc_html__( 'Hide Leaflet Branding', 'cbxgooglemap' ), | |
| 238 | + 'type' => 'radio', | |
| 239 | + 'default' => 0, | |
| 240 | + 'options' => [ | |
| 241 | + 0 => esc_html__( 'Show/Default', 'cbxgooglemap' ), | |
| 242 | + 1 => esc_html__( 'Hide', 'cbxgooglemap' ), | |
| 243 | + ], | |
| 244 | + 'inline' => 1, | |
| 245 | + 'sanitize_callback' => 'absint' | |
| 246 | + ], | |
| 251 | 247 | |
| 252 | - ], | |
| 253 | - 'cbxgooglemap_demo' => [ | |
| 254 | - 'demo_heading' => [ | |
| 255 | - 'name' => 'demo_heading', | |
| 256 | - 'label' => esc_html__('Demo & Shortcodes', 'cbxgooglemap'), | |
| 257 | - 'type' => 'heading', | |
| 258 | - 'default' => '', | |
| 259 | - ], | |
| 260 | - 'shortcode_demo' => [ | |
| 261 | - 'name' => 'shortcode_demo', | |
| 262 | - 'label' => esc_html__('Shortcode & Demo', 'cbxgooglemap'), | |
| 263 | - 'desc' => esc_html__('Shortcode and demo based on default setting, please save once to check change.', 'cbxgooglemap'), | |
| 264 | - 'type' => 'shortcode', | |
| 265 | - 'class' => 'cbcurrencyconverter_demo_copy', | |
| 266 | - 'default' => CBXGooglemapHelper::shortcode_builder($general_settings), | |
| 267 | - 'sanitize_callback' => 'sanitize_text_field' | |
| 268 | - ] | |
| 269 | - ], | |
| 270 | - 'cbxgooglemap_tools' => [ | |
| 271 | - 'tools_heading' => [ | |
| 272 | - 'name' => 'tools_heading', | |
| 273 | - 'label' => esc_html__('Tools Settings', 'cbxgooglemap'), | |
| 274 | - 'type' => 'heading', | |
| 275 | - 'default' => '', | |
| 276 | - ], | |
| 277 | - 'delete_global_config' => [ | |
| 278 | - 'name' => 'delete_global_config', | |
| 279 | - 'label' => esc_html__('On Uninstall delete plugin data', 'cbxgooglemap'), | |
| 280 | - 'desc' => '<p>'.esc_html__('Delete Global Config data(options/plugin settings), custom table(s), files/folders, all map custom post type created by this plugin on uninstall. Please note that this process can not be undone and it is recommended to keep full database and files backup before doing this.', 'cbxgooglemap').'</p>', | |
| 281 | - 'type' => 'radio', | |
| 282 | - 'options' => [ | |
| 283 | - 'yes' => esc_html__('Yes', 'cbxgooglemap'), | |
| 284 | - 'no' => esc_html__('No', 'cbxgooglemap'), | |
| 285 | - ], | |
| 286 | - 'default' => 'no', | |
| 287 | - ], | |
| 288 | - 'reset_data' => [ | |
| 289 | - 'name' => 'reset_data', | |
| 290 | - 'label' => esc_html__('Reset all section', 'cbxgooglemap'), | |
| 291 | - 'desc' => $tools_delete_table_html.'<p>'.esc_html__('This will reset all option/section created by this plugin.', | |
| 292 | - 'cbxgooglemap').'<a data-busy="0" class="button secondary ml-20" id="reset_data_trigger" href="#">'.esc_html__('Reset Sections', | |
| 293 | - 'cbxgooglemap').'</a></p>', | |
| 294 | - 'type' => 'html', | |
| 295 | - 'default' => 'off' | |
| 296 | - ], | |
| 297 | - ], | |
| 298 | - ]; | |
| 248 | + ], | |
| 249 | + 'cbxgooglemap_demo' => [ | |
| 250 | + 'demo_heading' => [ | |
| 251 | + 'name' => 'demo_heading', | |
| 252 | + 'label' => esc_html__( 'Demo & Shortcodes', 'cbxgooglemap' ), | |
| 253 | + 'type' => 'heading', | |
| 254 | + 'default' => '', | |
| 255 | + ], | |
| 256 | + 'shortcode_demo' => [ | |
| 257 | + 'name' => 'shortcode_demo', | |
| 258 | + 'label' => esc_html__( 'Shortcode & Demo', 'cbxgooglemap' ), | |
| 259 | + 'desc' => esc_html__( 'Shortcode and demo based on default setting, please save once to check change.', 'cbxgooglemap' ), | |
| 260 | + 'type' => 'shortcode', | |
| 261 | + 'class' => 'cbcurrencyconverter_demo_copy', | |
| 262 | + 'default' => CBXGooglemapHelper::shortcode_builder( $general_settings ), | |
| 263 | + 'sanitize_callback' => 'sanitize_text_field' | |
| 264 | + ] | |
| 265 | + ], | |
| 266 | + 'cbxgooglemap_tools' => [ | |
| 267 | + 'tools_heading' => [ | |
| 268 | + 'name' => 'tools_heading', | |
| 269 | + 'label' => esc_html__( 'Tools Settings', 'cbxgooglemap' ), | |
| 270 | + 'type' => 'heading', | |
| 271 | + 'default' => '', | |
| 272 | + ], | |
| 273 | + 'delete_global_config' => [ | |
| 274 | + 'name' => 'delete_global_config', | |
| 275 | + 'label' => esc_html__( 'On Uninstall delete plugin data', 'cbxgooglemap' ), | |
| 276 | + 'desc' => '<p>' . esc_html__( 'Delete Global Config data(options/plugin settings), custom table(s), files/folders, all map custom post type created by this plugin on uninstall. Please note that this process can not be undone and it is recommended to keep full database and files backup before doing this.', | |
| 277 | + 'cbxgooglemap' ) . '</p>', | |
| 278 | + 'type' => 'radio', | |
| 279 | + 'options' => [ | |
| 280 | + 'yes' => esc_html__( 'Yes', 'cbxgooglemap' ), | |
| 281 | + 'no' => esc_html__( 'No', 'cbxgooglemap' ), | |
| 282 | + ], | |
| 283 | + 'default' => 'no', | |
| 284 | + ], | |
| 285 | + 'reset_data' => [ | |
| 286 | + 'name' => 'reset_data', | |
| 287 | + 'label' => esc_html__( 'Reset all section', 'cbxgooglemap' ), | |
| 288 | + 'desc' => $tools_delete_table_html . '<p>' . esc_html__( 'This will reset all option/section created by this plugin.', | |
| 289 | + 'cbxgooglemap' ) . '<a data-busy="0" class="button secondary ml-20" id="reset_data_trigger" href="#">' . esc_html__( 'Reset Sections', | |
| 290 | + 'cbxgooglemap' ) . '</a></p>', | |
| 291 | + 'type' => 'html', | |
| 292 | + 'default' => 'off' | |
| 293 | + ], | |
| 294 | + ], | |
| 295 | + ]; | |
| 299 | 296 | |
| 300 | 297 | |
| 301 | - $settings_fields = []; //final setting array that will be passed to different filters | |
| 302 | - $sections = $this->get_settings_sections(); | |
| 298 | + $settings_fields = []; //final setting array that will be passed to different filters | |
| 299 | + $sections = $this->get_settings_sections(); | |
| 303 | 300 | |
| 304 | - foreach ($sections as $section) { | |
| 305 | - if ( ! isset($settings_builtin_fields[$section['id']])) { | |
| 306 | - $settings_builtin_fields[$section['id']] = []; | |
| 307 | - } | |
| 308 | - } | |
| 301 | + foreach ( $sections as $section ) { | |
| 302 | + if ( ! isset( $settings_builtin_fields[ $section['id'] ] ) ) { | |
| 303 | + $settings_builtin_fields[ $section['id'] ] = []; | |
| 304 | + } | |
| 305 | + } | |
| 309 | 306 | |
| 310 | 307 | |
| 311 | - foreach ($sections as $section) { | |
| 312 | - $settings_fields[$section['id']] = apply_filters('cbxgooglemap_global_'.$section['id'].'_fields', $settings_builtin_fields[$section['id']]); | |
| 313 | - } | |
| 308 | + foreach ( $sections as $section ) { | |
| 309 | + $settings_fields[ $section['id'] ] = apply_filters( 'cbxgooglemap_global_' . $section['id'] . '_fields', $settings_builtin_fields[ $section['id'] ] ); | |
| 310 | + } | |
| 314 | 311 | |
| 315 | - return apply_filters('cbxgooglemap_global_fields', $settings_fields); | |
| 316 | - }//end get_settings_fields | |
| 312 | + return apply_filters( 'cbxgooglemap_global_fields', $settings_fields ); | |
| 313 | + }//end get_settings_fields | |
| 317 | 314 | |
| 318 | - /** | |
| 319 | - * Register Custom Post Type cbxgooglemap | |
| 320 | - * | |
| 321 | - * @since 3.7.0 | |
| 322 | - */ | |
| 323 | - public function create_post_type() | |
| 324 | - { | |
| 325 | - CBXGooglemapHelper::create_googlemap_post_type(); | |
| 315 | + /** | |
| 316 | + * Register Custom Post Type cbxgooglemap | |
| 317 | + * | |
| 318 | + * @since 3.7.0 | |
| 319 | + */ | |
| 320 | + public function create_post_type() { | |
| 321 | + CBXGooglemapHelper::create_googlemap_post_type(); | |
| 326 | 322 | |
| 327 | - // Check the option we set on activation. | |
| 328 | - if (get_option('cbxgooglemap_flush_rewrite_rules') === 'true') { | |
| 329 | - flush_rewrite_rules(); | |
| 330 | - delete_option('cbxgooglemap_flush_rewrite_rules'); | |
| 331 | - } | |
| 332 | - }//end create_post_type | |
| 323 | + // Check the option we set on activation. | |
| 324 | + if ( get_option( 'cbxgooglemap_flush_rewrite_rules' ) === 'true' ) { | |
| 325 | + flush_rewrite_rules(); | |
| 326 | + delete_option( 'cbxgooglemap_flush_rewrite_rules' ); | |
| 327 | + } | |
| 328 | + }//end create_post_type | |
| 333 | 329 | |
| 334 | 330 | |
| 335 | - /** | |
| 336 | - * Show menu page | |
| 337 | - */ | |
| 338 | - public function menu_pages() | |
| 339 | - { | |
| 340 | - //setting page | |
| 341 | - $setting_page_hook = add_submenu_page('edit.php?post_type=cbxgooglemap', esc_html__('CBX Map: Settings', 'cbxgooglemap'), esc_html__('Settings', 'cbxgooglemap'), 'manage_options', 'cbxgooglemap_settings', [ | |
| 342 | - $this, | |
| 343 | - 'menu_page_settings' | |
| 344 | - ]); | |
| 331 | + /** | |
| 332 | + * Show menu page | |
| 333 | + */ | |
| 334 | + public function menu_pages() { | |
| 335 | + //setting page | |
| 336 | + $setting_page_hook = add_submenu_page( 'edit.php?post_type=cbxgooglemap', esc_html__( 'CBX Map: Settings', 'cbxgooglemap' ), esc_html__( 'Settings', 'cbxgooglemap' ), 'manage_options', | |
| 337 | + 'cbxgooglemap_settings', [ | |
| 338 | + $this, | |
| 339 | + 'menu_page_settings' | |
| 340 | + ] ); | |
| 345 | 341 | |
| 346 | - $doc_page_hook = add_submenu_page('edit.php?post_type=cbxgooglemap', esc_html__('CBX Map Helps & Updates', 'cbxgooglemap'), esc_html__('Helps & Updates', 'cbxgooglemap'), 'manage_options', 'cbxgooglemap_support', [ | |
| 347 | - $this, | |
| 348 | - 'menu_page_docs' | |
| 349 | - ]); | |
| 350 | - }//end menu_pages | |
| 342 | + $doc_page_hook = add_submenu_page( 'edit.php?post_type=cbxgooglemap', esc_html__( 'CBX Map Helps & Updates', 'cbxgooglemap' ), esc_html__( 'Helps & Updates', 'cbxgooglemap' ), | |
| 343 | + 'manage_options', 'cbxgooglemap_support', [ | |
| 344 | + $this, | |
| 345 | + 'menu_page_docs' | |
| 346 | + ] ); | |
| 347 | + }//end menu_pages | |
| 351 | 348 | |
| 352 | - /** | |
| 353 | - * Show cbxeventz Setting page | |
| 354 | - */ | |
| 355 | - public function menu_page_settings() | |
| 356 | - { | |
| 357 | - //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 358 | - echo cbxgooglemap_get_template_html('admin/settings.php', | |
| 359 | - [ | |
| 360 | - 'ref' => $this, | |
| 361 | - 'settings' => $this->settings | |
| 362 | - ] | |
| 363 | - ); | |
| 364 | - }//end menu_page_settings | |
| 349 | + /** | |
| 350 | + * Show cbxeventz Setting page | |
| 351 | + */ | |
| 352 | + public function menu_page_settings() { | |
| 353 | + //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 354 | + echo cbxgooglemap_get_template_html( 'admin/settings.php', | |
| 355 | + [ | |
| 356 | + 'ref' => $this, | |
| 357 | + 'settings' => $this->settings | |
| 358 | + ] | |
| 359 | + ); | |
| 360 | + }//end menu_page_settings | |
| 365 | 361 | |
| 366 | - /** | |
| 367 | - * Render the help & support page for this plugin. | |
| 368 | - * | |
| 369 | - * @since 1.0.0 | |
| 370 | - */ | |
| 371 | - public function menu_page_docs() | |
| 372 | - { | |
| 373 | - echo cbxgooglemap_get_template_html('admin/support.php');//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 374 | - }//end method menu_page_docs | |
| 362 | + /** | |
| 363 | + * Render the help & support page for this plugin. | |
| 364 | + * | |
| 365 | + * @since 1.0.0 | |
| 366 | + */ | |
| 367 | + public function menu_page_docs() { | |
| 368 | + echo cbxgooglemap_get_template_html( 'admin/support.php' );//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 369 | + }//end method menu_page_docs | |
| 375 | 370 | |
| 376 | - /** | |
| 377 | - * Add metabox for custom post type cbxfeedbackform && cbxfeedbackbtn | |
| 378 | - * | |
| 379 | - * @since 1.0.0 | |
| 380 | - */ | |
| 381 | - public function add_meta_boxes() | |
| 382 | - { | |
| 383 | - add_meta_box('cbxgooglemap_metabox', esc_html__('Map Parameters', 'cbxgooglemap'), [ | |
| 384 | - $this, | |
| 385 | - 'parameter_metabox_display' | |
| 386 | - ], 'cbxgooglemap', 'normal', 'high'); | |
| 371 | + /** | |
| 372 | + * Add metabox for custom post type cbxfeedbackform && cbxfeedbackbtn | |
| 373 | + * | |
| 374 | + * @since 1.0.0 | |
| 375 | + */ | |
| 376 | + public function add_meta_boxes() { | |
| 377 | + add_meta_box( 'cbxgooglemap_metabox', esc_html__( 'Map Parameters', 'cbxgooglemap' ), [ | |
| 378 | + $this, | |
| 379 | + 'parameter_metabox_display' | |
| 380 | + ], 'cbxgooglemap', 'normal', 'high' ); | |
| 387 | 381 | |
| 388 | 382 | |
| 389 | - add_meta_box('cbxgooglemap_shortcode', esc_html__('Shortcode', 'cbxgooglemap'), [ | |
| 390 | - $this, | |
| 391 | - 'shortcode_metabox_display' | |
| 392 | - ], 'cbxgooglemap', 'side', 'low'); | |
| 393 | - }//end add_meta_boxes | |
| 383 | + add_meta_box( 'cbxgooglemap_shortcode', esc_html__( 'Shortcode', 'cbxgooglemap' ), [ | |
| 384 | + $this, | |
| 385 | + 'shortcode_metabox_display' | |
| 386 | + ], 'cbxgooglemap', 'side', 'low' ); | |
| 387 | + }//end add_meta_boxes | |
| 394 | 388 | |
| 395 | - /** | |
| 396 | - * Show Shortcode display metabox | |
| 397 | - * | |
| 398 | - * @param $post | |
| 399 | - */ | |
| 400 | - public function shortcode_metabox_display($post) | |
| 401 | - { | |
| 402 | - if (isset($post->ID) && $post->ID > 0) { | |
| 403 | - $post_id = $post->ID; | |
| 404 | - $post_type = $post->post_type; | |
| 389 | + /** | |
| 390 | + * Show Shortcode display metabox | |
| 391 | + * | |
| 392 | + * @param $post | |
| 393 | + */ | |
| 394 | + public function shortcode_metabox_display( $post ) { | |
| 395 | + if ( isset( $post->ID ) && $post->ID > 0 ) { | |
| 396 | + $post_id = $post->ID; | |
| 397 | + $post_type = $post->post_type; | |
| 405 | 398 | |
| 406 | - echo cbxgooglemap_get_template_html('admin/metabox_shortcode.php', [//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 407 | - 'post_id' => $post_id, | |
| 408 | - 'post_type' => $post_type | |
| 409 | - ]); | |
| 410 | - } | |
| 411 | - }//end shortcode_metabox_display | |
| 399 | + echo cbxgooglemap_get_template_html( 'admin/metabox_shortcode.php', [//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 400 | + 'post_id' => $post_id, | |
| 401 | + 'post_type' => $post_type | |
| 402 | + ] ); | |
| 403 | + } | |
| 404 | + }//end shortcode_metabox_display | |
| 412 | 405 | |
| 413 | - /** | |
| 414 | - * Render metabox | |
| 415 | - * | |
| 416 | - * @param $post | |
| 417 | - * | |
| 418 | - * since v1.0.0 | |
| 419 | - */ | |
| 420 | - public function parameter_metabox_display($post) | |
| 421 | - { | |
| 422 | - global $post; | |
| 423 | - $post_type = $post->post_type; | |
| 406 | + /** | |
| 407 | + * Render metabox | |
| 408 | + * | |
| 409 | + * @param $post | |
| 410 | + * | |
| 411 | + * since v1.0.0 | |
| 412 | + */ | |
| 413 | + public function parameter_metabox_display( $post ) { | |
| 414 | + global $post; | |
| 415 | + $post_type = $post->post_type; | |
| 424 | 416 | |
| 425 | 417 | |
| 426 | - $meta_fields = CBXGooglemapMetaHelper::cbxgooglemap_meta_fields(); | |
| 418 | + $meta_fields = CBXGooglemapMetaHelper::cbxgooglemap_meta_fields(); | |
| 427 | 419 | |
| 428 | - $combined_field = '_'.$post_type.'_combined'; //field name for non sortable fields | |
| 429 | - $meta_prefix = '_'.$post_type; //field prefix for sortable fields | |
| 420 | + $combined_field = '_' . $post_type . '_combined'; //field name for non sortable fields | |
| 421 | + $meta_prefix = '_' . $post_type; //field prefix for sortable fields | |
| 430 | 422 | |
| 431 | 423 | |
| 432 | - CBXGooglemapMetaHelper::render_meta_fields($post, $meta_fields, $combined_field, $meta_prefix, true); // | |
| 433 | - }//end parameter_metabox_display | |
| 424 | + CBXGooglemapMetaHelper::render_meta_fields( $post, $meta_fields, $combined_field, $meta_prefix, true ); // | |
| 425 | + }//end parameter_metabox_display | |
| 434 | 426 | |
| 435 | - /** | |
| 436 | - * Save meta box for cbxeventz | |
| 437 | - * | |
| 438 | - * @param $post_id | |
| 439 | - */ | |
| 440 | - public function metabox_save($post_id, $post, $update) | |
| 441 | - { | |
| 427 | + /** | |
| 428 | + * Save meta box for cbxeventz | |
| 429 | + * | |
| 430 | + * @param $post_id | |
| 431 | + */ | |
| 432 | + public function metabox_save( $post_id, $post, $update ) { | |
| 442 | 433 | |
| 443 | - $post_type = $post->post_type; | |
| 434 | + $post_type = $post->post_type; | |
| 444 | 435 | |
| 445 | - // Check if our nonce is set. | |
| 446 | - if ( ! isset($_POST['cbxmetahelper_'.$post_type.'_meta_box_nonce'])) { | |
| 447 | - return $post_id; | |
| 448 | - } | |
| 436 | + // Check if our nonce is set. | |
| 437 | + if ( ! isset( $_POST[ 'cbxmetahelper_' . $post_type . '_meta_box_nonce' ] ) ) { | |
| 438 | + return $post_id; | |
| 439 | + } | |
| 449 | 440 | |
| 450 | - // Verify that the nonce is valid. | |
| 451 | - if ( ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['cbxmetahelper_'.$post_type.'_meta_box_nonce'])), 'cbxmetahelper_'.$post_type.'_meta_box')) { | |
| 452 | - return $post_id; | |
| 453 | - } | |
| 441 | + // Verify that the nonce is valid. | |
| 442 | + if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ 'cbxmetahelper_' . $post_type . '_meta_box_nonce' ] ) ), 'cbxmetahelper_' . $post_type . '_meta_box' ) ) { | |
| 443 | + return $post_id; | |
| 444 | + } | |
| 454 | 445 | |
| 455 | - // If this is an autosave, our form has not been submitted, so we don't want to do anything. | |
| 456 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { | |
| 457 | - return $post_id; | |
| 458 | - } | |
| 446 | + // If this is an autosave, our form has not been submitted, so we don't want to do anything. | |
| 447 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
| 448 | + return $post_id; | |
| 449 | + } | |
| 459 | 450 | |
| 460 | - // Check the user's permissions. | |
| 461 | - if (isset($_POST['post_type']) && $post_type == $_POST['post_type']) { | |
| 451 | + // Check the user's permissions. | |
| 452 | + if ( isset( $_POST['post_type'] ) && $post_type == $_POST['post_type'] ) { | |
| 462 | 453 | |
| 463 | - if ( ! current_user_can('edit_post', $post_id)) { | |
| 464 | - return $post_id; | |
| 465 | - } | |
| 466 | - } | |
| 454 | + if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
| 455 | + return $post_id; | |
| 456 | + } | |
| 457 | + } | |
| 467 | 458 | |
| 468 | - $meta_fields = CBXGooglemapMetaHelper::cbxgooglemap_meta_fields($post_id); | |
| 459 | + $meta_fields = CBXGooglemapMetaHelper::cbxgooglemap_meta_fields( $post_id ); | |
| 469 | 460 | |
| 470 | 461 | |
| 471 | - $combined_field = '_'.$post_type.'_combined'; //field name for non sortable fields | |
| 472 | - $meta_prefix = '_'.$post_type; //field prefix for sortable fields | |
| 462 | + $combined_field = '_' . $post_type . '_combined'; //field name for non sortable fields | |
| 463 | + $meta_prefix = '_' . $post_type; //field prefix for sortable fields | |
| 473 | 464 | |
| 474 | - $meta_combined = get_post_meta($post_id, $combined_field, true); //meta fields not sortable | |
| 465 | + $meta_combined = get_post_meta( $post_id, $combined_field, true ); //meta fields not sortable | |
| 475 | 466 | |
| 476 | - $meta_combined = ! is_array($meta_combined) ? [] : $meta_combined; | |
| 467 | + $meta_combined = ! is_array( $meta_combined ) ? [] : $meta_combined; | |
| 477 | 468 | |
| 478 | 469 | |
| 479 | - $combined_arr = []; | |
| 480 | - foreach ($meta_fields as $section_id => $fields) { | |
| 481 | - foreach ($fields as $id => $field) { | |
| 470 | + $combined_arr = []; | |
| 471 | + foreach ( $meta_fields as $section_id => $fields ) { | |
| 472 | + foreach ( $fields as $id => $field ) { | |
| 482 | 473 | |
| 483 | - $field_type = $field['type']; | |
| 474 | + $field_type = $field['type']; | |
| 484 | 475 | |
| 485 | - $sanitize_callback = isset($field['sanitize_callback']) ? $field['sanitize_callback'] : null; | |
| 476 | + $sanitize_callback = isset( $field['sanitize_callback'] ) ? $field['sanitize_callback'] : null; | |
| 486 | 477 | |
| 487 | - if (isset($_POST[$meta_prefix.$id])) { | |
| 478 | + if ( isset( $_POST[ $meta_prefix . $id ] ) ) { | |
| 488 | 479 | |
| 489 | - if (isset($_POST[$meta_prefix.$id])) { | |
| 490 | - $updated_value = sanitize_text_field(wp_unslash($_POST[$meta_prefix.$id])); | |
| 480 | + if ( isset( $_POST[ $meta_prefix . $id ] ) ) { | |
| 481 | + $updated_value = wp_unslash( $_POST[ $meta_prefix . $id ] );//phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 482 | + $updated_value = is_array( $updated_value ) ? cbxgooglemap_decode_entities_array( $updated_value ) : html_entity_decode( $updated_value ); | |
| 491 | 483 | |
| 484 | + $sanitized = false; | |
| 492 | 485 | |
| 493 | - if ($field_type == 'text') { | |
| 494 | - $updated_value = sanitize_text_field(wp_unslash($updated_value)); | |
| 495 | - } elseif ($field_type == 'textarea') { | |
| 496 | - $updated_value = sanitize_textarea_field(wp_unslash($updated_value)); | |
| 497 | - } else { | |
| 498 | - if ($sanitize_callback !== null && is_callable($sanitize_callback)) { | |
| 499 | - $updated_value = call_user_func($sanitize_callback, $updated_value); | |
| 500 | - } | |
| 501 | - } | |
| 486 | + if ( $sanitize_callback !== null && is_callable( $sanitize_callback ) ) { | |
| 487 | + $sanitized = true; | |
| 488 | + $updated_value = call_user_func( $sanitize_callback, $updated_value ); | |
| 489 | + } elseif ( $field_type == 'text' ) { | |
| 490 | + $sanitized = true; | |
| 491 | + $updated_value = sanitize_text_field( $updated_value ); | |
| 492 | + } elseif ( $field_type == 'textarea' ) { | |
| 493 | + $sanitized = true; | |
| 494 | + $updated_value = sanitize_textarea_field( $updated_value ); | |
| 495 | + } | |
| 502 | 496 | |
| 503 | - $is_sortable = isset($field['sortable']) ? $field['sortable'] : false; | |
| 497 | + if ( ! $sanitized ) { | |
| 498 | + $updated_value = wp_kses_post( $updated_value );//general sanitization | |
| 499 | + } | |
| 504 | 500 | |
| 505 | - if ($is_sortable) { | |
| 506 | - $ret = update_post_meta($post_id, $meta_prefix.$id, $updated_value); //update the combined meta | |
| 507 | - } else { | |
| 508 | - //save as combined meta | |
| 509 | - $meta_combined[$meta_prefix.$id] = $updated_value; | |
| 510 | - } | |
| 511 | - } | |
| 501 | + $updated_value = apply_filters( 'cbxgooglemap_meta_sanitize_admin', $updated_value, $id, $field, $fields ); | |
| 512 | 502 | |
| 513 | - } | |
| 503 | + $is_sortable = isset( $field['sortable'] ) ? $field['sortable'] : false; | |
| 514 | 504 | |
| 515 | - } | |
| 516 | - } | |
| 505 | + if ( $is_sortable ) { | |
| 506 | + $ret = update_post_meta( $post_id, $meta_prefix . $id, $updated_value ); //update the combined meta | |
| 507 | + } else { | |
| 508 | + //save as combined meta | |
| 509 | + $meta_combined[ $meta_prefix . $id ] = $updated_value; | |
| 510 | + } | |
| 511 | + } | |
| 517 | 512 | |
| 518 | - update_post_meta($post_id, $combined_field, $meta_combined); //update the combined meta | |
| 513 | + } | |
| 519 | 514 | |
| 520 | - do_action('cbxgooglemap_metabox_save', $post_id); | |
| 515 | + } | |
| 516 | + } | |
| 521 | 517 | |
| 522 | - }//end metabox_save | |
| 518 | + update_post_meta( $post_id, $combined_field, $meta_combined ); //update the combined meta | |
| 523 | 519 | |
| 524 | - /** | |
| 525 | - * Add or adjust col for cbxgooglemap post type | |
| 526 | - * | |
| 527 | - * @param $cbxpoll_columns | |
| 528 | - * | |
| 529 | - * @return array | |
| 530 | - * | |
| 531 | - */ | |
| 532 | - public function cbxgooglemap_add_new_columns($columns) | |
| 533 | - { | |
| 534 | - unset($columns['date']); | |
| 535 | - unset($columns['comments']); | |
| 520 | + do_action( 'cbxgooglemap_metabox_save', $post_id ); | |
| 536 | 521 | |
| 537 | - $columns['lat'] = esc_attr('Latitude', 'cbxgooglemap'); | |
| 538 | - $columns['lng'] = esc_attr('Longitude', 'cbxgooglemap'); | |
| 539 | - $columns['zoom'] = esc_attr('Zoom', 'cbxgooglemap'); | |
| 522 | + }//end metabox_save | |
| 540 | 523 | |
| 541 | - //$columns['shortcode'] = esc_attr( 'Shortcode', 'cbxgooglemap' ); | |
| 524 | + /** | |
| 525 | + * Add or adjust col for cbxgooglemap post type | |
| 526 | + * | |
| 527 | + * @param $cbxpoll_columns | |
| 528 | + * | |
| 529 | + * @return array | |
| 530 | + * | |
| 531 | + */ | |
| 532 | + public function cbxgooglemap_add_new_columns( $columns ) { | |
| 533 | + unset( $columns['date'] ); | |
| 534 | + unset( $columns['comments'] ); | |
| 542 | 535 | |
| 543 | - return $columns; | |
| 544 | - }//end cbxgooglemap_add_new_columns | |
| 536 | + $columns['lat'] = esc_attr( 'Latitude', 'cbxgooglemap' ); | |
| 537 | + $columns['lng'] = esc_attr( 'Longitude', 'cbxgooglemap' ); | |
| 538 | + $columns['zoom'] = esc_attr( 'Zoom', 'cbxgooglemap' ); | |
| 545 | 539 | |
| 546 | - /** | |
| 547 | - * Add extra cols information for cbxgooglemap post type | |
| 548 | - * | |
| 549 | - * @param $column_name | |
| 550 | - * | |
| 551 | - * | |
| 552 | - * show data to poll table custom column | |
| 553 | - */ | |
| 554 | - public function cbxgooglemap_manage_columns($column_name) | |
| 555 | - { | |
| 556 | - global $wpdb, $post; | |
| 540 | + //$columns['shortcode'] = esc_attr( 'Shortcode', 'cbxgooglemap' ); | |
| 557 | 541 | |
| 558 | - $post_id = intval($post->ID); | |
| 559 | - $post_type = $post->post_type; | |
| 542 | + return $columns; | |
| 543 | + }//end cbxgooglemap_add_new_columns | |
| 560 | 544 | |
| 561 | - $combined_field = '_cbxgooglemap_combined'; //field name for non sortable fields | |
| 562 | - $meta_prefix = '_cbxgooglemap'; //field prefix for sortable fields | |
| 545 | + /** | |
| 546 | + * Add extra cols information for cbxgooglemap post type | |
| 547 | + * | |
| 548 | + * @param $column_name | |
| 549 | + * | |
| 550 | + * | |
| 551 | + * show data to poll table custom column | |
| 552 | + */ | |
| 553 | + public function cbxgooglemap_manage_columns( $column_name ) { | |
| 554 | + global $wpdb, $post; | |
| 563 | 555 | |
| 564 | - $meta_combined = get_post_meta($post_id, $combined_field, true); | |
| 556 | + $post_id = intval( $post->ID ); | |
| 557 | + $post_type = $post->post_type; | |
| 565 | 558 | |
| 566 | - $lat = get_post_meta($post_id, $meta_prefix.'lat', true); | |
| 567 | - $lat = ($lat !== false) ? $lat : ''; | |
| 559 | + $combined_field = '_cbxgooglemap_combined'; //field name for non sortable fields | |
| 560 | + $meta_prefix = '_cbxgooglemap'; //field prefix for sortable fields | |
| 568 | 561 | |
| 569 | - $lng = get_post_meta($post_id, $meta_prefix.'lng', true); | |
| 570 | - $lng = ($lng !== false) ? $lng : ''; | |
| 562 | + $meta_combined = get_post_meta( $post_id, $combined_field, true ); | |
| 571 | 563 | |
| 572 | - $zoom = (isset($meta_combined[$meta_prefix.'zoom']) && intval($meta_combined[$meta_prefix.'zoom']) > 0) ? intval($meta_combined[$meta_prefix.'zoom']) : ''; | |
| 564 | + $lat = get_post_meta( $post_id, $meta_prefix . 'lat', true ); | |
| 565 | + $lat = ( $lat !== false ) ? $lat : ''; | |
| 573 | 566 | |
| 567 | + $lng = get_post_meta( $post_id, $meta_prefix . 'lng', true ); | |
| 568 | + $lng = ( $lng !== false ) ? $lng : ''; | |
| 574 | 569 | |
| 575 | - switch ($column_name) { | |
| 576 | - /*case 'shortcode': | |
| 577 | - echo '<div class="cbxshortcode-wrap">'; | |
| 578 | - echo '<span data-clipboard-text=\'[cbxgooglemap id="' . absint( $post_id ) . '"]\' title="' . esc_html__( 'Click to clipboard', 'cbxgooglemap' ) . '" id="cbxgooglemapshortcode-' . absint( $post_id ) . '" class="cbxshortcode cbxshortcode-edit cbxshortcode-' . absint( $post_id ) . '">[cbxgooglemap id="' . absint( $post_id ) . '"]</span>'; | |
| 579 | - echo '<span class="cbxballon_ctp_btn cbxballon_ctp" aria-label="' . esc_html__( 'Click to copy', 'cbxgooglemap' ) . '" data-balloon-pos="up"><i></i></span>'; | |
| 580 | - echo '</div>'; | |
| 581 | - break;*/ | |
| 582 | - case 'lat': | |
| 583 | - echo esc_html($lat); | |
| 584 | - break; | |
| 585 | - case 'lng': | |
| 586 | - echo esc_html($lng); | |
| 587 | - break; | |
| 588 | - case 'zoom': | |
| 589 | - echo esc_html($zoom); | |
| 590 | - break; | |
| 591 | - default: | |
| 592 | - break; | |
| 593 | - } // end switch | |
| 594 | - }//end cbxgooglemap_manage_columns | |
| 570 | + $zoom = ( isset( $meta_combined[ $meta_prefix . 'zoom' ] ) && absint( $meta_combined[ $meta_prefix . 'zoom' ] ) > 0 ) ? absint( $meta_combined[ $meta_prefix . 'zoom' ] ) : ''; | |
| 595 | 571 | |
| 596 | - /** | |
| 597 | - * Register the stylesheets for the admin area. | |
| 598 | - * | |
| 599 | - * @since 1.0.0 | |
| 600 | - */ | |
| 601 | - public function enqueue_styles($hook) | |
| 602 | - { | |
| 603 | - $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';// phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 604 | - $ver = $this->version; | |
| 605 | - $in_footer = [ | |
| 606 | - 'in_footer' => true, | |
| 607 | - ]; | |
| 608 | 572 | |
| 609 | - $vendor_url = CBXGOOGLEMAP_ROOT_URL.'assets/vendors/'; | |
| 610 | - //$css_url = CBXGOOGLEMAP_ROOT_URL . 'assets/css/'; | |
| 611 | - //$js_url = CBXGOOGLEMAP_ROOT_URL . 'assets/css/'; | |
| 573 | + switch ( $column_name ) { | |
| 574 | + /*case 'shortcode': | |
| 575 | + echo '<div class="cbxshortcode-wrap">'; | |
| 576 | + echo '<span data-clipboard-text=\'[cbxgooglemap id="' . absint( $post_id ) . '"]\' title="' . esc_html__( 'Click to clipboard', 'cbxgooglemap' ) . '" id="cbxgooglemapshortcode-' . absint( $post_id ) . '" class="cbxshortcode cbxshortcode-edit cbxshortcode-' . absint( $post_id ) . '">[cbxgooglemap id="' . absint( $post_id ) . '"]</span>'; | |
| 577 | + echo '<span class="cbxballon_ctp_btn cbxballon_ctp" aria-label="' . esc_html__( 'Click to copy', 'cbxgooglemap' ) . '" data-balloon-pos="up"><i></i></span>'; | |
| 578 | + echo '</div>'; | |
| 579 | + break;*/ | |
| 580 | + case 'lat': | |
| 581 | + echo esc_html( $lat ); | |
| 582 | + break; | |
| 583 | + case 'lng': | |
| 584 | + echo esc_html( $lng ); | |
| 585 | + break; | |
| 586 | + case 'zoom': | |
| 587 | + echo esc_html( $zoom ); | |
| 588 | + break; | |
| 589 | + default: | |
| 590 | + break; | |
| 591 | + } // end switch | |
| 592 | + }//end cbxgooglemap_manage_columns | |
| 612 | 593 | |
| 613 | - $css_url_part = CBXGOOGLEMAP_ROOT_URL.'assets/css/'; | |
| 614 | - $css_url_part_vendors = CBXGOOGLEMAP_ROOT_URL.'assets/vendors/'; | |
| 615 | - $js_url_part_vendors = CBXGOOGLEMAP_ROOT_URL.'assets/vendors/'; | |
| 594 | + /** | |
| 595 | + * Register the stylesheets for the admin area. | |
| 596 | + * | |
| 597 | + * @since 1.0.0 | |
| 598 | + */ | |
| 599 | + public function enqueue_styles( $hook ) { | |
| 600 | + $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';// phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 601 | + $ver = $this->version; | |
| 602 | + $in_footer = [ | |
| 603 | + 'in_footer' => true, | |
| 604 | + ]; | |
| 616 | 605 | |
| 617 | - global $post_type, $post; | |
| 606 | + $vendor_url = CBXGOOGLEMAP_ROOT_URL . 'assets/vendors/'; | |
| 607 | + //$css_url = CBXGOOGLEMAP_ROOT_URL . 'assets/css/'; | |
| 608 | + //$js_url = CBXGOOGLEMAP_ROOT_URL . 'assets/css/'; | |
| 618 | 609 | |
| 619 | - $api_key = esc_attr($this->settings->get_option('apikey', 'cbxgooglemap_general', '')); | |
| 620 | - $map_source = absint($this->settings->get_option('mapsource', 'cbxgooglemap_general', 1)); | |
| 610 | + $css_url_part = CBXGOOGLEMAP_ROOT_URL . 'assets/css/'; | |
| 611 | + $css_url_part_vendors = CBXGOOGLEMAP_ROOT_URL . 'assets/vendors/'; | |
| 612 | + $js_url_part_vendors = CBXGOOGLEMAP_ROOT_URL . 'assets/vendors/'; | |
| 621 | 613 | |
| 622 | - wp_register_style('awesome-notifications', $css_url_part_vendors.'awesome-notifications/style.css', [], $ver); | |
| 623 | - wp_register_style('flatpickr', $css_url_part_vendors.'flatpickr/flatpickr.min.css', [], $ver); | |
| 624 | - wp_register_style('cbxgooglemap-admin', $css_url_part.'cbxgooglemap-admin.css', [], $ver); | |
| 614 | + global $post_type, $post; | |
| 625 | 615 | |
| 626 | - //listing mode | |
| 627 | - if (($hook == 'edit.php') && $post_type == 'cbxgooglemap') { | |
| 628 | - wp_register_style('cbxgooglemap-admin', $css_url_part.'cbxgooglemap-admin.css', [], $ver); | |
| 629 | - wp_enqueue_style('cbxgooglemap-admin'); | |
| 630 | - } | |
| 616 | + $api_key = esc_attr( $this->settings->get_option( 'apikey', 'cbxgooglemap_general', '' ) ); | |
| 617 | + $map_source = absint( $this->settings->get_option( 'mapsource', 'cbxgooglemap_general', 1 ) ); | |
| 631 | 618 | |
| 632 | - //add new, edit mode | |
| 633 | - if (($hook == 'post.php' || $hook == 'post-new.php') && $post_type == 'cbxgooglemap') { | |
| 619 | + wp_register_style( 'awesome-notifications', $css_url_part_vendors . 'awesome-notifications/style.css', [], $ver ); | |
| 620 | + wp_register_style( 'flatpickr', $css_url_part_vendors . 'flatpickr/flatpickr.min.css', [], $ver ); | |
| 621 | + wp_register_style( 'cbxgooglemap-admin', $css_url_part . 'cbxgooglemap-admin.css', [], $ver ); | |
| 634 | 622 | |
| 635 | - if ($map_source == 0) { | |
| 636 | - wp_register_style('leaflet', $vendor_url.'leaflet/leaflet.css', [], $ver, 'all'); | |
| 637 | - wp_register_style('leaflet-control-geocoder', $vendor_url.'leaflet-control-geocoder/Control.Geocoder.css', [], $ver, 'all'); | |
| 638 | - } | |
| 623 | + //listing mode | |
| 624 | + if ( ( $hook === 'edit.php' ) && $post_type === 'cbxgooglemap' ) { | |
| 625 | + wp_register_style( 'cbxgooglemap-admin', $css_url_part . 'cbxgooglemap-admin.css', [], $ver ); | |
| 626 | + wp_enqueue_style( 'cbxgooglemap-admin' ); | |
| 627 | + } | |
| 639 | 628 | |
| 640 | - wp_register_style('select2', $vendor_url.'select2/select2.min.css', [], $ver); | |
| 641 | - wp_register_style('cbxgooglemap-admin', $css_url_part.'cbxgooglemap-admin.css', [ | |
| 642 | - 'select2', | |
| 643 | - ], $ver); | |
| 629 | + //add new, edit mode | |
| 630 | + if ( ( $hook === 'post.php' || $hook === 'post-new.php' ) && $post_type === 'cbxgooglemap' ) { | |
| 644 | 631 | |
| 645 | - wp_enqueue_style('select2'); | |
| 632 | + if ( $map_source === 0 ) { | |
| 633 | + wp_register_style( 'leaflet', $vendor_url . 'leaflet/leaflet.css', [], $ver, 'all' ); | |
| 634 | + wp_register_style( 'leaflet-control-geocoder', $vendor_url . 'leaflet-control-geocoder/Control.Geocoder.css', [], $ver, 'all' ); | |
| 635 | + } | |
| 646 | 636 | |
| 647 | - if ($map_source == 0) { | |
| 648 | - wp_enqueue_style('leaflet'); | |
| 649 | - wp_enqueue_style('leaflet-control-geocoder'); | |
| 650 | - } | |
| 637 | + wp_register_style( 'select2', $vendor_url . 'select2/select2.min.css', [], $ver ); | |
| 638 | + wp_register_style( 'cbxgooglemap-admin', $css_url_part . 'cbxgooglemap-admin.css', [ | |
| 639 | + 'select2', | |
| 640 | + ], $ver ); | |
| 651 | 641 | |
| 652 | - wp_enqueue_style('awesome-notifications'); | |
| 653 | - wp_enqueue_style('cbxgooglemap-admin'); | |
| 654 | - }//add new, edit mode | |
| 642 | + wp_enqueue_style( 'select2' ); | |
| 655 | 643 | |
| 656 | - if ($current_page == 'cbxgooglemap_settings') { | |
| 657 | - wp_register_style('pickr', $css_url_part_vendors.'pickr/classic.min.css', [], $ver); | |
| 658 | - wp_register_style('select2', $css_url_part_vendors.'select2/select2.min.css', [], $ver); | |
| 644 | + if ( $map_source == 0 ) { | |
| 645 | + wp_enqueue_style( 'leaflet' ); | |
| 646 | + wp_enqueue_style( 'leaflet-control-geocoder' ); | |
| 647 | + } | |
| 659 | 648 | |
| 660 | - wp_register_style('cbxgooglemap-setting', $css_url_part.'cbxgooglemap-setting.css', [ | |
| 661 | - 'pickr', | |
| 662 | - 'awesome-notifications', | |
| 663 | - 'select2', | |
| 664 | - 'cbxgooglemap-admin' | |
| 665 | - ], $ver); | |
| 649 | + wp_enqueue_style( 'awesome-notifications' ); | |
| 650 | + wp_enqueue_style( 'cbxgooglemap-admin' ); | |
| 651 | + }//add new, edit mode | |
| 666 | 652 | |
| 667 | - wp_enqueue_style('pickr'); | |
| 668 | - wp_enqueue_style('awesome-notifications'); | |
| 669 | - wp_enqueue_style('select2'); | |
| 653 | + if ( $current_page === 'cbxgooglemap_settings' ) { | |
| 654 | + wp_register_style( 'pickr', $css_url_part_vendors . 'pickr/classic.min.css', [], $ver ); | |
| 655 | + wp_register_style( 'select2', $css_url_part_vendors . 'select2/select2.min.css', [], $ver ); | |
| 670 | 656 | |
| 671 | - //for demo css | |
| 672 | - if ($map_source == 0) { | |
| 673 | - wp_register_style('leaflet', $vendor_url.'leaflet/leaflet.css', [], $ver, 'all'); | |
| 674 | - wp_register_style('cbxgooglemap-public', $css_url_part.'cbxgooglemap-public.css', ['leaflet'], $ver, 'all'); | |
| 675 | - wp_enqueue_style('leaflet'); | |
| 657 | + wp_register_style( 'cbxgooglemap-setting', $css_url_part . 'cbxgooglemap-setting.css', [ | |
| 658 | + 'pickr', | |
| 659 | + 'awesome-notifications', | |
| 660 | + 'select2', | |
| 661 | + 'cbxgooglemap-admin' | |
| 662 | + ], $ver ); | |
| 676 | 663 | |
| 677 | - } else { | |
| 678 | - wp_register_style('cbxgooglemap-public', $css_url_part.'cbxgooglemap-public.css', [], $ver, 'all'); | |
| 679 | - } | |
| 664 | + wp_enqueue_style( 'pickr' ); | |
| 665 | + wp_enqueue_style( 'awesome-notifications' ); | |
| 666 | + wp_enqueue_style( 'select2' ); | |
| 680 | 667 | |
| 681 | - wp_enqueue_style('cbxgooglemap-public'); | |
| 682 | - wp_enqueue_style('cbxgooglemap-admin'); | |
| 683 | - wp_enqueue_style('cbxgooglemap-setting'); | |
| 668 | + //for demo css | |
| 669 | + if ( $map_source === 0 ) { | |
| 670 | + wp_register_style( 'leaflet', $vendor_url . 'leaflet/leaflet.css', [], $ver, 'all' ); | |
| 671 | + wp_register_style( 'cbxgooglemap-public', $css_url_part . 'cbxgooglemap-public.css', [ 'leaflet' ], $ver, 'all' ); | |
| 672 | + wp_enqueue_style( 'leaflet' ); | |
| 684 | 673 | |
| 685 | - //end for demo css | |
| 686 | - }//end setting | |
| 674 | + } else { | |
| 675 | + wp_register_style( 'cbxgooglemap-public', $css_url_part . 'cbxgooglemap-public.css', [], $ver, 'all' ); | |
| 676 | + } | |
| 687 | 677 | |
| 688 | - if ($current_page == 'cbxgooglemap_support') { | |
| 689 | - wp_enqueue_style('cbxgooglemap-admin'); | |
| 690 | - }//end style adding for doc page | |
| 678 | + wp_enqueue_style( 'cbxgooglemap-public' ); | |
| 679 | + wp_enqueue_style( 'cbxgooglemap-admin' ); | |
| 680 | + wp_enqueue_style( 'cbxgooglemap-setting' ); | |
| 691 | 681 | |
| 692 | - //tax pages | |
| 693 | - if (($hook == 'edit-tags.php' || $hook == 'term.php') && $post_type == 'cbxgooglemap' && $current_page == '') { | |
| 694 | - wp_enqueue_style('awesome-notifications'); | |
| 695 | - wp_enqueue_style('cbxgooglemap-admin'); | |
| 696 | - } | |
| 697 | - }//end enqueue_styles | |
| 682 | + //end for demo css | |
| 683 | + }//end setting | |
| 698 | 684 | |
| 699 | - /** | |
| 700 | - * Register the JavaScript for the admin area. | |
| 701 | - * | |
| 702 | - * @since 1.0.0 | |
| 703 | - */ | |
| 704 | - public function enqueue_scripts($hook) | |
| 705 | - { | |
| 706 | - $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';// phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 707 | - $ver = $this->version; | |
| 708 | - $in_footer = [ | |
| 709 | - 'in_footer' => true, | |
| 710 | - ]; | |
| 685 | + if ( $current_page === 'cbxgooglemap_support' ) { | |
| 686 | + wp_enqueue_style( 'cbxgooglemap-admin' ); | |
| 687 | + }//end style adding for doc page | |
| 711 | 688 | |
| 712 | - $vendor_url = CBXGOOGLEMAP_ROOT_URL.'assets/vendors/'; | |
| 713 | - $css_url = CBXGOOGLEMAP_ROOT_URL.'assets/css/'; | |
| 714 | - $js_url = CBXGOOGLEMAP_ROOT_URL.'assets/js/'; | |
| 689 | + //tax pages | |
| 690 | + if ( ( $hook === 'edit-tags.php' || $hook === 'term.php' ) && $post_type === 'cbxgooglemap' && $current_page == '' ) { | |
| 691 | + wp_enqueue_style( 'awesome-notifications' ); | |
| 692 | + wp_enqueue_style( 'cbxgooglemap-admin' ); | |
| 693 | + } | |
| 694 | + }//end enqueue_styles | |
| 715 | 695 | |
| 716 | - //assets urls | |
| 717 | - $js_url_part = CBXGOOGLEMAP_ROOT_URL.'assets/js/'; | |
| 718 | - $js_url_part_vendors = CBXGOOGLEMAP_ROOT_URL.'assets/vendors/'; | |
| 719 | - $js_url_part_vanila = CBXGOOGLEMAP_ROOT_URL.'assets/js/vanila/'; | |
| 720 | - $js_url_part_build = CBXGOOGLEMAP_ROOT_URL.'assets/js/build/'; | |
| 696 | + /** | |
| 697 | + * Register the JavaScript for the admin area. | |
| 698 | + * | |
| 699 | + * @since 1.0.0 | |
| 700 | + */ | |
| 701 | + public function enqueue_scripts( $hook ) { | |
| 702 | + $current_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';// phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 703 | + $ver = $this->version; | |
| 704 | + $in_footer = [ | |
| 705 | + 'in_footer' => true, | |
| 706 | + ]; | |
| 721 | 707 | |
| 708 | + $vendor_url = CBXGOOGLEMAP_ROOT_URL . 'assets/vendors/'; | |
| 709 | + $css_url = CBXGOOGLEMAP_ROOT_URL . 'assets/css/'; | |
| 710 | + $js_url = CBXGOOGLEMAP_ROOT_URL . 'assets/js/'; | |
| 722 | 711 | |
| 723 | - $t = true; | |
| 724 | - $f = false; | |
| 712 | + //assets urls | |
| 713 | + $js_url_part = CBXGOOGLEMAP_ROOT_URL . 'assets/js/'; | |
| 714 | + $js_url_part_vendors = CBXGOOGLEMAP_ROOT_URL . 'assets/vendors/'; | |
| 715 | + $js_url_part_vanila = CBXGOOGLEMAP_ROOT_URL . 'assets/js/vanila/'; | |
| 716 | + $js_url_part_build = CBXGOOGLEMAP_ROOT_URL . 'assets/js/build/'; | |
| 725 | 717 | |
| 726 | 718 | |
| 727 | - $in_footer = [ | |
| 728 | - 'in_footer' => $t, | |
| 729 | - ]; | |
| 719 | + $t = true; | |
| 720 | + $f = false; | |
| 730 | 721 | |
| 731 | - $in_footer_async = [ | |
| 732 | - 'in_footer' => $t, | |
| 733 | - 'strategy' => 'async' | |
| 734 | - ]; | |
| 735 | 722 | |
| 736 | - $global_translation = CBXGooglemapHelper::global_translation_strings(); | |
| 737 | - $plus_svg = cbxgooglemap_esc_svg(cbxgooglemap_load_svg('icon_plus')); | |
| 723 | + $in_footer = [ | |
| 724 | + 'in_footer' => $t, | |
| 725 | + ]; | |
| 738 | 726 | |
| 727 | + $in_footer_async = [ | |
| 728 | + 'in_footer' => $t, | |
| 729 | + 'strategy' => 'async' | |
| 730 | + ]; | |
| 739 | 731 | |
| 740 | - global $post_type, $post; | |
| 741 | - $post_id = isset($post->ID) ? absint($post->ID) : 0; | |
| 732 | + $global_translation = CBXGooglemapHelper::global_translation_strings(); | |
| 733 | + $plus_svg = cbxgooglemap_esc_svg( cbxgooglemap_load_svg( 'icon_plus' ) ); | |
| 742 | 734 | |
| 743 | - $api_key = esc_attr($this->settings->get_option('apikey', 'cbxgooglemap_general', '')); | |
| 744 | - $map_source = absint($this->settings->get_option('mapsource', 'cbxgooglemap_general', 1)); | |
| 745 | - $default_mapicon = esc_url($this->settings->get_option('mapicon', 'cbxgooglemap_general', '')); | |
| 746 | 735 | |
| 747 | - /*if($default_mapicon == ''){ | |
| 748 | - $default_mapicon = 'https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-poi.png'; | |
| 749 | - }*/ | |
| 736 | + global $post_type, $post; | |
| 737 | + $post_id = isset( $post->ID ) ? absint( $post->ID ) : 0; | |
| 750 | 738 | |
| 751 | - /*$zoom_level_default = intval( $this->settings->get_option( 'zoom', 'cbxgooglemap_general', '8' ) ); | |
| 752 | - if ( $zoom_level_default == 0 ) { | |
| 753 | - $zoom_level_default = 8; | |
| 754 | - }*/ | |
| 739 | + $api_key = esc_attr( $this->settings->get_option( 'apikey', 'cbxgooglemap_general', '' ) ); | |
| 740 | + $map_source = absint( $this->settings->get_option( 'mapsource', 'cbxgooglemap_general', 1 ) ); | |
| 741 | + $default_mapicon = esc_url( $this->settings->get_option( 'mapicon', 'cbxgooglemap_general', '' ) ); | |
| 755 | 742 | |
| 743 | + /*if($default_mapicon == ''){ | |
| 744 | + $default_mapicon = 'https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-poi.png'; | |
| 745 | + }*/ | |
| 756 | 746 | |
| 757 | - wp_register_script('cbxgooglemap-events', $js_url.'cbxgooglemap-events.js', [], $ver, $in_footer); | |
| 758 | - wp_register_script('awesome-notifications', $js_url_part_vendors.'awesome-notifications/script.js', [], $ver, $in_footer); | |
| 759 | - wp_register_script('select2', $js_url_part_vendors.'select2/select2.min.js', ['jquery'], $ver, $in_footer); | |
| 760 | - //wp_register_script( 'flatpickr', $js_url_part_vendors . 'flatpickr/flatpickr.min.js', [ 'jquery' ], $ver, true ); | |
| 761 | - wp_register_script('pickr', $js_url_part_vendors.'pickr/pickr.min.js', [], $ver, $in_footer); | |
| 762 | - //wp_register_script( 'jquery-validate', $js_url_part_vendors . 'jquery-validation/jquery.validate.min.js', [ 'jquery' ], $ver, $in_footer ); | |
| 747 | + /*$zoom_level_default = intval( $this->settings->get_option( 'zoom', 'cbxgooglemap_general', '8' ) ); | |
| 748 | + if ( $zoom_level_default == 0 ) { | |
| 749 | + $zoom_level_default = 8; | |
| 750 | + }*/ | |
| 763 | 751 | |
| 764 | - //maps listing mode | |
| 765 | - if ($hook == 'edit.php' && $post_type == 'cbxgooglemap') { | |
| 766 | - wp_register_script('cbxgooglemap-listing', $js_url.'cbxgooglemap-listing.js', ['jquery'], $ver, $t); | |
| 767 | 752 | |
| 768 | - $cbxgooglemap_listing_js_vars = apply_filters('cbxgooglemap_listing_js_vars', $global_translation); | |
| 769 | - wp_localize_script('cbxgooglemap-listing', 'cbxgooglemap_listing', $cbxgooglemap_listing_js_vars); | |
| 753 | + wp_register_script( 'cbxgooglemap-events', $js_url . 'cbxgooglemap-events.js', [], $ver, $in_footer ); | |
| 754 | + wp_register_script( 'awesome-notifications', $js_url_part_vendors . 'awesome-notifications/script.js', [], $ver, $in_footer ); | |
| 755 | + wp_register_script( 'select2', $js_url_part_vendors . 'select2/select2.min.js', [ 'jquery' ], $ver, $in_footer ); | |
| 756 | + //wp_register_script( 'flatpickr', $js_url_part_vendors . 'flatpickr/flatpickr.min.js', [ 'jquery' ], $ver, true ); | |
| 757 | + wp_register_script( 'pickr', $js_url_part_vendors . 'pickr/pickr.min.js', [], $ver, $in_footer ); | |
| 758 | + //wp_register_script( 'jquery-validate', $js_url_part_vendors . 'jquery-validation/jquery.validate.min.js', [ 'jquery' ], $ver, $in_footer ); | |
| 770 | 759 | |
| 771 | - wp_enqueue_script('jquery'); | |
| 772 | - wp_enqueue_script('cbxgooglemap-listing'); | |
| 773 | - } | |
| 760 | + //maps listing mode | |
| 761 | + if ( $hook == 'edit.php' && $post_type == 'cbxgooglemap' ) { | |
| 762 | + wp_register_script( 'cbxgooglemap-listing', $js_url . 'cbxgooglemap-listing.js', [ 'jquery' ], $ver, $t ); | |
| 774 | 763 | |
| 775 | - //add new or edit mode | |
| 776 | - if (($hook == 'post.php' || $hook == 'post-new.php') && $post_type == 'cbxgooglemap') { | |
| 764 | + $cbxgooglemap_listing_js_vars = apply_filters( 'cbxgooglemap_listing_js_vars', $global_translation ); | |
| 765 | + wp_localize_script( 'cbxgooglemap-listing', 'cbxgooglemap_listing', $cbxgooglemap_listing_js_vars ); | |
| 777 | 766 | |
| 778 | - wp_enqueue_script('cbxgooglemap-events'); | |
| 767 | + wp_enqueue_script( 'jquery' ); | |
| 768 | + wp_enqueue_script( 'cbxgooglemap-listing' ); | |
| 769 | + } | |
| 779 | 770 | |
| 771 | + //add new or edit mode | |
| 772 | + if ( ( $hook == 'post.php' || $hook == 'post-new.php' ) && $post_type == 'cbxgooglemap' ) { | |
| 780 | 773 | |
| 781 | - $edit_js_dep = ['jquery', 'select2']; | |
| 774 | + wp_enqueue_script( 'cbxgooglemap-events' ); | |
| 782 | 775 | |
| 783 | - if ($map_source == 1 && $api_key != '') { | |
| 784 | - wp_register_script('coregooglemapapi', '//maps.googleapis.com/maps/api/js?key='.$api_key.'&libraries=places&callback=Function.prototype', [], $ver, $in_footer_async); | |
| 785 | 776 | |
| 786 | - $edit_js_dep[] = 'awesome-notifications'; | |
| 787 | - $edit_js_dep[] = 'coregooglemapapi'; | |
| 788 | - $edit_js_dep[] = 'cbxgooglemap-events'; | |
| 777 | + $edit_js_dep = [ 'jquery', 'select2' ]; | |
| 789 | 778 | |
| 790 | - } elseif ($map_source == 0) { | |
| 791 | - wp_register_script('coregooglemapapi', $vendor_url.'leaflet/leaflet.js', [], $ver, $in_footer_async); | |
| 792 | - wp_register_script('leaflet-control-geocoder', $vendor_url.'leaflet-control-geocoder/Control.Geocoder.js', [], $ver, $in_footer_async); | |
| 779 | + //if ($map_source == 1 && $api_key != '') { | |
| 780 | + if ( $map_source == 1 ) { | |
| 781 | + wp_register_script( 'coregooglemapapi', '//maps.googleapis.com/maps/api/js?key=' . $api_key . '&libraries=places&callback=Function.prototype', [], $ver, $in_footer_async ); | |
| 793 | 782 | |
| 794 | - $edit_js_dep[] = 'awesome-notifications'; | |
| 795 | - $edit_js_dep[] = 'coregooglemapapi'; | |
| 796 | - $edit_js_dep[] = 'leaflet-control-geocoder'; | |
| 797 | - $edit_js_dep[] = 'cbxgooglemap-events'; | |
| 798 | - } | |
| 783 | + $edit_js_dep[] = 'awesome-notifications'; | |
| 784 | + $edit_js_dep[] = 'coregooglemapapi'; | |
| 785 | + $edit_js_dep[] = 'cbxgooglemap-events'; | |
| 799 | 786 | |
| 800 | - wp_enqueue_media(); | |
| 801 | - $main_marker = []; | |
| 787 | + } elseif ( $map_source == 0 ) { | |
| 788 | + wp_register_script( 'coregooglemapapi', $vendor_url . 'leaflet/leaflet.js', [], $ver, $in_footer_async ); | |
| 789 | + wp_register_script( 'leaflet-control-geocoder', $vendor_url . 'leaflet-control-geocoder/Control.Geocoder.js', [], $ver, $in_footer_async ); | |
| 802 | 790 | |
| 803 | - wp_register_script('cbxgooglemap-edit', $js_url.'cbxgooglemap-edit.js', $edit_js_dep, $ver, $in_footer); | |
| 791 | + $edit_js_dep[] = 'awesome-notifications'; | |
| 792 | + $edit_js_dep[] = 'coregooglemapapi'; | |
| 793 | + $edit_js_dep[] = 'leaflet-control-geocoder'; | |
| 794 | + $edit_js_dep[] = 'cbxgooglemap-events'; | |
| 795 | + } | |
| 804 | 796 | |
| 805 | - $edit_js_vars = [ | |
| 806 | - 'search_address' => esc_html__('Search Address', 'cbxgooglemap'), | |
| 807 | - 'icon_url_default' => $default_mapicon, | |
| 808 | - 'api_key' => $api_key, | |
| 809 | - 'map_source' => $map_source, | |
| 810 | - 'map_title_placeholder' => esc_html__('Map Title Here', 'cbxgooglemap'), | |
| 811 | - 'no_address_found' => esc_html__('No details available for current input', 'cbxgooglemap'), | |
| 812 | - ]; | |
| 797 | + wp_enqueue_media(); | |
| 798 | + $main_marker = []; | |
| 813 | 799 | |
| 814 | - $edit_js_vars = array_merge($edit_js_vars, $global_translation); | |
| 800 | + wp_register_script( 'cbxgooglemap-edit', $js_url . 'cbxgooglemap-edit.js', $edit_js_dep, $ver, $in_footer ); | |
| 815 | 801 | |
| 816 | - $edit_js_vars = apply_filters('cbxgooglemap_edit_js_vars', $edit_js_vars, $post_id); | |
| 802 | + $edit_js_vars = [ | |
| 803 | + 'search_address' => esc_html__( 'Search Address', 'cbxgooglemap' ), | |
| 804 | + 'icon_url_default' => $default_mapicon, | |
| 805 | + 'api_key' => $api_key, | |
| 806 | + 'no_api_key' => ( $api_key === '' ) ? esc_html__( 'No google map api key found, please check CBX Map plugin setting.', 'cbxgooglemap' ) : '', | |
| 807 | + 'map_source' => $map_source, | |
| 808 | + 'map_title_placeholder' => esc_html__( 'Map Title Here', 'cbxgooglemap' ), | |
| 809 | + 'no_address_found' => esc_html__( 'No details available for current input', 'cbxgooglemap' ), | |
| 810 | + ]; | |
| 817 | 811 | |
| 818 | - wp_localize_script('cbxgooglemap-edit', 'cbxgooglemap_edit', $edit_js_vars); | |
| 812 | + $edit_js_vars = array_merge( $edit_js_vars, $global_translation ); | |
| 819 | 813 | |
| 820 | - //enqueue dependency js cripts | |
| 821 | - foreach ($edit_js_dep as $dep) { | |
| 822 | - wp_enqueue_script($dep); | |
| 823 | - } | |
| 814 | + $edit_js_vars = apply_filters( 'cbxgooglemap_edit_js_vars', $edit_js_vars, $post_id ); | |
| 824 | 815 | |
| 825 | - //enqueue main edit scripts | |
| 826 | - wp_enqueue_script('cbxgooglemap-edit'); | |
| 827 | - } | |
| 816 | + wp_localize_script( 'cbxgooglemap-edit', 'cbxgooglemap_edit', $edit_js_vars ); | |
| 828 | 817 | |
| 829 | - if ($current_page == 'cbxgooglemap_settings') { | |
| 830 | - $setting_js_deps = [ | |
| 831 | - 'jquery', | |
| 832 | - 'jquery-ui-sortable', | |
| 833 | - 'select2', | |
| 834 | - 'pickr', | |
| 835 | - 'awesome-notifications' | |
| 836 | - ]; | |
| 818 | + //enqueue dependency js cripts | |
| 819 | + foreach ( $edit_js_dep as $dep ) { | |
| 820 | + wp_enqueue_script( $dep ); | |
| 821 | + } | |
| 837 | 822 | |
| 838 | - $setting_js_deps = apply_filters('cbxgooglemap_setting_js_deps', $setting_js_deps); | |
| 823 | + //enqueue main edit scripts | |
| 824 | + wp_enqueue_script( 'cbxgooglemap-edit' ); | |
| 825 | + } | |
| 839 | 826 | |
| 840 | - $blog_id = is_multisite() ? get_current_blog_id() : null; | |
| 827 | + if ( $current_page == 'cbxgooglemap_settings' ) { | |
| 828 | + $setting_js_deps = [ | |
| 829 | + 'jquery', | |
| 830 | + 'jquery-ui-sortable', | |
| 831 | + 'select2', | |
| 832 | + 'pickr', | |
| 833 | + 'awesome-notifications' | |
| 834 | + ]; | |
| 841 | 835 | |
| 842 | - // Localize the script with new data | |
| 843 | - $setting_js_vars = [ | |
| 844 | - 'global_setting_link_html' => '<a href="'.esc_url(admin_url('edit.php?post_type=cbxgooglemap&page=cbxgooglemap_settings')).'" class="button outline primary pull-right">'.esc_html__('Global Settings', 'cbxgooglemap').'</a>', | |
| 845 | - 'lang' => get_user_locale(), | |
| 846 | - 'clearPermalinks' => esc_url_raw(get_rest_url($blog_id, 'cbxgooglemap/v1/admin/clear-permalinks')), | |
| 847 | - 'rest_end_points' => [ | |
| 848 | - 'migrate_wp_wpsimplegooglemap' => esc_url_raw(get_rest_url('', 'cbxgooglemap/v1/migrate-wp-wpsimplegooglemap-data')), | |
| 849 | - ], | |
| 850 | - ]; | |
| 836 | + $setting_js_deps = apply_filters( 'cbxgooglemap_setting_js_deps', $setting_js_deps ); | |
| 851 | 837 | |
| 852 | - $import_modal_html = '<div id="cbxgooglemap_settings_import_modal_wrap" class="cbx-chota">'; | |
| 853 | - $import_modal_html .= '<h2>'.esc_html__('Import CBX Google Map Setting: Json file', 'cbxgooglemap').'</h2>'; | |
| 854 | - $import_modal_html .= '<form method="post" id="cbxgooglemap_settings_import_form">'; | |
| 855 | - $import_modal_html .= '<input type="file" name="file" id="cbxgooglemap_settings_import_file" accept="application/json" />'; | |
| 856 | - $import_modal_html .= '</form>'; | |
| 857 | - $import_modal_html .= '</div>'; | |
| 838 | + $blog_id = is_multisite() ? get_current_blog_id() : null; | |
| 858 | 839 | |
| 859 | - $setting_js_vars['import_modal'] = $import_modal_html; | |
| 860 | - $setting_js_vars['import_modal_progress'] = '<p>'.esc_html__('Please wait, Importing...', 'cbxgooglemap').'</p>'; | |
| 840 | + // Localize the script with new data | |
| 841 | + $setting_js_vars = [ | |
| 842 | + 'global_setting_link_html' => '<a href="' . esc_url( admin_url( 'edit.php?post_type=cbxgooglemap&page=cbxgooglemap_settings' ) ) . '" class="button outline primary pull-right">' . esc_html__( 'Global Settings', | |
| 843 | + 'cbxgooglemap' ) . '</a>', | |
| 844 | + 'lang' => get_user_locale(), | |
| 845 | + 'clearPermalinks' => esc_url_raw( get_rest_url( $blog_id, 'cbxgooglemap/v1/admin/clear-permalinks' ) ), | |
| 846 | + 'rest_end_points' => [ | |
| 847 | + 'migrate_wp_wpsimplegooglemap' => esc_url_raw( get_rest_url( '', 'cbxgooglemap/v1/migrate-wp-wpsimplegooglemap-data' ) ), | |
| 848 | + ], | |
| 849 | + ]; | |
| 861 | 850 | |
| 862 | - $cbxgooglemap_setting_js_vars = apply_filters('cbxgooglemap_setting_js_vars', array_merge($setting_js_vars, $global_translation)); | |
| 851 | + $import_modal_html = '<div id="cbxgooglemap_settings_import_modal_wrap" class="cbx-chota">'; | |
| 852 | + $import_modal_html .= '<h2>' . esc_html__( 'Import CBX Google Map Setting: Json file', 'cbxgooglemap' ) . '</h2>'; | |
| 853 | + $import_modal_html .= '<form method="post" id="cbxgooglemap_settings_import_form">'; | |
| 854 | + $import_modal_html .= '<input type="file" name="file" id="cbxgooglemap_settings_import_file" accept="application/json" />'; | |
| 855 | + $import_modal_html .= '</form>'; | |
| 856 | + $import_modal_html .= '</div>'; | |
| 863 | 857 | |
| 864 | - wp_register_script('cbxgooglemap-setting', $js_url.'cbxgooglemap-setting.js', $setting_js_deps, $ver, $in_footer); | |
| 858 | + $setting_js_vars['import_modal'] = $import_modal_html; | |
| 859 | + $setting_js_vars['import_modal_progress'] = '<p>' . esc_html__( 'Please wait, Importing...', 'cbxgooglemap' ) . '</p>'; | |
| 865 | 860 | |
| 866 | - wp_localize_script('cbxgooglemap-setting', 'cbxgooglemap_setting_js_var', $cbxgooglemap_setting_js_vars); | |
| 861 | + $cbxgooglemap_setting_js_vars = apply_filters( 'cbxgooglemap_setting_js_vars', array_merge( $setting_js_vars, $global_translation ) ); | |
| 867 | 862 | |
| 868 | - //core | |
| 869 | - wp_enqueue_script('jquery'); | |
| 870 | - wp_enqueue_media(); | |
| 863 | + wp_register_script( 'cbxgooglemap-setting', $js_url . 'cbxgooglemap-setting.js', $setting_js_deps, $ver, $in_footer ); | |
| 871 | 864 | |
| 872 | - //vendors | |
| 873 | - wp_enqueue_script('jquery-ui-sortable'); | |
| 874 | - wp_enqueue_script('select2'); | |
| 875 | - wp_enqueue_script('pickr'); | |
| 876 | - wp_enqueue_script('awesome-notifications'); | |
| 865 | + wp_localize_script( 'cbxgooglemap-setting', 'cbxgooglemap_setting_js_var', $cbxgooglemap_setting_js_vars ); | |
| 877 | 866 | |
| 878 | - //custom | |
| 879 | - wp_enqueue_script('cbxgooglemap-setting'); | |
| 867 | + //core | |
| 868 | + wp_enqueue_script( 'jquery' ); | |
| 869 | + wp_enqueue_media(); | |
| 880 | 870 | |
| 881 | - //for demo js (we need this but we will sort out later) | |
| 882 | - if (($map_source == 1 && ! empty($api_key)) || $map_source == 0) { | |
| 883 | - if ($map_source == 1) { | |
| 884 | - //phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter | |
| 885 | - wp_register_script('coregooglemapapi', '//maps.googleapis.com/maps/api/js?key='.esc_attr($api_key).'&libraries=places&callback=Function.prototype', [], $ver, $in_footer_async); | |
| 886 | - wp_register_script('cbxgooglemap-public', $js_url.'cbxgooglemap-public.js', [ | |
| 887 | - 'jquery', | |
| 888 | - 'cbxgooglemap-events', | |
| 889 | - 'coregooglemapapi' | |
| 890 | - ], $ver, $in_footer); | |
| 871 | + //vendors | |
| 872 | + wp_enqueue_script( 'jquery-ui-sortable' ); | |
| 873 | + wp_enqueue_script( 'select2' ); | |
| 874 | + wp_enqueue_script( 'pickr' ); | |
| 875 | + wp_enqueue_script( 'awesome-notifications' ); | |
| 891 | 876 | |
| 892 | - wp_enqueue_script('coregooglemapapi'); | |
| 893 | - } else { | |
| 894 | - wp_register_script('coregooglemapapi', $vendor_url.'leaflet/leaflet.js', [], $ver, $in_footer_async); | |
| 895 | - wp_register_script('cbxgooglemap-public', $js_url.'cbxgooglemap-public.js', [ | |
| 896 | - 'jquery', | |
| 897 | - 'cbxgooglemap-events', | |
| 898 | - 'coregooglemapapi', | |
| 899 | - //'leaflet-control-geocoder' | |
| 900 | - ], $ver, $in_footer); | |
| 877 | + //custom | |
| 878 | + wp_enqueue_script( 'cbxgooglemap-setting' ); | |
| 901 | 879 | |
| 902 | - wp_enqueue_script('cbxgooglemap-events'); | |
| 903 | - wp_enqueue_script('coregooglemapapi'); | |
| 904 | - //wp_enqueue_script( 'leaflet-control-geocoder' ); | |
| 905 | - } | |
| 880 | + //for demo js (we need this but we will sort out later) | |
| 881 | + if ( ( $map_source == 1 && ! empty( $api_key ) ) || $map_source == 0 ) { | |
| 882 | + if ( $map_source == 1 ) { | |
| 883 | + //phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter | |
| 884 | + wp_register_script( 'coregooglemapapi', '//maps.googleapis.com/maps/api/js?key=' . esc_attr( $api_key ) . '&libraries=places&callback=Function.prototype', [], $ver, | |
| 885 | + $in_footer_async ); | |
| 886 | + wp_register_script( 'cbxgooglemap-public', $js_url . 'cbxgooglemap-public.js', [ | |
| 887 | + 'jquery', | |
| 888 | + 'cbxgooglemap-events', | |
| 889 | + 'coregooglemapapi' | |
| 890 | + ], $ver, $in_footer ); | |
| 906 | 891 | |
| 907 | - wp_enqueue_script('cbxgooglemap-public'); | |
| 908 | - }//end for demo js | |
| 892 | + wp_enqueue_script( 'coregooglemapapi' ); | |
| 893 | + } else { | |
| 894 | + wp_register_script( 'coregooglemapapi', $vendor_url . 'leaflet/leaflet.js', [], $ver, $in_footer_async ); | |
| 895 | + wp_register_script( 'cbxgooglemap-public', $js_url . 'cbxgooglemap-public.js', [ | |
| 896 | + 'jquery', | |
| 897 | + 'cbxgooglemap-events', | |
| 898 | + 'coregooglemapapi', | |
| 899 | + //'leaflet-control-geocoder' | |
| 900 | + ], $ver, $in_footer ); | |
| 909 | 901 | |
| 910 | - }//end js for setting page | |
| 902 | + wp_enqueue_script( 'cbxgooglemap-events' ); | |
| 903 | + wp_enqueue_script( 'coregooglemapapi' ); | |
| 904 | + //wp_enqueue_script( 'leaflet-control-geocoder' ); | |
| 905 | + } | |
| 911 | 906 | |
| 912 | - //enqueue js for tax page | |
| 913 | - if (($hook == 'edit-tags.php' || $hook == 'term.php') && $post_type == 'cbxgooglemap' && $current_page == '') { | |
| 914 | - //tax js dependencies | |
| 907 | + wp_enqueue_script( 'cbxgooglemap-public' ); | |
| 908 | + }//end for demo js | |
| 915 | 909 | |
| 916 | - $tax_js_deps = [ | |
| 917 | - //core | |
| 918 | - 'jquery', | |
| 919 | - //vendors | |
| 920 | - //'jquery-validate' | |
| 921 | - ]; | |
| 910 | + }//end js for setting page | |
| 922 | 911 | |
| 923 | - $tax_js_deps = apply_filters('cbxgooglemap_tax_js_deps', $tax_js_deps); | |
| 912 | + //enqueue js for tax page | |
| 913 | + if ( ( $hook == 'edit-tags.php' || $hook == 'term.php' ) && $post_type == 'cbxgooglemap' && $current_page == '' ) { | |
| 914 | + //tax js dependencies | |
| 924 | 915 | |
| 925 | - $new_map_link_html = '<a href="'.esc_url(admin_url('edit.php?post_type=cbxgooglemap')).'" class="button secondary icon icon-right icon-inline mr-5"><i class="cbx-icon">'.$plus_svg.'</i>'.esc_html__('New Map', | |
| 926 | - 'cbxgooglemap').'</a>'; | |
| 916 | + $tax_js_deps = [ | |
| 917 | + //core | |
| 918 | + 'jquery', | |
| 919 | + //vendors | |
| 920 | + //'jquery-validate' | |
| 921 | + ]; | |
| 927 | 922 | |
| 928 | - $global_setting_link_html = '<a href="'.esc_url(admin_url('edit.php?post_type=cbxgooglemap&page=cbxgooglemap_settings')).'" class="button outline primary">'.esc_html__('Global Settings', 'cbxgooglemap').'</a>'; | |
| 923 | + $tax_js_deps = apply_filters( 'cbxgooglemap_tax_js_deps', $tax_js_deps ); | |
| 929 | 924 | |
| 930 | - $tax_js_vars = | |
| 931 | - [ | |
| 932 | - 'tax_title_prefix' => esc_html__('Map:', 'cbxgooglemap'), | |
| 933 | - 'tags_title' => esc_html__('Map: Tags', 'cbxgooglemap'), | |
| 934 | - 'category_title' => esc_html__('Map: Category', 'cbxgooglemap'), | |
| 935 | - 'tax_new_setting' => '<div class="wp-heading-wrap-right pull-right">'.$new_map_link_html.$global_setting_link_html.'</div>' | |
| 936 | - ]; | |
| 925 | + $new_map_link_html = '<a href="' . esc_url( admin_url( 'edit.php?post_type=cbxgooglemap' ) ) . '" class="button secondary icon icon-right icon-inline mr-5"><i class="cbx-icon">' . $plus_svg . '</i>' . esc_html__( 'New Map', | |
| 926 | + 'cbxgooglemap' ) . '</a>'; | |
| 937 | 927 | |
| 938 | - $tax_js_vars = apply_filters('cbxgooglemap_tax_js_vars', array_merge($tax_js_vars, $global_translation)); | |
| 928 | + $global_setting_link_html = '<a href="' . esc_url( admin_url( 'edit.php?post_type=cbxgooglemap&page=cbxgooglemap_settings' ) ) . '" class="button outline primary">' . esc_html__( 'Global Settings', | |
| 929 | + 'cbxgooglemap' ) . '</a>'; | |
| 939 | 930 | |
| 940 | - wp_register_script('cbxgooglemap-tax', $js_url_part.'cbxgooglemap-tax.js', $tax_js_deps, $ver, true); | |
| 941 | - wp_localize_script('cbxgooglemap-tax', 'cbxgooglemap_tax', $tax_js_vars); | |
| 931 | + $tax_js_vars = | |
| 932 | + [ | |
| 933 | + 'tax_title_prefix' => esc_html__( 'Map:', 'cbxgooglemap' ), | |
| 934 | + 'tags_title' => esc_html__( 'Map: Tags', 'cbxgooglemap' ), | |
| 935 | + 'category_title' => esc_html__( 'Map: Category', 'cbxgooglemap' ), | |
| 936 | + 'tax_new_setting' => '<div class="wp-heading-wrap-right pull-right">' . $new_map_link_html . $global_setting_link_html . '</div>' | |
| 937 | + ]; | |
| 942 | 938 | |
| 939 | + $tax_js_vars = apply_filters( 'cbxgooglemap_tax_js_vars', array_merge( $tax_js_vars, $global_translation ) ); | |
| 943 | 940 | |
| 944 | - //core | |
| 945 | - wp_enqueue_script('jquery'); | |
| 941 | + wp_register_script( 'cbxgooglemap-tax', $js_url_part . 'cbxgooglemap-tax.js', $tax_js_deps, $ver, true ); | |
| 942 | + wp_localize_script( 'cbxgooglemap-tax', 'cbxgooglemap_tax', $tax_js_vars ); | |
| 946 | 943 | |
| 947 | - //vendors | |
| 948 | - //wp_enqueue_script( 'jquery-validate' ); | |
| 949 | 944 | |
| 950 | - //custom | |
| 951 | - wp_enqueue_script('cbxgooglemap-tax'); | |
| 952 | - }//end enqueue js for tax page | |
| 953 | - }//end enqueue_scripts | |
| 945 | + //core | |
| 946 | + wp_enqueue_script( 'jquery' ); | |
| 954 | 947 | |
| 955 | - /** | |
| 956 | - * Init all gutenberg blocks | |
| 957 | - */ | |
| 958 | - public function gutenberg_blocks(){ | |
| 959 | - if ( ! function_exists('register_block_type')) { | |
| 960 | - return; | |
| 961 | - } | |
| 948 | + //vendors | |
| 949 | + //wp_enqueue_script( 'jquery-validate' ); | |
| 962 | 950 | |
| 963 | - $settings = $this->settings; | |
| 964 | - $in_footer = [ | |
| 965 | - 'in_footer' => true, | |
| 966 | - ]; | |
| 951 | + //custom | |
| 952 | + wp_enqueue_script( 'cbxgooglemap-tax' ); | |
| 953 | + }//end enqueue js for tax page | |
| 954 | + }//end enqueue_scripts | |
| 967 | 955 | |
| 956 | + /** | |
| 957 | + * Init all gutenberg blocks | |
| 958 | + */ | |
| 959 | + public function gutenberg_blocks() { | |
| 960 | + if ( ! function_exists( 'register_block_type' ) ) { | |
| 961 | + return; | |
| 962 | + } | |
| 968 | 963 | |
| 969 | - //$general_settings = get_option( 'cbxgooglemap_general', [] ); | |
| 964 | + $settings = $this->settings; | |
| 965 | + $in_footer = [ | |
| 966 | + 'in_footer' => true, | |
| 967 | + ]; | |
| 970 | 968 | |
| 971 | - //default field values | |
| 972 | - $zoom_default = $settings->get_field('zoom', 'cbxgooglemap_general', '8'); | |
| 973 | - if ($zoom_default == 0) { | |
| 974 | - $zoom_default = 8; | |
| 975 | - } | |
| 976 | 969 | |
| 977 | - $width_default = $settings->get_field('width', 'cbxgooglemap_general', '100%'); | |
| 978 | - if ($width_default == '' || $width_default == 0) { | |
| 979 | - $width_default = '100%'; | |
| 980 | - } | |
| 970 | + //$general_settings = get_option( 'cbxgooglemap_general', [] ); | |
| 981 | 971 | |
| 982 | - $height_default = absint($settings->get_field('height', 'cbxgooglemap_general', '300')); | |
| 983 | - if ($height_default == 0) { | |
| 984 | - $height_default = 300; | |
| 985 | - } | |
| 972 | + //default field values | |
| 973 | + $zoom_default = $settings->get_field( 'zoom', 'cbxgooglemap_general', '8' ); | |
| 974 | + if ( $zoom_default == 0 ) { | |
| 975 | + $zoom_default = 8; | |
| 976 | + } | |
| 986 | 977 | |
| 978 | + $width_default = $settings->get_field( 'width', 'cbxgooglemap_general', '100%' ); | |
| 979 | + if ( $width_default == '' || $width_default == 0 ) { | |
| 980 | + $width_default = '100%'; | |
| 981 | + } | |
| 987 | 982 | |
| 988 | - $scrollwheel_default = absint($settings->get_field('scrollwheel', 'cbxgooglemap_general', 1)); | |
| 989 | - $showinfo_default = absint($settings->get_field('showinfo', 'cbxgooglemap_general', 1)); | |
| 990 | - $infow_open_default = absint($settings->get_field('infow_open', 'cbxgooglemap_general', 1)); | |
| 991 | - $maptype_default = esc_attr($settings->get_field('maptype', 'cbxgooglemap_general', 'roadmap')); | |
| 983 | + $height_default = absint( $settings->get_field( 'height', 'cbxgooglemap_general', '300' ) ); | |
| 984 | + if ( $height_default == 0 ) { | |
| 985 | + $height_default = 300; | |
| 986 | + } | |
| 992 | 987 | |
| 993 | - $query = get_posts([ | |
| 994 | - 'post_type' => 'cbxgooglemap', | |
| 995 | - 'orderby' => 'date', | |
| 996 | - 'posts_per_page' => -1, | |
| 997 | - 'post_status' => 'publish' | |
| 998 | - ]); | |
| 999 | 988 | |
| 1000 | - $googleMap_posts = []; | |
| 989 | + $scrollwheel_default = absint( $settings->get_field( 'scrollwheel', 'cbxgooglemap_general', 1 ) ); | |
| 990 | + $showinfo_default = absint( $settings->get_field( 'showinfo', 'cbxgooglemap_general', 1 ) ); | |
| 991 | + $infow_open_default = absint( $settings->get_field( 'infow_open', 'cbxgooglemap_general', 1 ) ); | |
| 992 | + $maptype_default = esc_attr( $settings->get_field( 'maptype', 'cbxgooglemap_general', 'roadmap' ) ); | |
| 1001 | 993 | |
| 1002 | - $googleMap_posts[] = [ | |
| 1003 | - 'label' => esc_html__('Select Map', 'cbxgooglemap'), | |
| 1004 | - 'value' => '0' | |
| 1005 | - ]; | |
| 994 | + $query = get_posts( [ | |
| 995 | + 'post_type' => 'cbxgooglemap', | |
| 996 | + 'orderby' => 'date', | |
| 997 | + 'posts_per_page' => - 1, | |
| 998 | + 'post_status' => 'publish' | |
| 999 | + ] ); | |
| 1006 | 1000 | |
| 1007 | - foreach ($query as $key => $data) { | |
| 1008 | - $googleMap_posts[] = [ | |
| 1009 | - 'label' => esc_html($data->post_title), | |
| 1010 | - 'value' => absint($data->ID) | |
| 1011 | - ]; | |
| 1012 | - } | |
| 1001 | + $googleMap_posts = []; | |
| 1013 | 1002 | |
| 1003 | + $googleMap_posts[] = [ | |
| 1004 | + 'label' => esc_html__( 'Select Map', 'cbxgooglemap' ), | |
| 1005 | + 'value' => '0' | |
| 1006 | + ]; | |
| 1014 | 1007 | |
| 1015 | - wp_register_script('cbxgooglemap-block', plugin_dir_url(__FILE__).'../assets/js/blocks/cbxgooglemap-block.js', [ | |
| 1016 | - 'wp-blocks', | |
| 1017 | - 'wp-element', | |
| 1018 | - 'wp-components', | |
| 1019 | - 'wp-editor', | |
| 1020 | - ], filemtime(plugin_dir_path(__FILE__).'../assets/js/blocks/cbxgooglemap-block.js'), $in_footer); | |
| 1008 | + foreach ( $query as $key => $data ) { | |
| 1009 | + $googleMap_posts[] = [ | |
| 1010 | + 'label' => esc_html( $data->post_title ), | |
| 1011 | + 'value' => absint( $data->ID ) | |
| 1012 | + ]; | |
| 1013 | + } | |
| 1021 | 1014 | |
| 1022 | - wp_register_style('cbxgooglemap-block', plugin_dir_url(__FILE__).'../assets/css/cbxgooglemap-block.css', [], filemtime(plugin_dir_path(__FILE__).'../assets/css/cbxgooglemap-block.css')); | |
| 1023 | 1015 | |
| 1024 | - $js_vars = apply_filters('cbxgooglemap_block_js_vars', | |
| 1025 | - [ | |
| 1026 | - 'block_title' => esc_html__('CBX Map: Location Map', 'cbxgooglemap'), | |
| 1027 | - 'block_category' => 'codeboxr', | |
| 1028 | - 'block_icon' => 'universal-access-alt', | |
| 1029 | - 'general_settings' => [ | |
| 1030 | - 'title' => esc_html__('CBX Map Settings', 'cbxgooglemap'), | |
| 1031 | - 'id' => esc_html__('Select Map', 'cbxgooglemap'), | |
| 1032 | - 'id_default' => '', | |
| 1033 | - 'id_options' => $googleMap_posts, | |
| 1034 | - 'id_note' => esc_html__('Choose saved map or create from custom attributes below', 'cbxgooglemap'), | |
| 1035 | - 'custom_attribute_note' => esc_html__('Custom Map Attributes', 'cbxgooglemap'), | |
| 1036 | - 'maptype' => esc_html__('Map Type(Google Map Only)', 'cbxgooglemap'), | |
| 1037 | - 'maptype_options' => CBXGooglemapHelper::maptype_block_options(), | |
| 1038 | - 'lat' => esc_html__('Latitude', 'cbxgooglemap'), | |
| 1039 | - 'lng' => esc_html__('Longitude', 'cbxgooglemap'), | |
| 1040 | - 'width' => esc_html__('Width(Numeric, % allowed)', 'cbxgooglemap'), | |
| 1041 | - 'height' => esc_html__('Height(only Numeric)', 'cbxgooglemap'), | |
| 1042 | - 'zoom' => esc_html__('zoom', 'cbxgooglemap'), | |
| 1043 | - 'scrollwheel' => esc_html__('Mouse Scroll Wheel', 'cbxgooglemap'), | |
| 1044 | - 'showinfo' => esc_html__('Show Popup', 'cbxgooglemap'), | |
| 1045 | - 'infow_open' => esc_html__('Popup Auto Display ', 'cbxgooglemap'), | |
| 1046 | - 'heading' => esc_html__('Popup Heading', 'cbxgooglemap'), | |
| 1047 | - 'address' => esc_html__('Location Address', 'cbxgooglemap'), | |
| 1048 | - 'website' => esc_html__('Website url', 'cbxgooglemap'), | |
| 1049 | - 'mapicon' => esc_html__('Map Icon', 'cbxgooglemap'), | |
| 1050 | - 'mapicon_select' => esc_html__('Select image', 'cbxgooglemap'), | |
| 1051 | - ], | |
| 1052 | - ]); | |
| 1016 | + wp_register_script( 'cbxgooglemap-block', plugin_dir_url( __FILE__ ) . '../assets/js/blocks/cbxgooglemap-block.js', [ | |
| 1017 | + 'wp-blocks', | |
| 1018 | + 'wp-element', | |
| 1019 | + 'wp-components', | |
| 1020 | + 'wp-editor', | |
| 1021 | + ], filemtime( plugin_dir_path( __FILE__ ) . '../assets/js/blocks/cbxgooglemap-block.js' ), $in_footer ); | |
| 1053 | 1022 | |
| 1054 | - wp_localize_script('cbxgooglemap-block', 'cbxgooglemap_block', $js_vars); | |
| 1023 | + wp_register_style( 'cbxgooglemap-block', plugin_dir_url( __FILE__ ) . '../assets/css/cbxgooglemap-block.css', [], | |
| 1024 | + filemtime( plugin_dir_path( __FILE__ ) . '../assets/css/cbxgooglemap-block.css' ) ); | |
| 1055 | 1025 | |
| 1056 | - register_block_type('codeboxr/cbxgooglemap', [ | |
| 1057 | - 'editor_script' => 'cbxgooglemap-block', | |
| 1058 | - 'editor_style' => 'cbxgooglemap-block', | |
| 1059 | - 'attributes' => apply_filters('cbxgooglemap_block_attributes', [ | |
| 1060 | - //general | |
| 1061 | - 'id' => [ | |
| 1062 | - 'type' => 'integer', | |
| 1063 | - 'default' => '0', | |
| 1064 | - ], | |
| 1065 | - 'maptype' => [ | |
| 1066 | - 'type' => 'string', | |
| 1067 | - 'default' => $maptype_default | |
| 1068 | - ], | |
| 1069 | - 'lat' => [ | |
| 1070 | - 'type' => 'string', | |
| 1071 | - 'default' => '' | |
| 1072 | - ], | |
| 1073 | - 'lng' => [ | |
| 1074 | - 'type' => 'string', | |
| 1075 | - 'default' => '' | |
| 1076 | - ], | |
| 1077 | - 'width' => [ | |
| 1078 | - 'type' => 'string', | |
| 1079 | - 'default' => $width_default, | |
| 1080 | - ], | |
| 1026 | + $js_vars = apply_filters( 'cbxgooglemap_block_js_vars', | |
| 1027 | + [ | |
| 1028 | + 'block_title' => esc_html__( 'CBX Map: Location Map', 'cbxgooglemap' ), | |
| 1029 | + 'block_category' => 'codeboxr', | |
| 1030 | + 'block_icon' => 'universal-access-alt', | |
| 1031 | + 'general_settings' => [ | |
| 1032 | + 'title' => esc_html__( 'CBX Map Settings', 'cbxgooglemap' ), | |
| 1033 | + 'id' => esc_html__( 'Select Map', 'cbxgooglemap' ), | |
| 1034 | + 'id_default' => '', | |
| 1035 | + 'id_options' => $googleMap_posts, | |
| 1036 | + 'id_note' => esc_html__( 'Choose saved map or create from custom attributes below', 'cbxgooglemap' ), | |
| 1037 | + 'custom_attribute_note' => esc_html__( 'Custom Map Attributes', 'cbxgooglemap' ), | |
| 1038 | + 'maptype' => esc_html__( 'Map Type(Google Map Only)', 'cbxgooglemap' ), | |
| 1039 | + 'maptype_options' => CBXGooglemapHelper::maptype_block_options(), | |
| 1040 | + 'lat' => esc_html__( 'Latitude', 'cbxgooglemap' ), | |
| 1041 | + 'lng' => esc_html__( 'Longitude', 'cbxgooglemap' ), | |
| 1042 | + 'width' => esc_html__( 'Width(Numeric, % allowed)', 'cbxgooglemap' ), | |
| 1043 | + 'height' => esc_html__( 'Height(only Numeric)', 'cbxgooglemap' ), | |
| 1044 | + 'zoom' => esc_html__( 'zoom', 'cbxgooglemap' ), | |
| 1045 | + 'scrollwheel' => esc_html__( 'Mouse Scroll Wheel', 'cbxgooglemap' ), | |
| 1046 | + 'showinfo' => esc_html__( 'Show Popup', 'cbxgooglemap' ), | |
| 1047 | + 'infow_open' => esc_html__( 'Popup Auto Display ', 'cbxgooglemap' ), | |
| 1048 | + 'heading' => esc_html__( 'Popup Heading', 'cbxgooglemap' ), | |
| 1049 | + 'address' => esc_html__( 'Location Address', 'cbxgooglemap' ), | |
| 1050 | + 'website' => esc_html__( 'Website url', 'cbxgooglemap' ), | |
| 1051 | + 'mapicon' => esc_html__( 'Map Icon', 'cbxgooglemap' ), | |
| 1052 | + 'mapicon_select' => esc_html__( 'Select image', 'cbxgooglemap' ), | |
| 1053 | + ], | |
| 1054 | + ] ); | |
| 1081 | 1055 | |
| 1082 | - 'height' => [ | |
| 1083 | - 'type' => 'integer', | |
| 1084 | - 'default' => $height_default | |
| 1085 | - ], | |
| 1086 | - 'zoom' => [ | |
| 1087 | - 'type' => 'string', | |
| 1088 | - 'default' => $zoom_default | |
| 1089 | - ], | |
| 1090 | - 'scrollwheel' => [ | |
| 1091 | - 'type' => 'boolean', | |
| 1092 | - 'default' => ($scrollwheel_default) ? true : false | |
| 1093 | - ], | |
| 1094 | - 'showinfo' => [ | |
| 1095 | - 'type' => 'boolean', | |
| 1096 | - 'default' => ($showinfo_default) ? true : false | |
| 1097 | - ], | |
| 1098 | - 'infow_open' => [ | |
| 1099 | - 'type' => 'boolean', | |
| 1100 | - 'default' => ($infow_open_default) ? true : false | |
| 1101 | - ], | |
| 1102 | - 'heading' => [ | |
| 1103 | - 'type' => 'string', | |
| 1104 | - 'default' => '' | |
| 1105 | - ], | |
| 1106 | - 'address' => [ | |
| 1107 | - 'type' => 'string', | |
| 1108 | - 'default' => '' | |
| 1109 | - ], | |
| 1110 | - 'website' => [ | |
| 1111 | - 'type' => 'string', | |
| 1112 | - 'default' => '' | |
| 1113 | - ], | |
| 1114 | - 'mapicon' => [ | |
| 1115 | - 'type' => 'string', | |
| 1116 | - 'default' => '', | |
| 1117 | - ] | |
| 1118 | - ]), | |
| 1119 | - 'render_callback' => [$this, 'render_block'] | |
| 1120 | - ]); | |
| 1056 | + wp_localize_script( 'cbxgooglemap-block', 'cbxgooglemap_block', $js_vars ); | |
| 1121 | 1057 | |
| 1122 | - }//end gutenberg_blocks | |
| 1058 | + register_block_type( 'codeboxr/cbxgooglemap', [ | |
| 1059 | + 'editor_script' => 'cbxgooglemap-block', | |
| 1060 | + 'editor_style' => 'cbxgooglemap-block', | |
| 1061 | + 'attributes' => apply_filters( 'cbxgooglemap_block_attributes', [ | |
| 1062 | + //general | |
| 1063 | + 'id' => [ | |
| 1064 | + 'type' => 'integer', | |
| 1065 | + 'default' => '0', | |
| 1066 | + ], | |
| 1067 | + 'maptype' => [ | |
| 1068 | + 'type' => 'string', | |
| 1069 | + 'default' => $maptype_default | |
| 1070 | + ], | |
| 1071 | + 'lat' => [ | |
| 1072 | + 'type' => 'string', | |
| 1073 | + 'default' => '' | |
| 1074 | + ], | |
| 1075 | + 'lng' => [ | |
| 1076 | + 'type' => 'string', | |
| 1077 | + 'default' => '' | |
| 1078 | + ], | |
| 1079 | + 'width' => [ | |
| 1080 | + 'type' => 'string', | |
| 1081 | + 'default' => $width_default, | |
| 1082 | + ], | |
| 1123 | 1083 | |
| 1124 | - /** | |
| 1125 | - * Getenberg server side render | |
| 1126 | - * | |
| 1127 | - * @param $settings | |
| 1128 | - * | |
| 1129 | - * @return string | |
| 1130 | - */ | |
| 1131 | - public function render_block($attributes) | |
| 1132 | - { | |
| 1133 | - $settings = $this->settings; | |
| 1134 | - //$general_settings = get_option( 'cbxgooglemap_general', [] ); | |
| 1084 | + 'height' => [ | |
| 1085 | + 'type' => 'integer', | |
| 1086 | + 'default' => $height_default | |
| 1087 | + ], | |
| 1088 | + 'zoom' => [ | |
| 1089 | + 'type' => 'string', | |
| 1090 | + 'default' => $zoom_default | |
| 1091 | + ], | |
| 1092 | + 'scrollwheel' => [ | |
| 1093 | + 'type' => 'boolean', | |
| 1094 | + 'default' => ( $scrollwheel_default ) ? true : false | |
| 1095 | + ], | |
| 1096 | + 'showinfo' => [ | |
| 1097 | + 'type' => 'boolean', | |
| 1098 | + 'default' => ( $showinfo_default ) ? true : false | |
| 1099 | + ], | |
| 1100 | + 'infow_open' => [ | |
| 1101 | + 'type' => 'boolean', | |
| 1102 | + 'default' => ( $infow_open_default ) ? true : false | |
| 1103 | + ], | |
| 1104 | + 'heading' => [ | |
| 1105 | + 'type' => 'string', | |
| 1106 | + 'default' => '' | |
| 1107 | + ], | |
| 1108 | + 'address' => [ | |
| 1109 | + 'type' => 'string', | |
| 1110 | + 'default' => '' | |
| 1111 | + ], | |
| 1112 | + 'website' => [ | |
| 1113 | + 'type' => 'string', | |
| 1114 | + 'default' => '' | |
| 1115 | + ], | |
| 1116 | + 'mapicon' => [ | |
| 1117 | + 'type' => 'string', | |
| 1118 | + 'default' => '', | |
| 1119 | + ] | |
| 1120 | + ] ), | |
| 1121 | + 'render_callback' => [ $this, 'render_block' ] | |
| 1122 | + ] ); | |
| 1135 | 1123 | |
| 1136 | - $api_key = $settings->get_field('apikey', 'cbxgooglemap_general', ''); | |
| 1137 | - $map_source = intval($settings->get_field('mapsource', 'cbxgooglemap_general', 1)); | |
| 1124 | + }//end gutenberg_blocks | |
| 1138 | 1125 | |
| 1139 | - if ($map_source == 1 && $api_key == '') { | |
| 1140 | - echo '<p style="text-align: center;">'.esc_html__('Google Map Api Key is invalid!', 'cbxgooglemap').'</p>'; | |
| 1141 | - } else { | |
| 1142 | - $id = isset($attributes['id']) ? absint($attributes['id']) : 0; | |
| 1126 | + /** | |
| 1127 | + * Getenberg server side render | |
| 1128 | + * | |
| 1129 | + * @param $settings | |
| 1130 | + * | |
| 1131 | + * @return string | |
| 1132 | + */ | |
| 1133 | + public function render_block( $attributes ) { | |
| 1134 | + $settings = $this->settings; | |
| 1135 | + //$general_settings = get_option( 'cbxgooglemap_general', [] ); | |
| 1143 | 1136 | |
| 1144 | - if ($id > 0) { | |
| 1145 | - //render map from saved map | |
| 1146 | - return '[cbxgooglemap id="'.$id.'"]'; | |
| 1147 | - } else { | |
| 1148 | - $attr = []; | |
| 1137 | + $api_key = $settings->get_field( 'apikey', 'cbxgooglemap_general', '' ); | |
| 1138 | + $map_source = (int) $settings->get_field( 'mapsource', 'cbxgooglemap_general', 1 ); | |
| 1149 | 1139 | |
| 1150 | - if (isset($attributes['lat'])) { | |
| 1151 | - $attr['lat'] = sanitize_text_field(wp_unslash($attributes['lat'])); | |
| 1152 | - } | |
| 1140 | + if ( $map_source == 1 && $api_key == '' ) { | |
| 1141 | + echo '<p style="text-align: center;">' . esc_html__( 'Google Map Api Key is invalid!', 'cbxgooglemap' ) . '</p>'; | |
| 1142 | + } else { | |
| 1143 | + $id = isset( $attributes['id'] ) ? absint( $attributes['id'] ) : 0; | |
| 1153 | 1144 | |
| 1154 | - if (isset($attributes['lng'])) { | |
| 1155 | - $attr['lng'] = sanitize_text_field(wp_unslash($attributes['lng'])); | |
| 1156 | - } | |
| 1145 | + if ( $id > 0 ) { | |
| 1146 | + //render map from saved map | |
| 1147 | + return '[cbxgooglemap id="' . $id . '"]'; | |
| 1148 | + } else { | |
| 1149 | + $attr = []; | |
| 1157 | 1150 | |
| 1158 | - if (isset($attributes['width'])) { | |
| 1159 | - $attr['width'] = sanitize_text_field($attributes['width']); | |
| 1160 | - } | |
| 1151 | + if ( isset( $attributes['lat'] ) ) { | |
| 1152 | + $attr['lat'] = sanitize_text_field( wp_unslash( $attributes['lat'] ) ); | |
| 1153 | + } | |
| 1161 | 1154 | |
| 1162 | - if (isset($attributes['height'])) { | |
| 1163 | - $attr['height'] = intval($attributes['height']); | |
| 1164 | - } | |
| 1155 | + if ( isset( $attributes['lng'] ) ) { | |
| 1156 | + $attr['lng'] = sanitize_text_field( wp_unslash( $attributes['lng'] ) ); | |
| 1157 | + } | |
| 1165 | 1158 | |
| 1166 | - if (isset($attributes['zoom'])) { | |
| 1167 | - $attr['zoom'] = sanitize_text_field($attributes['zoom']); | |
| 1168 | - } | |
| 1159 | + if ( isset( $attributes['width'] ) ) { | |
| 1160 | + $attr['width'] = sanitize_text_field( $attributes['width'] ); | |
| 1161 | + } | |
| 1169 | 1162 | |
| 1163 | + if ( isset( $attributes['height'] ) ) { | |
| 1164 | + $attr['height'] = (int) $attributes['height']; | |
| 1165 | + } | |
| 1170 | 1166 | |
| 1171 | - $attr['scrollwheel'] = ! empty($attributes['scrollwheel']) ? 1 : 0; | |
| 1172 | - $attr['infow_open'] = ! empty($attributes['infow_open']) ? 1 : 0; | |
| 1173 | - $attr['showinfo'] = ! empty($attributes['showinfo']) ? 1 : 0; | |
| 1167 | + if ( isset( $attributes['zoom'] ) ) { | |
| 1168 | + $attr['zoom'] = sanitize_text_field( $attributes['zoom'] ); | |
| 1169 | + } | |
| 1174 | 1170 | |
| 1175 | - if (isset($attributes['heading'])) { | |
| 1176 | - $attr['heading'] = sanitize_text_field(wp_unslash($attributes['heading'])); | |
| 1177 | - } | |
| 1178 | - if (isset($attributes['address'])) { | |
| 1179 | - $attr['address'] = sanitize_text_field(wp_unslash($attributes['address'])); | |
| 1180 | - } | |
| 1181 | - if (isset($attributes['website'])) { | |
| 1182 | - $attr['website'] = sanitize_text_field(wp_unslash($attributes['website'])); | |
| 1183 | - } | |
| 1184 | - if (isset($attributes['maptype'])) { | |
| 1185 | - $attr['maptype'] = sanitize_text_field(wp_unslash($attributes['maptype'])); | |
| 1186 | - } | |
| 1187 | - if (isset($attributes['mapicon'])) { | |
| 1188 | - $attr['mapicon'] = esc_url($attributes['mapicon']); | |
| 1189 | - } | |
| 1190 | 1171 | |
| 1191 | - $attr = apply_filters('cbxgooglemap_block_shortcode_builder_attr', $attr, $attributes); | |
| 1172 | + $attr['scrollwheel'] = ! empty( $attributes['scrollwheel'] ) ? 1 : 0; | |
| 1173 | + $attr['infow_open'] = ! empty( $attributes['infow_open'] ) ? 1 : 0; | |
| 1174 | + $attr['showinfo'] = ! empty( $attributes['showinfo'] ) ? 1 : 0; | |
| 1192 | 1175 | |
| 1193 | - $attr_html = ''; | |
| 1176 | + if ( isset( $attributes['heading'] ) ) { | |
| 1177 | + $attr['heading'] = sanitize_text_field( wp_unslash( $attributes['heading'] ) ); | |
| 1178 | + } | |
| 1179 | + if ( isset( $attributes['address'] ) ) { | |
| 1180 | + $attr['address'] = sanitize_text_field( wp_unslash( $attributes['address'] ) ); | |
| 1181 | + } | |
| 1182 | + if ( isset( $attributes['website'] ) ) { | |
| 1183 | + $attr['website'] = sanitize_text_field( wp_unslash( $attributes['website'] ) ); | |
| 1184 | + } | |
| 1185 | + if ( isset( $attributes['maptype'] ) ) { | |
| 1186 | + $attr['maptype'] = sanitize_text_field( wp_unslash( $attributes['maptype'] ) ); | |
| 1187 | + } | |
| 1188 | + if ( isset( $attributes['mapicon'] ) ) { | |
| 1189 | + $attr['mapicon'] = esc_url( $attributes['mapicon'] ); | |
| 1190 | + } | |
| 1194 | 1191 | |
| 1195 | - foreach ($attr as $key => $value) { | |
| 1196 | - $attr_html .= ' '.$key.'="'.$value.'" '; | |
| 1197 | - } | |
| 1192 | + $attr = apply_filters( 'cbxgooglemap_block_shortcode_builder_attr', $attr, $attributes ); | |
| 1198 | 1193 | |
| 1199 | - //return do_shortcode( '[cbxgooglemap ' . $attr_html . ']' ); | |
| 1200 | - return '[cbxgooglemap '.$attr_html.']'; | |
| 1201 | - } | |
| 1202 | - }//end if api keys are ok | |
| 1194 | + $attr_html = ''; | |
| 1203 | 1195 | |
| 1204 | - }//end codeboxrflexiblecountdown_block_render | |
| 1196 | + foreach ( $attr as $key => $value ) { | |
| 1197 | + $attr_html .= ' ' . $key . '="' . $value . '" '; | |
| 1198 | + } | |
| 1205 | 1199 | |
| 1206 | - /** | |
| 1207 | - * Register New Gutenberg block Category if need | |
| 1208 | - * | |
| 1209 | - * @param $categories | |
| 1210 | - * @param $post | |
| 1211 | - * | |
| 1212 | - * @return mixed | |
| 1213 | - */ | |
| 1214 | - public function gutenberg_block_categories($categories, $post) | |
| 1215 | - { | |
| 1216 | - $found = false; | |
| 1217 | - foreach ($categories as $category) { | |
| 1218 | - if ($category['slug'] == 'codeboxr') { | |
| 1219 | - $found = true; | |
| 1220 | - break; | |
| 1221 | - } | |
| 1222 | - } | |
| 1200 | + //return do_shortcode( '[cbxgooglemap ' . $attr_html . ']' ); | |
| 1201 | + return '[cbxgooglemap ' . $attr_html . ']'; | |
| 1202 | + } | |
| 1203 | + }//end if api keys are ok | |
| 1223 | 1204 | |
| 1224 | - if ( ! $found) { | |
| 1225 | - return array_merge( | |
| 1226 | - $categories, | |
| 1227 | - [ | |
| 1228 | - [ | |
| 1229 | - 'slug' => 'codeboxr', | |
| 1230 | - 'title' => esc_html__('CBX Blocks', 'cbxgooglemap'), | |
| 1231 | - ], | |
| 1232 | - ] | |
| 1233 | - ); | |
| 1234 | - } | |
| 1205 | + }//end codeboxrflexiblecountdown_block_render | |
| 1235 | 1206 | |
| 1236 | - return $categories; | |
| 1237 | - }//end gutenberg_block_categories | |
| 1207 | + /** | |
| 1208 | + * Register New Gutenberg block Category if need | |
| 1209 | + * | |
| 1210 | + * @param $categories | |
| 1211 | + * @param $post | |
| 1212 | + * | |
| 1213 | + * @return mixed | |
| 1214 | + */ | |
| 1215 | + public function gutenberg_block_categories( $categories, $post ) { | |
| 1216 | + $found = false; | |
| 1217 | + foreach ( $categories as $category ) { | |
| 1218 | + if ( $category['slug'] == 'codeboxr' ) { | |
| 1219 | + $found = true; | |
| 1220 | + break; | |
| 1221 | + } | |
| 1222 | + } | |
| 1238 | 1223 | |
| 1224 | + if ( ! $found ) { | |
| 1225 | + return array_merge( | |
| 1226 | + $categories, | |
| 1227 | + [ | |
| 1228 | + [ | |
| 1229 | + 'slug' => 'codeboxr', | |
| 1230 | + 'title' => esc_html__( 'CBX Blocks', 'cbxgooglemap' ), | |
| 1231 | + ], | |
| 1232 | + ] | |
| 1233 | + ); | |
| 1234 | + } | |
| 1239 | 1235 | |
| 1240 | - /** | |
| 1241 | - * Enqueue style for block editor | |
| 1242 | - */ | |
| 1243 | - public function enqueue_block_editor_assets() | |
| 1244 | - { | |
| 1245 | - }//end enqueue_block_editor_assets | |
| 1236 | + return $categories; | |
| 1237 | + }//end gutenberg_block_categories | |
| 1246 | 1238 | |
| 1247 | - /** | |
| 1248 | - * Load setting html | |
| 1249 | - * | |
| 1250 | - * @return void | |
| 1251 | - */ | |
| 1252 | - public function settings_reset_load() | |
| 1253 | - { | |
| 1254 | - //security check | |
| 1255 | - check_ajax_referer('cbxgooglemap_nonce', 'security'); | |
| 1256 | 1239 | |
| 1257 | - $msg = []; | |
| 1258 | - $msg['html'] = ''; | |
| 1259 | - $msg['message'] = esc_html__('CBX Google Map reset setting html loaded successfully', 'cbxgooglemap'); | |
| 1260 | - $msg['success'] = 1; | |
| 1240 | + /** | |
| 1241 | + * Enqueue style for block editor | |
| 1242 | + */ | |
| 1243 | + public function enqueue_block_editor_assets() { | |
| 1244 | + }//end enqueue_block_editor_assets | |
| 1261 | 1245 | |
| 1262 | - if ( ! current_user_can('manage_options')) { | |
| 1263 | - $msg['message'] = esc_html__('Sorry, you don\'t have enough permission', 'cbxgooglemap'); | |
| 1264 | - $msg['success'] = 0; | |
| 1265 | - wp_send_json($msg); | |
| 1266 | - } | |
| 1246 | + /** | |
| 1247 | + * Load setting html | |
| 1248 | + * | |
| 1249 | + * @return void | |
| 1250 | + */ | |
| 1251 | + public function settings_reset_load() { | |
| 1252 | + //security check | |
| 1253 | + check_ajax_referer( 'cbxgooglemap_nonce', 'security' ); | |
| 1267 | 1254 | |
| 1268 | - $msg['html'] = CBXGooglemapHelper::setting_reset_html_table(); | |
| 1255 | + $msg = []; | |
| 1256 | + $msg['html'] = ''; | |
| 1257 | + $msg['message'] = esc_html__( 'CBX Google Map reset setting html loaded successfully', 'cbxgooglemap' ); | |
| 1258 | + $msg['success'] = 1; | |
| 1269 | 1259 | |
| 1270 | - wp_send_json($msg); | |
| 1271 | - } //end method settings_reset_load | |
| 1260 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 1261 | + $msg['message'] = esc_html__( 'Sorry, you don\'t have enough permission', 'cbxgooglemap' ); | |
| 1262 | + $msg['success'] = 0; | |
| 1263 | + wp_send_json( $msg ); | |
| 1264 | + } | |
| 1272 | 1265 | |
| 1273 | - /** | |
| 1274 | - * Full plugin reset and redirect | |
| 1275 | - */ | |
| 1276 | - public function plugin_options_reset() | |
| 1277 | - { | |
| 1266 | + $msg['html'] = CBXGooglemapHelper::setting_reset_html_table(); | |
| 1278 | 1267 | |
| 1279 | - //security check | |
| 1280 | - check_ajax_referer('cbxgooglemap_nonce', 'security'); | |
| 1268 | + wp_send_json( $msg ); | |
| 1269 | + } //end method settings_reset_load | |
| 1281 | 1270 | |
| 1282 | - $url = admin_url('admin.php?page=cbxgooglemap_settings'); | |
| 1271 | + /** | |
| 1272 | + * Full plugin reset and redirect | |
| 1273 | + */ | |
| 1274 | + public function plugin_options_reset() { | |
| 1283 | 1275 | |
| 1284 | - $msg = []; | |
| 1285 | - $msg['message'] = esc_html__('CBX Google Map setting options reset successfully', 'cbxgooglemap'); | |
| 1286 | - $msg['success'] = 1; | |
| 1287 | - $msg['url'] = $url; | |
| 1276 | + //security check | |
| 1277 | + check_ajax_referer( 'cbxgooglemap_nonce', 'security' ); | |
| 1288 | 1278 | |
| 1289 | - if ( ! current_user_can('manage_options')) { | |
| 1290 | - $msg['message'] = esc_html__('Sorry, you don\'t have enough permission', 'cbxgooglemap'); | |
| 1291 | - $msg['success'] = 0; | |
| 1292 | - wp_send_json($msg); | |
| 1293 | - } | |
| 1279 | + $url = admin_url( 'admin.php?page=cbxgooglemap_settings' ); | |
| 1294 | 1280 | |
| 1295 | - do_action('cbxgooglemap_plugin_reset_before'); | |
| 1281 | + $msg = []; | |
| 1282 | + $msg['message'] = esc_html__( 'CBX Google Map setting options reset successfully', 'cbxgooglemap' ); | |
| 1283 | + $msg['success'] = 1; | |
| 1284 | + $msg['url'] = $url; | |
| 1296 | 1285 | |
| 1297 | - $plugin_resets = wp_unslash($_POST); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 1286 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 1287 | + $msg['message'] = esc_html__( 'Sorry, you don\'t have enough permission', 'cbxgooglemap' ); | |
| 1288 | + $msg['success'] = 0; | |
| 1289 | + wp_send_json( $msg ); | |
| 1290 | + } | |
| 1298 | 1291 | |
| 1299 | - //delete options | |
| 1300 | - $reset_options = isset($plugin_resets['reset_options']) ? $plugin_resets['reset_options'] : []; | |
| 1301 | - $option_values = (is_array($reset_options) && sizeof($reset_options) > 0) ? array_values($reset_options) : array_values(CBXGooglemapHelper::getAllOptionNames()); | |
| 1292 | + do_action( 'cbxgooglemap_plugin_reset_before' ); | |
| 1302 | 1293 | |
| 1303 | - foreach ($option_values as $key => $option) { | |
| 1304 | - delete_option($option); | |
| 1305 | - } | |
| 1294 | + $plugin_resets = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing | |
| 1306 | 1295 | |
| 1307 | - do_action('cbxgooglemap_plugin_option_delete'); | |
| 1308 | - do_action('cbxgooglemap_plugin_reset_after'); | |
| 1309 | - do_action('cbxgooglemap_plugin_reset'); | |
| 1296 | + //delete options | |
| 1297 | + $reset_options = isset( $plugin_resets['reset_options'] ) ? $plugin_resets['reset_options'] : []; | |
| 1298 | + $option_values = ( is_array( $reset_options ) && sizeof( $reset_options ) > 0 ) ? array_values( $reset_options ) : array_values( CBXGooglemapHelper::getAllOptionNames() ); | |
| 1310 | 1299 | |
| 1311 | - wp_send_json($msg); | |
| 1312 | - } //end plugin_reset | |
| 1300 | + foreach ( $option_values as $key => $option ) { | |
| 1301 | + delete_option( $option ); | |
| 1302 | + } | |
| 1313 | 1303 | |
| 1314 | - /** | |
| 1315 | - * Export plugin global settings | |
| 1316 | - * | |
| 1317 | - * @return void | |
| 1318 | - */ | |
| 1319 | - public function settings_export() | |
| 1320 | - { | |
| 1304 | + do_action( 'cbxgooglemap_plugin_option_delete' ); | |
| 1305 | + do_action( 'cbxgooglemap_plugin_reset_after' ); | |
| 1306 | + do_action( 'cbxgooglemap_plugin_reset' ); | |
| 1321 | 1307 | |
| 1322 | - if (isset($_GET['cbxgooglemap_settings_export'])) { | |
| 1323 | - $url = admin_url('admin.php?page=cbxgooglemap_settings'); | |
| 1308 | + wp_send_json( $msg ); | |
| 1309 | + } //end plugin_reset | |
| 1324 | 1310 | |
| 1325 | - $msg = []; | |
| 1326 | - $msg['message'] = esc_html__('Google Map setting exported successfully', 'cbxgooglemap'); | |
| 1327 | - $msg['success'] = 1; | |
| 1328 | - $msg['url'] = $url; | |
| 1311 | + /** | |
| 1312 | + * Export plugin global settings | |
| 1313 | + * | |
| 1314 | + * @return void | |
| 1315 | + */ | |
| 1316 | + public function settings_export() { | |
| 1329 | 1317 | |
| 1330 | - $passed = true; | |
| 1318 | + if ( isset( $_GET['cbxgooglemap_settings_export'] ) ) { | |
| 1319 | + $url = admin_url( 'admin.php?page=cbxgooglemap_settings' ); | |
| 1331 | 1320 | |
| 1332 | - $nonce = isset($_GET['security']) ? sanitize_text_field(wp_unslash($_GET['security'])) : ''; | |
| 1333 | - if ( ! wp_verify_nonce($nonce, 'cbxgooglemap_settings_nonce')) { | |
| 1334 | - $passed = false; | |
| 1335 | - $msg['success'] = 0; | |
| 1336 | - $msg['message'] = esc_html__('Security check failed', 'cbxgooglemap'); | |
| 1337 | - } | |
| 1321 | + $msg = []; | |
| 1322 | + $msg['message'] = esc_html__( 'Google Map setting exported successfully', 'cbxgooglemap' ); | |
| 1323 | + $msg['success'] = 1; | |
| 1324 | + $msg['url'] = $url; | |
| 1338 | 1325 | |
| 1339 | - if ( ! current_user_can('manage_options')) { | |
| 1340 | - $passed = true; | |
| 1341 | - $msg['message'] = esc_html__('Sorry, you don\'t have enough permission', 'cbxgooglemap'); | |
| 1342 | - $msg['success'] = 0; | |
| 1343 | - } | |
| 1326 | + $passed = true; | |
| 1344 | 1327 | |
| 1345 | - if ( ! $passed) { | |
| 1346 | - wp_send_json($msg); | |
| 1347 | - } | |
| 1328 | + $nonce = isset( $_GET['security'] ) ? sanitize_text_field( wp_unslash( $_GET['security'] ) ) : ''; | |
| 1329 | + if ( ! wp_verify_nonce( $nonce, 'cbxgooglemap_settings_nonce' ) ) { | |
| 1330 | + $passed = false; | |
| 1331 | + $msg['success'] = 0; | |
| 1332 | + $msg['message'] = esc_html__( 'Security check failed', 'cbxgooglemap' ); | |
| 1333 | + } | |
| 1348 | 1334 | |
| 1349 | - // Get Meta box data | |
| 1350 | - $sections = CBXGoogleMapAdmin::get_settings_sections(); | |
| 1335 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 1336 | + $passed = true; | |
| 1337 | + $msg['message'] = esc_html__( 'Sorry, you don\'t have enough permission', 'cbxgooglemap' ); | |
| 1338 | + $msg['success'] = 0; | |
| 1339 | + } | |
| 1351 | 1340 | |
| 1352 | - $data = [ | |
| 1353 | - 'cbxgooglemap_settings' => true | |
| 1354 | - ]; | |
| 1341 | + if ( ! $passed ) { | |
| 1342 | + wp_send_json( $msg ); | |
| 1343 | + } | |
| 1355 | 1344 | |
| 1356 | - $single_section = isset($_REQUEST['section']) ? sanitize_text_field(wp_unslash($_REQUEST['section'])) : ''; | |
| 1345 | + // Get Meta box data | |
| 1346 | + $sections = CBXGoogleMapAdmin::get_settings_sections(); | |
| 1357 | 1347 | |
| 1358 | - foreach ($sections as $section) { | |
| 1359 | - if ($single_section != '' && $section['id'] != $single_section) { | |
| 1360 | - continue; | |
| 1361 | - } | |
| 1348 | + $data = [ | |
| 1349 | + 'cbxgooglemap_settings' => true | |
| 1350 | + ]; | |
| 1362 | 1351 | |
| 1352 | + $single_section = isset( $_REQUEST['section'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ) : ''; | |
| 1363 | 1353 | |
| 1364 | - $sections_fields = get_option($section['id']); | |
| 1365 | - if ( ! is_array($sections_fields)) { | |
| 1366 | - $sections_fields = []; | |
| 1367 | - } | |
| 1354 | + foreach ( $sections as $section ) { | |
| 1355 | + if ( $single_section != '' && $section['id'] != $single_section ) { | |
| 1356 | + continue; | |
| 1357 | + } | |
| 1368 | 1358 | |
| 1369 | - $data[$section['id']] = $sections_fields; | |
| 1370 | 1359 | |
| 1371 | - if ($single_section != '' && $section['id'] == $single_section) { | |
| 1372 | - break; | |
| 1373 | - } | |
| 1374 | - } | |
| 1360 | + $sections_fields = get_option( $section['id'] ); | |
| 1361 | + if ( ! is_array( $sections_fields ) ) { | |
| 1362 | + $sections_fields = []; | |
| 1363 | + } | |
| 1375 | 1364 | |
| 1376 | - // Create JSON | |
| 1377 | - $generate_json = wp_json_encode($data, JSON_PRETTY_PRINT); | |
| 1365 | + $data[ $section['id'] ] = $sections_fields; | |
| 1378 | 1366 | |
| 1379 | - // Create filename | |
| 1380 | - $filename = 'cbxgooglemap_settings_json'; | |
| 1367 | + if ( $single_section != '' && $section['id'] == $single_section ) { | |
| 1368 | + break; | |
| 1369 | + } | |
| 1370 | + } | |
| 1381 | 1371 | |
| 1382 | - // Force download .json file with JSON in it | |
| 1383 | - header('Content-type: application/vnd.ms-excel'); | |
| 1384 | - header('Content-Type: application/force-download'); | |
| 1385 | - header('Content-Type: application/download'); | |
| 1386 | - header('Content-disposition: '.$filename.'.json'); | |
| 1387 | - header('Content-disposition: filename='.$filename.'.json'); | |
| 1372 | + // Create JSON | |
| 1373 | + $generate_json = wp_json_encode( $data, JSON_PRETTY_PRINT ); | |
| 1388 | 1374 | |
| 1389 | - print $generate_json;//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1390 | - exit; | |
| 1391 | - }//end if export mode | |
| 1392 | - }//end method settings_export | |
| 1375 | + // Create filename | |
| 1376 | + $filename = 'cbxgooglemap_settings_json'; | |
| 1393 | 1377 | |
| 1394 | - /** | |
| 1395 | - * Import settings | |
| 1396 | - * | |
| 1397 | - * @return void | |
| 1398 | - */ | |
| 1399 | - public function settings_import() | |
| 1400 | - { | |
| 1401 | - //security check | |
| 1402 | - check_ajax_referer('cbxgooglemap_nonce', 'security'); | |
| 1378 | + // Force download .json file with JSON in it | |
| 1379 | + header( 'Content-type: application/vnd.ms-excel' ); | |
| 1380 | + header( 'Content-Type: application/force-download' ); | |
| 1381 | + header( 'Content-Type: application/download' ); | |
| 1382 | + header( 'Content-disposition: ' . $filename . '.json' ); | |
| 1383 | + header( 'Content-disposition: filename=' . $filename . '.json' ); | |
| 1403 | 1384 | |
| 1404 | - $msg = []; | |
| 1405 | - $msg['message'] = esc_html__('CBX Google Map Settings imported successfully', 'cbxgooglemap'); | |
| 1406 | - $msg['success'] = 1; | |
| 1385 | + print $generate_json;//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1386 | + exit; | |
| 1387 | + }//end if export mode | |
| 1388 | + }//end method settings_export | |
| 1407 | 1389 | |
| 1408 | - if ( ! current_user_can('manage_options')) { | |
| 1409 | - $msg['message'] = esc_html__('Sorry, you don\'t have enough permission', 'cbxgooglemap'); | |
| 1410 | - $msg['success'] = 0; | |
| 1411 | - wp_send_json($msg); | |
| 1412 | - } | |
| 1390 | + /** | |
| 1391 | + * Import settings | |
| 1392 | + * | |
| 1393 | + * @return void | |
| 1394 | + */ | |
| 1395 | + public function settings_import() { | |
| 1396 | + //security check | |
| 1397 | + check_ajax_referer( 'cbxgooglemap_nonce', 'security' ); | |
| 1413 | 1398 | |
| 1414 | - // Import settings api data | |
| 1415 | - $settings_data = isset($_REQUEST['settings_data']) ? sanitize_text_field(wp_unslash($_REQUEST['settings_data'])) : ''; | |
| 1416 | - $settings_data = str_replace('data:application/json;base64,', '', $settings_data); | |
| 1417 | - $settings_data = base64_decode($settings_data); | |
| 1399 | + $msg = []; | |
| 1400 | + $msg['message'] = esc_html__( 'CBX Google Map Settings imported successfully', 'cbxgooglemap' ); | |
| 1401 | + $msg['success'] = 1; | |
| 1418 | 1402 | |
| 1419 | - $settings_data = json_decode($settings_data, true); | |
| 1420 | - // Redirect to settings page | |
| 1421 | - $msg['url'] = admin_url('admin.php?page=cbxgooglemap_settings'); | |
| 1403 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 1404 | + $msg['message'] = esc_html__( 'Sorry, you don\'t have enough permission', 'cbxgooglemap' ); | |
| 1405 | + $msg['success'] = 0; | |
| 1406 | + wp_send_json( $msg ); | |
| 1407 | + } | |
| 1422 | 1408 | |
| 1423 | - if (isset($settings_data['cbxgooglemap_settings'])) { | |
| 1424 | - unset($settings_data['cbxgooglemap_settings']); | |
| 1409 | + // Import settings api data | |
| 1410 | + $settings_data = isset( $_REQUEST['settings_data'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['settings_data'] ) ) : ''; | |
| 1411 | + $settings_data = str_replace( 'data:application/json;base64,', '', $settings_data ); | |
| 1412 | + $settings_data = base64_decode( $settings_data ); | |
| 1425 | 1413 | |
| 1426 | - if (is_array($settings_data)) { | |
| 1427 | - foreach ($settings_data as $key => $value) { | |
| 1428 | - update_option($key, $value); | |
| 1429 | - } | |
| 1430 | - } | |
| 1431 | - wp_send_json($msg); | |
| 1432 | - } | |
| 1414 | + $settings_data = json_decode( $settings_data, true ); | |
| 1415 | + // Redirect to settings page | |
| 1416 | + $msg['url'] = admin_url( 'admin.php?page=cbxgooglemap_settings' ); | |
| 1433 | 1417 | |
| 1434 | - $msg['message'] = esc_html__('Sorry, wrong format data', 'cbxgooglemap'); | |
| 1435 | - $msg['success'] = 0; | |
| 1436 | - wp_send_json($msg); | |
| 1437 | - }//end method settings_import | |
| 1418 | + if ( isset( $settings_data['cbxgooglemap_settings'] ) ) { | |
| 1419 | + unset( $settings_data['cbxgooglemap_settings'] ); | |
| 1438 | 1420 | |
| 1439 | - /** | |
| 1440 | - * Reset single section | |
| 1441 | - * | |
| 1442 | - * @return void | |
| 1443 | - */ | |
| 1444 | - public function plugin_reset_section() | |
| 1445 | - { | |
| 1421 | + if ( is_array( $settings_data ) ) { | |
| 1422 | + foreach ( $settings_data as $key => $value ) { | |
| 1423 | + update_option( $key, $value ); | |
| 1424 | + } | |
| 1425 | + } | |
| 1426 | + wp_send_json( $msg ); | |
| 1427 | + } | |
| 1446 | 1428 | |
| 1447 | - //security check | |
| 1448 | - check_ajax_referer('cbxgooglemap_nonce', 'security'); | |
| 1429 | + $msg['message'] = esc_html__( 'Sorry, wrong format data', 'cbxgooglemap' ); | |
| 1430 | + $msg['success'] = 0; | |
| 1431 | + wp_send_json( $msg ); | |
| 1432 | + }//end method settings_import | |
| 1449 | 1433 | |
| 1450 | - $url = admin_url('admin.php?page=cbxgooglemap_settings'); | |
| 1434 | + /** | |
| 1435 | + * Reset single section | |
| 1436 | + * | |
| 1437 | + * @return void | |
| 1438 | + */ | |
| 1439 | + public function plugin_reset_section() { | |
| 1451 | 1440 | |
| 1452 | - $msg = []; | |
| 1453 | - $msg['message'] = esc_html__('Comfort Google Map setting section reset successfully', 'cbxgooglemap'); | |
| 1454 | - $msg['success'] = 1; | |
| 1455 | - $msg['url'] = $url; | |
| 1441 | + //security check | |
| 1442 | + check_ajax_referer( 'cbxgooglemap_nonce', 'security' ); | |
| 1456 | 1443 | |
| 1457 | - if ( ! current_user_can('manage_options')) { | |
| 1458 | - $msg['message'] = esc_html__('Sorry, you don\'t have enough permission', 'cbxgooglemap'); | |
| 1459 | - $msg['success'] = 0; | |
| 1460 | - wp_send_json($msg); | |
| 1461 | - } | |
| 1444 | + $url = admin_url( 'admin.php?page=cbxgooglemap_settings' ); | |
| 1462 | 1445 | |
| 1463 | - $section = isset($_POST['section']) ? sanitize_text_field(wp_unslash($_POST['section'])) : ''; | |
| 1464 | - if ($section == '') { | |
| 1465 | - $msg['message'] = esc_html__('Option section setting failed, as no section id is empty', 'cbxgooglemap'); | |
| 1466 | - $msg['success'] = 0; | |
| 1467 | - wp_send_json($msg); | |
| 1468 | - } | |
| 1446 | + $msg = []; | |
| 1447 | + $msg['message'] = esc_html__( 'Comfort Google Map setting section reset successfully', 'cbxgooglemap' ); | |
| 1448 | + $msg['success'] = 1; | |
| 1449 | + $msg['url'] = $url; | |
| 1469 | 1450 | |
| 1470 | - //before hooks | |
| 1471 | - do_action('cbxgooglemap_plugin_reset_section_before'); | |
| 1451 | + if ( ! current_user_can( 'manage_options' ) ) { | |
| 1452 | + $msg['message'] = esc_html__( 'Sorry, you don\'t have enough permission', 'cbxgooglemap' ); | |
| 1453 | + $msg['success'] = 0; | |
| 1454 | + wp_send_json( $msg ); | |
| 1455 | + } | |
| 1472 | 1456 | |
| 1457 | + $section = isset( $_POST['section'] ) ? sanitize_text_field( wp_unslash( $_POST['section'] ) ) : ''; | |
| 1458 | + if ( $section == '' ) { | |
| 1459 | + $msg['message'] = esc_html__( 'Option section setting failed, as no section id is empty', 'cbxgooglemap' ); | |
| 1460 | + $msg['success'] = 0; | |
| 1461 | + wp_send_json( $msg ); | |
| 1462 | + } | |
| 1473 | 1463 | |
| 1474 | - //delete the section | |
| 1475 | - delete_option($section); | |
| 1464 | + //before hooks | |
| 1465 | + do_action( 'cbxgooglemap_plugin_reset_section_before' ); | |
| 1476 | 1466 | |
| 1477 | - //after hoooks | |
| 1478 | - do_action('cbxgooglemap_plugin_reset_section_after'); | |
| 1479 | - do_action('cbxgooglemap_plugin_reset_section'); | |
| 1480 | 1467 | |
| 1481 | - wp_send_json($msg); | |
| 1482 | - }//end method plugin_reset_section | |
| 1468 | + //delete the section | |
| 1469 | + delete_option( $section ); | |
| 1470 | + | |
| 1471 | + //after hoooks | |
| 1472 | + do_action( 'cbxgooglemap_plugin_reset_section_after' ); | |
| 1473 | + do_action( 'cbxgooglemap_plugin_reset_section' ); | |
| 1474 | + | |
| 1475 | + wp_send_json( $msg ); | |
| 1476 | + }//end method plugin_reset_section | |
| 1483 | 1477 | }//end class CBXGoogleMapAdmin |