| @@ -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,9 +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' ) ); | |
| 50 | + add_action( 'wp_ajax_'.$this->plugin['prefix'].'_item_save', array( $this, 'item_save' ) ); | |
| 51 | 51 | |
| 52 | 52 | /*if ( get_option( 'wow_' . $this->plugin['prefix'] . '_notice_action' ) != 'read' ) { |
| 53 | 53 | add_action( 'admin_notices', array( $this, 'general_admin_notice' ) ); |
| 54 | 54 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_notice_assets' ) ); |
| @@ -238,12 +238,23 @@ | ||
| 238 | 238 | |
| 239 | 239 | // include tooltip script |
| 240 | 240 | wp_enqueue_script( 'jquery-ui-tooltip' ); |
| 241 | 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 | + | |
| 242 | 249 | // include the plugin admin script |
| 243 | 250 | $url_script = $url_assets . 'js/admin-script.min.js'; |
| 244 | 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' ) ) ); | |
| 245 | 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 ); | |
| 246 | 257 | |
| 247 | 258 | } |
| 248 | 259 | |
| 249 | 260 | /** |
| @@ -287,24 +298,22 @@ | ||
| 287 | 298 | return $footer_text; |
| 288 | 299 | } |
| 289 | 300 | } |
| 290 | 301 | |
| 291 | - function item_save() { | |
| 292 | - | |
| 293 | - $response = 'No'; | |
| 302 | + /* | |
| 303 | + * Check the post parameter from wow plugin | |
| 304 | + * | |
| 305 | + * @since 1.0 | |
| 306 | + */ | |
| 307 | + public function plugin_check() { | |
| 294 | 308 | if ( isset( $_POST[ $this->plugin['slug'] . '_nonce' ] ) ) { |
| 295 | 309 | if ( ! empty( $_POST ) |
| 296 | 310 | && wp_verify_nonce( $_POST[ $this->plugin['slug'] . '_nonce' ], $this->plugin['slug'] . '_action' ) |
| 297 | 311 | && current_user_can( 'manage_options' ) |
| 298 | 312 | ) { |
| 299 | - $response = self:: save_data(); | |
| 313 | + self:: save_data(); | |
| 300 | 314 | } |
| 301 | 315 | } |
| 302 | - | |
| 303 | - wp_send_json( $response ); | |
| 304 | - | |
| 305 | - wp_die(); | |
| 306 | - | |
| 307 | 316 | } |
| 308 | 317 | |
| 309 | 318 | /** |
| 310 | 319 | * Save and Update the Item into the plugin Database |
| @@ -341,6 +350,68 @@ | ||
| 341 | 350 | |
| 342 | 351 | return $response; |
| 343 | 352 | } |
| 344 | 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 | + } | |
| 345 | 416 | |
| 346 | 417 | } |