| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | * Admin Class |
| 5 | 5 | * |
| 6 | 6 | * @package Wow_Plugin |
| 7 | 7 | * @subpackage Admin |
| 8 | - * @author Dmytro Lobov <d@dayes.dev> | |
| 8 | + * @author Dmytro Lobov <i@wpbiker.com> | |
| 9 | 9 | * @copyright 2019 Wow-Company |
| 10 | 10 | * @license GNU Public License |
| 11 | 11 | * @version 1.0 |
| 12 | 12 | */ |
| @@ -46,11 +46,9 @@ | ||
| 46 | 46 | add_action( 'admin_menu', array( $this, 'add_admin_page' ) ); |
| 47 | 47 | add_filter( 'admin_footer_text', array( $this, 'rate_us' ) ); |
| 48 | 48 | // add_action( 'plugins_loaded', array( $this, 'plugin_check' ) ); |
| 49 | 49 | |
| 50 | - add_action( 'wp_ajax_' . $this->plugin['prefix'] . '_item_save', array( $this, 'item_save' ) ); | |
| 51 | - | |
| 52 | - add_action( 'admin_enqueue_scripts', array( $this, 'admin_style_script' ) ); // add admin script | |
| 50 | + add_action( 'wp_ajax_'.$this->plugin['prefix'].'_item_save', array( $this, 'item_save' ) ); | |
| 53 | 51 | |
| 54 | 52 | /*if ( get_option( 'wow_' . $this->plugin['prefix'] . '_notice_action' ) != 'read' ) { |
| 55 | 53 | add_action( 'admin_notices', array( $this, 'general_admin_notice' ) ); |
| 56 | 54 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_notice_assets' ) ); |
| @@ -202,9 +200,10 @@ | ||
| 202 | 200 | */ |
| 203 | 201 | public function plugin_page() { |
| 204 | 202 | global $wow_plugin_page; |
| 205 | 203 | $wow_plugin_page = $this->plugin['slug']; |
| 206 | - require_once 'partials/main.php'; | |
| 204 | + require_once 'partials/main.php'; | |
| 205 | + self:: admin_style_script(); | |
| 207 | 206 | } |
| 208 | 207 | |
| 209 | 208 | /** |
| 210 | 209 | * Include Styles and Scripts on the plugin admin page |
| @@ -210,28 +209,19 @@ | ||
| 210 | 209 | * Include Styles and Scripts on the plugin admin page |
| 211 | 210 | * |
| 212 | 211 | * @since 1.0 |
| 213 | 212 | */ |
| 214 | - public function admin_style_script($hook) { | |
| 215 | - | |
| 216 | - $page = 'wow-plugins_page_' . $this->plugin['slug']; | |
| 217 | - | |
| 218 | - if ( $page != $hook ) { | |
| 219 | - return false; | |
| 220 | - } | |
| 221 | - | |
| 222 | - | |
| 213 | + public function admin_style_script() { | |
| 223 | 214 | $slug = $this->plugin['slug']; |
| 224 | 215 | $version = $this->plugin['version']; |
| 225 | 216 | $url_assets = $this->plugin['url'] . 'assets/'; |
| 226 | - $pre_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 227 | 217 | |
| 228 | 218 | // include the main style |
| 229 | - wp_enqueue_style( $slug . '-admin', $url_assets . 'css/admin-style' . $pre_suffix . '.css', false, $version ); | |
| 219 | + wp_enqueue_style( $slug . '-admin', $url_assets . 'css/admin-style.min.css', false, $version ); | |
| 230 | 220 | |
| 231 | 221 | // include fontAwesome icon |
| 232 | - $url_fontawesome = $url_assets . 'vendors/fontawesome/css/fontawesome-all' . $pre_suffix . '.css'; | |
| 233 | - wp_enqueue_style( $slug . '-fontawesome', $url_fontawesome, null, '5.14' ); | |
| 222 | + $url_fontawesome = $url_assets . 'vendors/fontawesome/css/fontawesome-all.min.css'; | |
| 223 | + wp_enqueue_style( $slug . '-fontawesome', $url_fontawesome, null, '5.6.3' ); | |
| 234 | 224 | |
| 235 | 225 | // include fonticonpicker styles & scripts |
| 236 | 226 | $fonticonpicker_js = $url_assets . 'vendors/fonticonpicker/fonticonpicker.min.js'; |
| 237 | 227 | wp_enqueue_script( $slug . '-fonticonpicker', $fonticonpicker_js, array( 'jquery' ) ); |
| @@ -248,12 +238,23 @@ | ||
| 248 | 238 | |
| 249 | 239 | // include tooltip script |
| 250 | 240 | wp_enqueue_script( 'jquery-ui-tooltip' ); |
| 251 | 241 | |
| 242 | + // include sortable | |
| 243 | + //wp_enqueue_script( 'jquery-ui-sortable' ); | |
| 244 | + | |
| 245 | + // include an alpha rgba color picker | |
| 246 | + $url_alpha = $url_assets . 'js/wp-color-picker-alpha.min.js'; | |
| 247 | + // wp_enqueue_script( 'wp-color-picker-alpha', $url_alpha, array( 'wp-color-picker' ) ); | |
| 248 | + | |
| 252 | 249 | // include the plugin admin script |
| 253 | - $url_script = $url_assets . 'js/admin-script' . $pre_suffix . '.js'; | |
| 254 | - wp_enqueue_script( $slug . '-admin', $url_script, array( 'jquery' ), $version, true ); | |
| 250 | + $url_script = $url_assets . 'js/admin-script.min.js'; | |
| 251 | + wp_enqueue_script( $slug . '-admin', $url_script, array( 'jquery' ), $version ); | |
| 252 | +// wp_localize_script( $slug . '-admin', 'btg_count', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); | |
| 255 | 253 | |
| 254 | + // include the plugin preview script | |
| 255 | + $url_preview = $url_assets . 'js/preview.min.js'; | |
| 256 | +// wp_enqueue_script( $slug . '-preview', $url_preview, array( 'jquery' ), $version ); | |
| 256 | 257 | |
| 257 | 258 | } |
| 258 | 259 | |
| 259 | 260 | /** |
| @@ -297,24 +298,22 @@ | ||
| 297 | 298 | return $footer_text; |
| 298 | 299 | } |
| 299 | 300 | } |
| 300 | 301 | |
| 301 | - function item_save() { | |
| 302 | - | |
| 303 | - $response = 'No'; | |
| 302 | + /* | |
| 303 | + * Check the post parameter from wow plugin | |
| 304 | + * | |
| 305 | + * @since 1.0 | |
| 306 | + */ | |
| 307 | + public function plugin_check() { | |
| 304 | 308 | if ( isset( $_POST[ $this->plugin['slug'] . '_nonce' ] ) ) { |
| 305 | 309 | if ( ! empty( $_POST ) |
| 306 | 310 | && wp_verify_nonce( $_POST[ $this->plugin['slug'] . '_nonce' ], $this->plugin['slug'] . '_action' ) |
| 307 | 311 | && current_user_can( 'manage_options' ) |
| 308 | 312 | ) { |
| 309 | - $response = self:: save_data(); | |
| 313 | + self:: save_data(); | |
| 310 | 314 | } |
| 311 | 315 | } |
| 312 | - | |
| 313 | - wp_send_json( $response ); | |
| 314 | - | |
| 315 | - wp_die(); | |
| 316 | - | |
| 317 | 316 | } |
| 318 | 317 | |
| 319 | 318 | /** |
| 320 | 319 | * Save and Update the Item into the plugin Database |
| @@ -351,6 +350,68 @@ | ||
| 351 | 350 | |
| 352 | 351 | return $response; |
| 353 | 352 | } |
| 354 | 353 | |
| 354 | + function item_save() { | |
| 355 | + | |
| 356 | + $response = 'No'; | |
| 357 | + if ( isset( $_POST[ $this->plugin['slug'] . '_nonce' ] ) ) { | |
| 358 | + if ( ! empty( $_POST ) | |
| 359 | + && wp_verify_nonce( $_POST[ $this->plugin['slug'] . '_nonce' ], $this->plugin['slug'] . '_action' ) | |
| 360 | + && current_user_can( 'manage_options' ) | |
| 361 | + ) { | |
| 362 | + $response = self:: save_data(); | |
| 363 | + } | |
| 364 | + } | |
| 365 | + | |
| 366 | + wp_send_json( $response ); | |
| 367 | + | |
| 368 | + wp_die(); | |
| 369 | + | |
| 370 | + } | |
| 371 | + | |
| 372 | + /** | |
| 373 | + * Delete the files from plugin folder in 'uploads' | |
| 374 | + * | |
| 375 | + * @param integer $id id of the item | |
| 376 | + * | |
| 377 | + * @since 1.0 | |
| 378 | + */ | |
| 379 | + public function delete_file( $id = null ) { | |
| 380 | + $upload = wp_upload_dir(); | |
| 381 | + $basedir = $upload['basedir'] . '/' . $this->plugin['slug'] . '/'; | |
| 382 | + $file_style = $basedir . 'style-' . $id . '.css'; | |
| 383 | + $file_script = $basedir . 'script-' . $id . '.js'; | |
| 384 | + if ( file_exists( $file_style ) ) { | |
| 385 | + wp_delete_file( $file_style ); | |
| 386 | + } | |
| 387 | + if ( file_exists( $file_script ) ) { | |
| 388 | + wp_delete_file( $file_script ); | |
| 389 | + } | |
| 390 | + | |
| 391 | + return; | |
| 392 | + } | |
| 393 | + | |
| 394 | + /* | |
| 395 | + * Notice for updating the plugin | |
| 396 | + */ | |
| 397 | + | |
| 398 | + function general_admin_notice() { | |
| 399 | + echo '<div class="notice notice-warning wow-plugin-notice is-dismissible"> | |
| 400 | + <p><b>' . $this->plugin['name'] | |
| 401 | + . '</b>! In connection with the upgrade of Font Awesome to version 5, we ask you to edit and update all previously created menus. <a href="' | |
| 402 | + . admin_url() . 'admin.php?page=' . $this->plugin['slug'] . '">Go to the ' . $this->plugin['name'] . ' page</a></p> | |
| 403 | + </div>'; | |
| 404 | + | |
| 405 | + } | |
| 406 | + | |
| 407 | + function admin_notice_assets() { | |
| 408 | + wp_enqueue_script( 'wow-notice-update', $this->plugin['url'] . 'assets/js/notice-update.min.js', | |
| 409 | + array( 'jquery' ), '1.0', true ); | |
| 410 | + } | |
| 411 | + | |
| 412 | + function wow_notice_action_callback() { | |
| 413 | + update_option( 'wow_' . $this->plugin['prefix'] . '_notice_action', 'read' ); | |
| 414 | + wp_die(); | |
| 415 | + } | |
| 355 | 416 | |
| 356 | 417 | } |