| 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 <dev@listing-themes.com> |
| 22 |
*/ |
| 23 |
|
| 24 |
if ( ! defined( 'ABSPATH' ) ) { |
| 25 |
exit; // Exit if accessed directly. |
| 26 |
} |
| 27 |
class Wpdirectorykit_Admin { |
| 28 |
|
| 29 |
/** |
| 30 |
* The ID of this plugin. |
| 31 |
* |
| 32 |
* @since 1.0.0 |
| 33 |
* @access private |
| 34 |
* @var string $plugin_name The ID of this plugin. |
| 35 |
*/ |
| 36 |
private $plugin_name; |
| 37 |
|
| 38 |
/** |
| 39 |
* The version of this plugin. |
| 40 |
* |
| 41 |
* @since 1.0.0 |
| 42 |
* @access private |
| 43 |
* @var string $version The current version of this plugin. |
| 44 |
*/ |
| 45 |
private $version; |
| 46 |
|
| 47 |
/** |
| 48 |
* Initialize the class and set its properties. |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
* @param string $plugin_name The name of this plugin. |
| 52 |
* @param string $version The version of this plugin. |
| 53 |
*/ |
| 54 |
public function __construct( $plugin_name, $version ) { |
| 55 |
|
| 56 |
$this->plugin_name = $plugin_name; |
| 57 |
$this->version = $version; |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Register the stylesheets for the admin area. |
| 63 |
* |
| 64 |
* @since 1.0.0 |
| 65 |
*/ |
| 66 |
public function enqueue_styles() { |
| 67 |
|
| 68 |
/** |
| 69 |
* This function is provided for demonstration purposes only. |
| 70 |
* |
| 71 |
* An instance of this class should be passed to the run() function |
| 72 |
* defined in Wpdirectorykit_Loader as all of the hooks are defined |
| 73 |
* in that particular class. |
| 74 |
* |
| 75 |
* The Wpdirectorykit_Loader will then create the relationship |
| 76 |
* between the defined hooks and the functions defined in this |
| 77 |
* class. |
| 78 |
*/ |
| 79 |
|
| 80 |
wp_register_style( 'wdk-treefield', WPDIRECTORYKIT_URL . 'public/js/wdk_treefield/treefield.css', array(), '1.0.0' ); |
| 81 |
wp_register_style( 'wdk-modal', WPDIRECTORYKIT_URL. 'public/css/wdk-modal.css', array(), $this->version, 'all'); |
| 82 |
wp_register_style( 'wdk-notify', WPDIRECTORYKIT_URL. 'public/css/wdk-notify.css', array(), $this->version, 'all'); |
| 83 |
wp_register_style( 'leaflet', WPDIRECTORYKIT_URL. 'public/js/openstreetmap/leaflet.css', array(), '1.7.1', 'all' ); |
| 84 |
wp_register_style( 'leaflet-cluster-def', WPDIRECTORYKIT_URL. 'public/js/openstreetmap/MarkerCluster.Default.css', array(), '1.7.1', 'all' ); |
| 85 |
wp_register_style( 'leaflet-cluster', WPDIRECTORYKIT_URL. 'public/js/openstreetmap/MarkerCluster.css', array(), '1.7.1', 'all' ); |
| 86 |
|
| 87 |
wp_register_style( 'select2', WPDIRECTORYKIT_URL. 'public/js/select2/css/select2.min.css', array(), '4.0.13', 'all' ); |
| 88 |
wp_register_style('jquery-confirm', WPDIRECTORYKIT_URL. 'public/js/jquery-confirm/css/jquery-confirm.css', array(), '3.3.4', 'all'); |
| 89 |
|
| 90 |
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wpdirectorykit-admin.css', array(), $this->version, 'all' ); |
| 91 |
wp_enqueue_style( $this->plugin_name.'-responsive', plugin_dir_url( __FILE__ ) . 'css/wpdirectorykit-admin-responsive.css', array(), $this->version, 'all' ); |
| 92 |
wp_register_style('jquery-ui', WPDIRECTORYKIT_URL. 'public/css/jquery-ui.css', array(), null ); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Register the JavaScript for the admin area. |
| 97 |
* |
| 98 |
* @since 1.0.0 |
| 99 |
*/ |
| 100 |
public function enqueue_scripts() { |
| 101 |
|
| 102 |
/** |
| 103 |
* This function is provided for demonstration purposes only. |
| 104 |
* |
| 105 |
* An instance of this class should be passed to the run() function |
| 106 |
* defined in Wpdirectorykit_Loader as all of the hooks are defined |
| 107 |
* in that particular class. |
| 108 |
* |
| 109 |
* The Wpdirectorykit_Loader will then create the relationship |
| 110 |
* between the defined hooks and the functions defined in this |
| 111 |
* class. |
| 112 |
*/ |
| 113 |
|
| 114 |
wp_register_script( 'wdk-treefield', WPDIRECTORYKIT_URL . 'public/js/wdk_treefield/treefield.js', array( 'jquery' ), false, false ); |
| 115 |
wp_register_script( 'wpmediaelement_file', WPDIRECTORYKIT_URL . 'admin/js/jquery.wpmediaelement_file.js', array( 'jquery' ), false, false ); |
| 116 |
|
| 117 |
wp_register_script( 'wdk-modal', WPDIRECTORYKIT_URL. 'public/js/wdk-modal.js', array( 'jquery' ), $this->version, false); |
| 118 |
wp_register_script( 'wdk-notify', WPDIRECTORYKIT_URL. 'public/js/wdk-notify.js', array( 'jquery' ), $this->version, false); |
| 119 |
wp_register_script( 'leaflet', WPDIRECTORYKIT_URL. 'public/js/openstreetmap/leaflet.js', array( 'jquery' ), '1.7.1', false ); |
| 120 |
|
| 121 |
wp_register_script( 'leaflet-cluster', WPDIRECTORYKIT_URL. 'public/js/openstreetmap/leaflet.markercluster.js', array( 'jquery' ), '1.7.1', false ); |
| 122 |
|
| 123 |
|
| 124 |
wp_register_script('select2', WPDIRECTORYKIT_URL. 'public/js/select2/js/select2.min.js', array( 'jquery' ), '4.0.13', false ); |
| 125 |
wp_register_script('wdk-select2', WPDIRECTORYKIT_URL. 'public/js/wdk-select2.js', array( 'jquery' ), '4.0.13', false ); |
| 126 |
|
| 127 |
wp_register_script('jquery-confirm', WPDIRECTORYKIT_URL. 'public/js/jquery-confirm/js/jquery-confirm.js', array( 'jquery' ), '3.3.4', false ); |
| 128 |
wp_register_script( 'wdk-dependfields-submitform', WPDIRECTORYKIT_URL. 'public/js/wdk-dependfields-submitform.js', array( 'jquery' ), false, false ); |
| 129 |
|
| 130 |
wp_register_script( 'wdk-dependfields-edit', plugin_dir_url( __FILE__ ) . 'js/wdk-dependfields-edit.js', array( 'jquery' ), $this->version, false ); |
| 131 |
$params = array( |
| 132 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 133 |
); |
| 134 |
|
| 135 |
wp_localize_script('wdk-dependfields-edit', 'script_dependfields_parameters', $params); |
| 136 |
|
| 137 |
$params = array( |
| 138 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 139 |
'format_date' => wdk_convert_date_format_js(get_option('date_format')), |
| 140 |
'format_datetime' => wdk_convert_date_format_js(get_option('date_format').' '.get_option('time_format')), |
| 141 |
'format_date_js' => wdk_convert_date_format_jquery(get_option('date_format')), |
| 142 |
'format_datetime_js' => wdk_convert_date_format_jquery(get_option('date_format').' '.get_option('time_format')), |
| 143 |
); |
| 144 |
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/wpdirectorykit-admin.js', array( 'jquery' ), $this->version, false ); |
| 145 |
wp_localize_script( $this->plugin_name, 'script_parameters', $params); |
| 146 |
|
| 147 |
|
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Admin AJAX |
| 152 |
*/ |
| 153 |
|
| 154 |
public function ajax_admin() |
| 155 |
{ |
| 156 |
global $Winter_MVC_WDK; |
| 157 |
|
| 158 |
$page = ''; |
| 159 |
$function = ''; |
| 160 |
|
| 161 |
if(isset($_POST['page']))$page = sanitize_text_field($_POST['page']); |
| 162 |
if(isset($_POST['function']))$function = sanitize_text_field($_POST['function']); |
| 163 |
|
| 164 |
$Winter_MVC_WDK->load_controller($page, $function, array()); |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Admin Page Display |
| 169 |
*/ |
| 170 |
public function admin_page_display() { |
| 171 |
global $Winter_MVC_WDK, $submenu, $menu; |
| 172 |
|
| 173 |
$page = ''; |
| 174 |
$function = ''; |
| 175 |
|
| 176 |
if(isset($_GET['page']))$page = sanitize_text_field($_GET['page']); |
| 177 |
if(isset($_GET['function']))$function = sanitize_text_field($_GET['function']); |
| 178 |
|
| 179 |
$Winter_MVC_WDK->load_controller($page, $function, array()); |
| 180 |
} |
| 181 |
|
| 182 |
private function multilingual_register_strings() |
| 183 |
{ |
| 184 |
if (!function_exists('PLL'))return; |
| 185 |
|
| 186 |
global $Winter_MVC_WDK; |
| 187 |
$Winter_MVC_WDK->model('field_m'); |
| 188 |
$Winter_MVC_WDK->model('category_m'); |
| 189 |
$Winter_MVC_WDK->model('location_m'); |
| 190 |
|
| 191 |
$fields = $Winter_MVC_WDK->field_m->get(); |
| 192 |
|
| 193 |
foreach($fields as $field) |
| 194 |
{ |
| 195 |
if(!empty($field->field_label)) |
| 196 |
pll_register_string( 'wpdirectorykit', $field->field_label, 'wdk-fields'); |
| 197 |
|
| 198 |
if(!empty($field->values_list)) |
| 199 |
pll_register_string( 'wpdirectorykit', $field->values_list, 'wdk-fields'); |
| 200 |
|
| 201 |
if(!empty($field->hint)) |
| 202 |
pll_register_string( 'wpdirectorykit', $field->hint, 'wdk-fields'); |
| 203 |
} |
| 204 |
|
| 205 |
$categories = $Winter_MVC_WDK->category_m->get_tree_table(); |
| 206 |
|
| 207 |
foreach($categories as $category) |
| 208 |
{ |
| 209 |
pll_register_string( 'wpdirectorykit', $category->category_title, 'wdk-categories'); |
| 210 |
} |
| 211 |
|
| 212 |
$locations = $Winter_MVC_WDK->location_m->get_tree_table(); |
| 213 |
|
| 214 |
foreach($locations as $location) |
| 215 |
{ |
| 216 |
pll_register_string( 'wpdirectorykit', $location->location_title, 'wdk-locations'); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* To add Plugin Menu and Settings page |
| 222 |
*/ |
| 223 |
public function plugin_menu() { |
| 224 |
|
| 225 |
ob_start(); |
| 226 |
|
| 227 |
$this->multilingual_register_strings(); |
| 228 |
|
| 229 |
//require_once WPDIRECTORYKIT_PATH . 'vendor/boo-settings-helper/class-boo-settings-helper.php'; |
| 230 |
|
| 231 |
add_menu_page(__('Directory Kit','wpdirectorykit'), __('Directory Kit','wpdirectorykit'), |
| 232 |
'manage_options', 'wdk', array($this, 'admin_page_display'), |
| 233 |
//plugin_dir_url( __FILE__ ) . 'resources/logo.png', |
| 234 |
'dashicons-category', |
| 235 |
28 ); |
| 236 |
|
| 237 |
add_submenu_page('wdk', |
| 238 |
__('Listings','wpdirectorykit'), |
| 239 |
__('Listings','wpdirectorykit'), |
| 240 |
'manage_options', 'wdk', array($this, 'admin_page_display')); |
| 241 |
|
| 242 |
add_submenu_page('wdk', |
| 243 |
__('Add Listing','wpdirectorykit'), |
| 244 |
__('Add Listing','wpdirectorykit'), |
| 245 |
'manage_options', 'wdk_listing', array($this, 'admin_page_display')); |
| 246 |
|
| 247 |
add_submenu_page('wdk', |
| 248 |
__('Fields','wpdirectorykit'), |
| 249 |
__('Fields','wpdirectorykit'), |
| 250 |
'manage_options', 'wdk_fields', array($this, 'admin_page_display')); |
| 251 |
|
| 252 |
if(get_option('wdk_is_category_enabled', FALSE)) |
| 253 |
add_submenu_page('wdk', |
| 254 |
__('Categories','wpdirectorykit'), |
| 255 |
__('Categories','wpdirectorykit'), |
| 256 |
'manage_options', 'wdk_category', array($this, 'admin_page_display')); |
| 257 |
|
| 258 |
if(get_option('wdk_is_location_enabled', FALSE)) |
| 259 |
add_submenu_page('wdk', |
| 260 |
__('Locations','wpdirectorykit'), |
| 261 |
__('Locations','wpdirectorykit'), |
| 262 |
'manage_options', 'wdk_location', array($this, 'admin_page_display')); |
| 263 |
|
| 264 |
add_submenu_page('wdk', |
| 265 |
__('Search Form','wpdirectorykit'), |
| 266 |
__('Search Form','wpdirectorykit'), |
| 267 |
'manage_options', 'wdk_searchform', array($this, 'admin_page_display')); |
| 268 |
|
| 269 |
add_submenu_page('wdk', |
| 270 |
__('Result Card','wpdirectorykit'), |
| 271 |
__('Result Card','wpdirectorykit'), |
| 272 |
'manage_options', 'wdk_resultitem', array($this, 'admin_page_display')); |
| 273 |
|
| 274 |
add_submenu_page('wdk', |
| 275 |
__('Change Currency','wpdirectorykit'), |
| 276 |
__('Change Currency','wpdirectorykit'), |
| 277 |
'manage_options', 'wdk_change_currency', array($this, 'admin_page_display')); |
| 278 |
|
| 279 |
add_submenu_page('wdk', |
| 280 |
__('Messages','wpdirectorykit'), |
| 281 |
__('Messages','wpdirectorykit'), |
| 282 |
'manage_options', 'wdk_messages', array($this, 'admin_page_display')); |
| 283 |
|
| 284 |
add_submenu_page('wdk', |
| 285 |
__('Settings','wpdirectorykit'), |
| 286 |
__('Settings','wpdirectorykit'), |
| 287 |
'manage_options', 'wdk_settings', array($this, 'admin_page_display')); |
| 288 |
|
| 289 |
add_submenu_page('wdk', |
| 290 |
__('Documentation','wpdirectorykit'), |
| 291 |
__('Documentation','wpdirectorykit'), |
| 292 |
'manage_options', 'https://wpdirectorykit.com/documentation'); |
| 293 |
|
| 294 |
if(!file_exists(WPDIRECTORYKIT_PATH . 'premium_functions.php') || defined('WDK_FS_DISABLE')) |
| 295 |
{ |
| 296 |
|
| 297 |
if(!file_exists(WP_PLUGIN_DIR.'/wdk-currency-conversion') || !is_plugin_active( 'wdk-currency-conversion/wdk-currency-conversion.php' )) |
| 298 |
add_submenu_page('wdk', |
| 299 |
__('Currencies Addon','wpdirectorykit'), |
| 300 |
__('Currencies Addon','wpdirectorykit'), |
| 301 |
'manage_options', 'wdk_addons_currencies', array($this, 'admin_page_display')); |
| 302 |
|
| 303 |
if(!file_exists(WP_PLUGIN_DIR.'/wdk-membership') || !is_plugin_active( 'wdk-membership/wdk-membership.php' )) |
| 304 |
add_submenu_page('wdk', |
| 305 |
__('Membership Addon','wpdirectorykit'), |
| 306 |
__('Membership Addon','wpdirectorykit'), |
| 307 |
'manage_options', 'wdk_addons_membership', array($this, 'admin_page_display')); |
| 308 |
|
| 309 |
if(!file_exists(WP_PLUGIN_DIR.'/wdk-bookings') || !is_plugin_active( 'wdk-bookings/wdk-bookings.php' )) |
| 310 |
add_submenu_page('wdk', |
| 311 |
__('Booking Addon','wpdirectorykit'), |
| 312 |
__('Booking Addon','wpdirectorykit'), |
| 313 |
'manage_options', 'wdk_addons_bookings', array($this, 'admin_page_display')); |
| 314 |
|
| 315 |
add_submenu_page('wdk', |
| 316 |
__('More Addons','wpdirectorykit'), |
| 317 |
__('More Addons','wpdirectorykit'), |
| 318 |
'manage_options', 'wdk_addons', array($this, 'admin_page_display')); |
| 319 |
|
| 320 |
add_submenu_page('wdk', |
| 321 |
__('Support Forum','wpdirectorykit'), |
| 322 |
__('Support Forum','wpdirectorykit'), |
| 323 |
'manage_options', 'https://wordpress.org/support/plugin/wpdirectorykit/'); |
| 324 |
|
| 325 |
add_submenu_page('wdk', |
| 326 |
__('Contact','wpdirectorykit'), |
| 327 |
__('Contact','wpdirectorykit'), |
| 328 |
'manage_options', 'https://wpdirectorykit.com/contact.html'); |
| 329 |
} |
| 330 |
|
| 331 |
$current_theme = wp_get_theme(); |
| 332 |
|
| 333 |
if( defined( 'WP_DEBUG' ) && WP_DEBUG && $current_theme->get( 'AuthorURI' ) == 'https://wpdirectorykit.com') |
| 334 |
add_submenu_page('tools.php', |
| 335 |
esc_html__('WDK Demo Import', 'wpdirectorykit'), esc_html__('WDK Demo Import', 'wpdirectorykit'), 'manage_options', 'wdk_demo_import', array($this, 'admin_page_display')); |
| 336 |
|
| 337 |
|
| 338 |
} |
| 339 |
|
| 340 |
} |
| 341 |
|