PluginProbe
WP Directory Kit / 1.5.4
WP Directory Kit v1.5.4
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / admin / class-wpdirectorykit-admin.php

class-wpdirectorykit-admin.php in WP Directory Kit 1.5.4, at admin/class-wpdirectorykit-admin.php

473 lines 17.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @link listing-themes.com
7 * @since 1.0.0
8 *
9 * @package Wpdirectorykit
10 * @subpackage Wpdirectorykit/admin
11 */
12
13 /**
14 * The admin-specific functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the admin-specific stylesheet and JavaScript.
18 *
19 * @package Wpdirectorykit
20 * @subpackage Wpdirectorykit/admin
21 * @author listing-themes.com <[email protected]>
22 */
23
24 if (! defined('ABSPATH')) {
25 exit; // Exit if accessed directly.
26 }
27 class Wpdirectorykit_Admin
28 {
29
30 /**
31 * The ID of this plugin.
32 *
33 * @since 1.0.0
34 * @access private
35 * @var string $plugin_name The ID of this plugin.
36 */
37 private $plugin_name;
38
39 /**
40 * The version of this plugin.
41 *
42 * @since 1.0.0
43 * @access private
44 * @var string $version The current version of this plugin.
45 */
46 private $version;
47
48 /**
49 * Initialize the class and set its properties.
50 *
51 * @since 1.0.0
52 * @param string $plugin_name The name of this plugin.
53 * @param string $version The version of this plugin.
54 */
55 public function __construct($plugin_name, $version)
56 {
57
58 $this->plugin_name = $plugin_name;
59 $this->version = $version;
60 }
61
62 /**
63 * Register the stylesheets for the admin area.
64 *
65 * @since 1.0.0
66 */
67 public function enqueue_styles()
68 {
69
70 /**
71 * This function is provided for demonstration purposes only.
72 *
73 * An instance of this class should be passed to the run() function
74 * defined in Wpdirectorykit_Loader as all of the hooks are defined
75 * in that particular class.
76 *
77 * The Wpdirectorykit_Loader will then create the relationship
78 * between the defined hooks and the functions defined in this
79 * class.
80 */
81
82 wp_register_style('wdk-treefield', WPDIRECTORYKIT_URL . 'public/js/wdk_treefield/treefield.css', array(), '1.0.0');
83 wp_register_style('wdk-modal', WPDIRECTORYKIT_URL . 'public/css/wdk-modal.css', array(), $this->version, 'all');
84 wp_register_style('wdk-notify', WPDIRECTORYKIT_URL . 'public/css/wdk-notify.css', array(), $this->version, 'all');
85 wp_register_style('leaflet', WPDIRECTORYKIT_URL . 'public/js/openstreetmap/leaflet.css', array(), '1.7.1', 'all');
86 wp_register_style('leaflet-cluster-def', WPDIRECTORYKIT_URL . 'public/js/openstreetmap/MarkerCluster.Default.css', array(), '1.7.1', 'all');
87 wp_register_style('leaflet-cluster', WPDIRECTORYKIT_URL . 'public/js/openstreetmap/MarkerCluster.css', array(), '1.7.1', 'all');
88
89 wp_register_style('select2-select2', WPDIRECTORYKIT_URL . 'public/js/select2/css/select2.min.css', array(), '4.0.13', 'all');
90 wp_register_style('jquery-confirm', WPDIRECTORYKIT_URL . 'public/js/jquery-confirm/css/jquery-confirm.css', array(), '3.3.4', 'all');
91
92 wp_register_style('wdk-treefield-dropdown', WPDIRECTORYKIT_URL . 'public/js/wdk_treefield_dropdown/wdk_treefield_dropdown.css', array(), '1.0', 'all');
93
94 wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpdirectorykit-admin.css', array(), $this->version, 'all');
95 wp_enqueue_style($this->plugin_name . '-responsive', plugin_dir_url(__FILE__) . 'css/wpdirectorykit-admin-responsive.css', array(), $this->version, 'all');
96 wp_register_style('jquery-ui', WPDIRECTORYKIT_URL . 'public/css/jquery-ui.css', array(), null);
97
98 // Register and enqueue Tribute.js style
99 wp_register_style(
100 'tribute-css',
101 'https://cdn.jsdelivr.net/npm/[email protected]/dist/tribute.css',
102 [],
103 '5.1.3'
104 );
105
106 }
107
108 /**
109 * Register the JavaScript for the admin area.
110 *
111 * @since 1.0.0
112 */
113 public function enqueue_scripts()
114 {
115
116 /**
117 * This function is provided for demonstration purposes only.
118 *
119 * An instance of this class should be passed to the run() function
120 * defined in Wpdirectorykit_Loader as all of the hooks are defined
121 * in that particular class.
122 *
123 * The Wpdirectorykit_Loader will then create the relationship
124 * between the defined hooks and the functions defined in this
125 * class.
126 */
127
128
129 // Register and enqueue Tribute.js script
130 wp_register_script(
131 'tribute-js',
132 'https://cdn.jsdelivr.net/npm/[email protected]/dist/tribute.min.js',
133 [],
134 '5.1.3',
135 true
136 );
137
138 wp_register_script('wdk-treefield', WPDIRECTORYKIT_URL . 'public/js/wdk_treefield/treefield.js', array('jquery'), false, false);
139 wp_register_script('wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array('jquery'), false, false);
140
141 wp_register_script('wdk-modal', WPDIRECTORYKIT_URL . 'public/js/wdk-modal.js', array('jquery'), $this->version, false);
142 wp_register_script('wdk-notify', WPDIRECTORYKIT_URL . 'public/js/wdk-notify.js', array('jquery'), $this->version, false);
143 wp_register_script('leaflet', WPDIRECTORYKIT_URL . 'public/js/openstreetmap/leaflet.js', array('jquery'), '1.7.1', false);
144
145 wp_register_script('leaflet-cluster', WPDIRECTORYKIT_URL . 'public/js/openstreetmap/leaflet.markercluster.js', array('jquery'), '1.7.1', false);
146
147
148 wp_register_script('select2-select2', WPDIRECTORYKIT_URL . 'public/js/select2/js/select2.min.js', array('jquery'), '4.0.13', false);
149 wp_register_script('wdk-select2', WPDIRECTORYKIT_URL . 'public/js/wdk-select2.js', array('jquery'), '4.0.13', false);
150
151 $params = array(
152 'ajax_url' => admin_url('admin-ajax.php'),
153 'text' => array(
154 'errorLoading' => esc_html__('The results could not be loaded.', 'wpdirectorykit'),
155 'loadingMore' => esc_html__('Loading more results…', 'wpdirectorykit'),
156 'noResults' => esc_html__('No results found', 'wpdirectorykit'),
157 'searching' => esc_html__('Searching…', 'wpdirectorykit'),
158 'removeAllItems' => esc_html__('Remove all items', 'wpdirectorykit'),
159 "read_more"=> esc_html__("Read More", 'wpdirectorykit'),
160 "read_less"=> esc_html__("Read Less", 'wpdirectorykit'),
161 ),
162 'wpApiSettings' => [
163 'root'=> esc_url_raw(rest_url()),
164 'nonce'=> wp_create_nonce('wp_rest'),
165 'wdk_secure_nonce'=> wp_create_nonce('wdk_secure_ajax'),
166 ]
167 );
168 wp_localize_script('wdk-select2', 'wdk_select2_script_parameters', $params);
169
170 wp_register_script('jquery-confirm', WPDIRECTORYKIT_URL . 'public/js/jquery-confirm/js/jquery-confirm.js', array('jquery'), '3.3.4', false);
171 wp_register_script('wdk-dependfields-submitform', WPDIRECTORYKIT_URL . 'public/js/wdk-dependfields-submitform.js', array('jquery'), false, false);
172
173 wp_register_script('wdk-treefield-dropdown', WPDIRECTORYKIT_URL . 'public/js/wdk_treefield_dropdown/wdk_treefield_dropdown.js', array('jquery'), '1.0', false);
174 wp_localize_script('wdk-treefield-dropdown', 'script_parameters', $params);
175 wp_localize_script('wdk-treefield-dropdown', 'wdk_script_parameters', $params);
176
177 wp_register_script('wdk-dependfields-edit', plugin_dir_url(__FILE__) . 'js/wdk-dependfields-edit.js', array('jquery'), $this->version, false);
178 $params = array(
179 'ajax_url' => admin_url('admin-ajax.php'),
180 );
181
182 wp_localize_script('wdk-dependfields-edit', 'script_dependfields_parameters', $params);
183
184 $params = array(
185 'ajax_url' => admin_url('admin-ajax.php'),
186 'format_date' => wdk_convert_date_format_js(get_option('date_format')),
187 'format_datetime' => wdk_convert_date_format_js(get_option('date_format') . ' ' . get_option('time_format')),
188 'format_date_js' => wdk_convert_date_format_jquery(get_option('date_format')),
189 'format_datetime_js' => wdk_convert_date_format_jquery(get_option('date_format') . ' ' . get_option('time_format')),
190 'text' => array(
191 "read_more"=> esc_html__("Read More", 'wpdirectorykit'),
192 "read_less"=> esc_html__("Read Less", 'wpdirectorykit'),
193 ),
194 'wpApiSettings' => [
195 'root'=> esc_url_raw(rest_url()),
196 'nonce'=> wp_create_nonce('wp_rest'),
197 'wdk_secure_nonce'=> wp_create_nonce('wdk_secure_ajax'),
198 ]
199 );
200 wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/wpdirectorykit-admin.js', array('jquery'), $this->version, false);
201 wp_localize_script($this->plugin_name, 'script_parameters', $params);
202 wp_localize_script($this->plugin_name, 'wdk_script_parameters', $params);
203
204 }
205
206 /**
207 * Admin AJAX
208 */
209
210 public function ajax_admin()
211 {
212 global $Winter_MVC_WDK;
213
214 $page = '';
215 $function = '';
216
217 if (isset($_POST['page'])) $page = sanitize_text_field($_POST['page']);
218 if (isset($_POST['function'])) $function = sanitize_text_field($_POST['function']);
219
220 $Winter_MVC_WDK->load_controller($page, $function, array());
221 }
222
223 /**
224 * Admin Page Display
225 */
226 public function admin_page_display()
227 {
228 global $Winter_MVC_WDK, $submenu, $menu;
229
230 $page = '';
231 $function = '';
232
233 if (isset($_GET['page'])) $page = sanitize_text_field(wp_unslash($_GET['page']));
234 if (isset($_GET['function'])) $function = sanitize_text_field(wp_unslash($_GET['function']));
235
236 if (substr($function, 0, 1) == '_') {
237 exit(esc_html__('blocked for public', 'wpdirectorykit'));
238 }
239
240 $Winter_MVC_WDK->load_controller($page, $function, array());
241 }
242
243 private function multilingual_register_strings()
244 {
245 if (!function_exists('PLL')) return;
246
247 global $Winter_MVC_WDK;
248 $Winter_MVC_WDK->model('field_m');
249 $Winter_MVC_WDK->model('category_m');
250 $Winter_MVC_WDK->model('location_m');
251
252 $fields = $Winter_MVC_WDK->field_m->get();
253
254 foreach ($fields as $field) {
255 if (!empty($field->field_label))
256 pll_register_string('wpdirectorykit', $field->field_label, 'wdk-fields');
257
258 if (!empty($field->values_list))
259 pll_register_string('wpdirectorykit', $field->values_list, 'wdk-fields');
260
261 if (!empty($field->hint))
262 pll_register_string('wpdirectorykit', $field->hint, 'wdk-fields');
263 }
264
265 $categories = $Winter_MVC_WDK->category_m->get_tree_table();
266
267 foreach ($categories as $category) {
268 pll_register_string('wpdirectorykit', $category->category_title, 'wdk-categories');
269 }
270
271 $locations = $Winter_MVC_WDK->location_m->get_tree_table();
272
273 foreach ($locations as $location) {
274 pll_register_string('wpdirectorykit', $location->location_title, 'wdk-locations');
275 }
276 }
277
278 /**
279 * To add Plugin Menu and Settings page
280 */
281 public function plugin_menu()
282 {
283
284 ob_start();
285
286 $this->multilingual_register_strings();
287
288 //require_once WPDIRECTORYKIT_PATH . 'vendor/boo-settings-helper/class-boo-settings-helper.php';
289
290 add_menu_page(
291 __('Directory Kit', 'wpdirectorykit'),
292 __('Directory Kit', 'wpdirectorykit'),
293 'wdk_listings_manage',
294 'wdk',
295 array($this, 'admin_page_display'),
296 //plugin_dir_url( __FILE__ ) . 'resources/logo.png',
297 'dashicons-category',
298 28
299 );
300
301 add_submenu_page(
302 'wdk',
303 __('Listings', 'wpdirectorykit'),
304 __('Listings', 'wpdirectorykit'),
305 'wdk_listings_manage',
306 'wdk',
307 array($this, 'admin_page_display')
308 );
309
310 add_submenu_page(
311 'wdk',
312 __('Add Listing', 'wpdirectorykit'),
313 __('Add Listing', 'wpdirectorykit'),
314 'wdk_listings_manage',
315 'wdk_listing',
316 array($this, 'admin_page_display')
317 );
318
319 add_submenu_page(
320 'wdk',
321 __('Fields', 'wpdirectorykit'),
322 __('Fields', 'wpdirectorykit'),
323 'wdk_listings_manage',
324 'wdk_fields',
325 array($this, 'admin_page_display')
326 );
327
328 if (get_option('wdk_is_category_enabled', FALSE))
329 add_submenu_page(
330 'wdk',
331 __('Categories', 'wpdirectorykit'),
332 __('Categories', 'wpdirectorykit'),
333 'wdk_listings_manage',
334 'wdk_category',
335 array($this, 'admin_page_display')
336 );
337
338 if (get_option('wdk_is_location_enabled', FALSE))
339 add_submenu_page(
340 'wdk',
341 __('Locations', 'wpdirectorykit'),
342 __('Locations', 'wpdirectorykit'),
343 'wdk_listings_manage',
344 'wdk_location',
345 array($this, 'admin_page_display')
346 );
347
348 add_submenu_page(
349 'wdk',
350 __('Search Form', 'wpdirectorykit'),
351 __('Search Form', 'wpdirectorykit'),
352 'wdk_listings_manage',
353 'wdk_searchform',
354 array($this, 'admin_page_display')
355 );
356
357 add_submenu_page(
358 'wdk',
359 __('Result Card', 'wpdirectorykit'),
360 __('Result Card', 'wpdirectorykit'),
361 'wdk_listings_manage',
362 'wdk_resultitem',
363 array($this, 'admin_page_display')
364 );
365
366 add_submenu_page(
367 'wdk',
368 __('Change Currency', 'wpdirectorykit'),
369 __('Change Currency', 'wpdirectorykit'),
370 'wdk_listings_manage',
371 'wdk_change_currency',
372 array($this, 'admin_page_display')
373 );
374
375 add_submenu_page(
376 'wdk',
377 __('Messages', 'wpdirectorykit'),
378 __('Messages', 'wpdirectorykit'),
379 'wdk_listings_manage',
380 'wdk_messages',
381 array($this, 'admin_page_display')
382 );
383
384 add_submenu_page(
385 'wdk',
386 __('Settings', 'wpdirectorykit'),
387 __('Settings', 'wpdirectorykit'),
388 'wdk_listings_manage',
389 'wdk_settings',
390 array($this, 'admin_page_display')
391 );
392
393 add_submenu_page(
394 'wdk',
395 __('Documentation', 'wpdirectorykit'),
396 __('Documentation', 'wpdirectorykit'),
397 'wdk_listings_manage',
398 'https://wpdirectorykit.com/documentation'
399 );
400
401 //if(!file_exists(WPDIRECTORYKIT_PATH . 'premium_functions.php') || defined('WDK_FS_DISABLE'))
402 //{
403
404 if (!file_exists(WP_PLUGIN_DIR . '/wdk-currency-conversion') || !is_plugin_active('wdk-currency-conversion/wdk-currency-conversion.php'))
405 add_submenu_page(
406 'wdk',
407 __('Currencies Addon', 'wpdirectorykit'),
408 __('Currencies Addon', 'wpdirectorykit'),
409 'wdk_listings_manage',
410 'wdk_addons_currencies',
411 array($this, 'admin_page_display')
412 );
413
414 if (!file_exists(WP_PLUGIN_DIR . '/wdk-membership') || !is_plugin_active('wdk-membership/wdk-membership.php'))
415 add_submenu_page(
416 'wdk',
417 __('Membership Addon', 'wpdirectorykit'),
418 __('Membership Addon', 'wpdirectorykit'),
419 'wdk_listings_manage',
420 'wdk_addons_membership',
421 array($this, 'admin_page_display')
422 );
423
424 if (!file_exists(WP_PLUGIN_DIR . '/wdk-bookings') || !is_plugin_active('wdk-bookings/wdk-bookings.php'))
425 add_submenu_page(
426 'wdk',
427 __('Booking Addon', 'wpdirectorykit'),
428 __('Booking Addon', 'wpdirectorykit'),
429 'wdk_listings_manage',
430 'wdk_addons_bookings',
431 array($this, 'admin_page_display')
432 );
433
434 add_submenu_page(
435 'wdk',
436 __('More Addons', 'wpdirectorykit'),
437 __('More Addons', 'wpdirectorykit'),
438 'wdk_listings_manage',
439 'wdk_addons',
440 array($this, 'admin_page_display')
441 );
442
443 add_submenu_page(
444 'wdk',
445 __('Support Forum', 'wpdirectorykit'),
446 __('Support Forum', 'wpdirectorykit'),
447 'wdk_listings_manage',
448 'https://wordpress.org/support/plugin/wpdirectorykit/'
449 );
450
451 add_submenu_page(
452 'wdk',
453 __('Contact', 'wpdirectorykit'),
454 __('Contact', 'wpdirectorykit'),
455 'wdk_listings_manage',
456 'https://wpdirectorykit.com/contact.html'
457 );
458 //}
459
460 $current_theme = wp_get_theme();
461
462 if (defined('WP_DEBUG') && WP_DEBUG && $current_theme->get('AuthorURI') == 'https://wpdirectorykit.com')
463 add_submenu_page(
464 'tools.php',
465 esc_html__('WDK Demo Import', 'wpdirectorykit'),
466 esc_html__('WDK Demo Import', 'wpdirectorykit'),
467 'wdk_listings_manage',
468 'wdk_demo_import',
469 array($this, 'admin_page_display')
470 );
471 }
472 }
473