| @@ -20,8 +20,13 @@ | ||
| 20 | 20 | */ |
| 21 | 21 | protected $boxzilla; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | + * @var ReviewNotice | |
| 25 | + */ | |
| 26 | + protected $review_notice; | |
| 27 | + | |
| 28 | + /** | |
| 24 | 29 | * @param Plugin $plugin |
| 25 | 30 | * @param Boxzilla $boxzilla |
| 26 | 31 | */ |
| 27 | 32 | public function __construct( Plugin $plugin, Boxzilla $boxzilla ) { |
| @@ -26,8 +31,9 @@ | ||
| 26 | 31 | */ |
| 27 | 32 | public function __construct( Plugin $plugin, Boxzilla $boxzilla ) { |
| 28 | 33 | $this->plugin = $plugin; |
| 29 | 34 | $this->boxzilla = $boxzilla; |
| 35 | + $this->review_notice = new ReviewNotice(); | |
| 30 | 36 | } |
| 31 | 37 | |
| 32 | 38 | /** |
| 33 | 39 | * Initialise the all admin related stuff |
| @@ -32,10 +38,11 @@ | ||
| 32 | 38 | /** |
| 33 | 39 | * Initialise the all admin related stuff |
| 34 | 40 | */ |
| 35 | 41 | public function init() { |
| 42 | + | |
| 36 | 43 | // Load the plugin textdomain |
| 37 | - load_plugin_textdomain( 'boxzilla', null, $this->plugin->dir() . '/languages' ); | |
| 44 | + load_plugin_textdomain( 'boxzilla', null, basename( $this->plugin->dir() ) . '/languages' ); | |
| 38 | 45 | |
| 39 | 46 | // action hooks |
| 40 | 47 | $this->add_hooks(); |
| 41 | 48 | $this->run_migrations(); |
| @@ -44,26 +51,65 @@ | ||
| 44 | 51 | /** |
| 45 | 52 | * Add necessary hooks |
| 46 | 53 | */ |
| 47 | 54 | protected function add_hooks() { |
| 48 | - | |
| 49 | 55 | add_action( 'admin_init', array( $this, 'lazy_add_hooks' ) ); |
| 50 | 56 | add_action( 'admin_init', array( $this, 'register' ) ); |
| 57 | + add_action( 'init', array( $this, 'listen_for_actions' ) ); | |
| 51 | 58 | add_action( 'admin_menu', array( $this, 'menu' ) ); |
| 52 | - | |
| 59 | + add_action( 'admin_notices', array( $this, 'notices' ) ); | |
| 53 | 60 | add_action( 'save_post_boxzilla-box', array( $this, 'save_box_options' ), 20, 2 ); |
| 54 | 61 | add_action( 'trashed_post', array( $this, 'flush_rules' ) ); |
| 55 | 62 | add_action( 'untrashed_post', array( $this, 'flush_rules' ) ); |
| 56 | 63 | |
| 57 | - // if a premium add-on is installed, instantiate dependencies | |
| 58 | - if ( count( $this->boxzilla['plugins'] ) > 0 ) { | |
| 59 | - $this->boxzilla['license_manager']->add_hooks(); | |
| 60 | - $this->boxzilla['update_manager']->add_hooks(); | |
| 61 | - $this->boxzilla['api_authenticator']->add_hooks(); | |
| 64 | + $this->review_notice->add_hooks(); | |
| 65 | + } | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * Listen for admin actions. | |
| 69 | + */ | |
| 70 | + public function listen_for_actions() { | |
| 71 | + | |
| 72 | + // triggered? | |
| 73 | + $vars = array_merge( $_POST, $_GET ); | |
| 74 | + if( empty( $vars['_boxzilla_admin_action'] ) ) { | |
| 75 | + return false; | |
| 62 | 76 | } |
| 77 | + | |
| 78 | + // authorized? | |
| 79 | + if( ! current_user_can( 'edit_posts' ) ) { | |
| 80 | + return false; | |
| 81 | + } | |
| 82 | + | |
| 83 | + // fire action | |
| 84 | + $action = $vars['_boxzilla_admin_action']; | |
| 85 | + do_action( 'boxzilla_admin_' . $action ); | |
| 86 | + | |
| 87 | + return true; | |
| 63 | 88 | } |
| 64 | 89 | |
| 65 | 90 | /** |
| 91 | + * All logic for admin notices lives here. | |
| 92 | + */ | |
| 93 | + public function notices() { | |
| 94 | + global $pagenow, | |
| 95 | + $current_screen; | |
| 96 | + | |
| 97 | + if( ( $pagenow === 'plugins.php' || ( $current_screen && $current_screen->post_type === 'boxzilla-box' ) ) | |
| 98 | + && current_user_can( 'install_plugins' ) | |
| 99 | + && is_plugin_active( 'scroll-triggered-boxes/index.php' ) ) { | |
| 100 | + | |
| 101 | + $url = wp_nonce_url( 'plugins.php?action=deactivate&plugin=scroll-triggered-boxes/index.php', 'deactivate-plugin_' . 'scroll-triggered-boxes/index.php' ); | |
| 102 | + ?> | |
| 103 | + <div class="notice notice-info"> | |
| 104 | + <p><?php printf( __( 'Awesome, you are using Boxzilla! You can now safely <a href="%s">deactivate the Scroll Triggered Boxes plugin</a>.', 'boxzilla' ), $url ); ?></p> | |
| 105 | + </div> | |
| 106 | + <?php | |
| 107 | + } | |
| 108 | + | |
| 109 | + } | |
| 110 | + | |
| 111 | + /** | |
| 66 | 112 | * Checks current version against stored version & runs necessary update routines. |
| 67 | 113 | * |
| 68 | 114 | * @return bool |
| 69 | 115 | */ |
| @@ -88,15 +134,11 @@ | ||
| 88 | 134 | add_action( 'admin_enqueue_scripts', array( $this, 'load_assets' ) ); |
| 89 | 135 | add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
| 90 | 136 | add_filter( 'tiny_mce_before_init', array( $this, 'tinymce_init' ) ); |
| 91 | 137 | add_filter( 'manage_edit-boxzilla-box_columns', array( $this, 'post_type_column_titles' ) ); |
| 92 | - add_action( 'manage_boxzilla-box_posts_custom_column', array( | |
| 93 | - $this, | |
| 94 | - 'post_type_column_content' | |
| 95 | - ), 10, 2 ); | |
| 138 | + add_action( 'manage_boxzilla-box_posts_custom_column', array( $this, 'post_type_column_content' ), 10, 2 ); | |
| 96 | 139 | add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
| 97 | 140 | |
| 98 | - | |
| 99 | 141 | if ( $pagenow === 'plugins.php' ) { |
| 100 | 142 | add_filter( 'plugin_action_links', array( $this, 'add_plugin_settings_link' ), 10, 2 ); |
| 101 | 143 | add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 ); |
| 102 | 144 | } |
| @@ -113,10 +155,11 @@ | ||
| 113 | 155 | * @param $column |
| 114 | 156 | * @param $post_id |
| 115 | 157 | */ |
| 116 | 158 | public function post_type_column_content( $column, $post_id ) { |
| 117 | - if ( method_exists( $this, 'post_type_column_' . $column . '_content' ) ) { | |
| 118 | - call_user_func( array( $this, 'post_type_column_' . $column . '_content' ), $post_id ); | |
| 159 | + $method_name = 'post_type_column_' . $column . '_content'; | |
| 160 | + if ( method_exists( $this, $method_name ) ) { | |
| 161 | + call_user_func( array( $this, $method_name ), $post_id ); | |
| 119 | 162 | } |
| 120 | 163 | } |
| 121 | 164 | |
| 122 | 165 | /** |
| @@ -194,9 +237,9 @@ | ||
| 194 | 237 | /** |
| 195 | 238 | * Shows the extensions page |
| 196 | 239 | */ |
| 197 | 240 | public function show_extensions_page() { |
| 198 | - $extensions = $this->fetch_extensions(); | |
| 241 | + $extensions = $this->fetch_extensions(); | |
| 199 | 242 | require __DIR__ . '/views/extensions.php'; |
| 200 | 243 | } |
| 201 | 244 | |
| 202 | 245 | /** |
| @@ -250,9 +293,8 @@ | ||
| 250 | 293 | return false; |
| 251 | 294 | } |
| 252 | 295 | |
| 253 | 296 | if ( $screen->base === 'edit' && $screen->post_type === 'boxzilla-box' ) { |
| 254 | - // load stylesheets | |
| 255 | 297 | wp_enqueue_style( 'boxzilla-admin' ); |
| 256 | 298 | } |
| 257 | 299 | |
| 258 | 300 | if ( $screen->base === 'post' && $screen->post_type === 'boxzilla-box' ) { |
| @@ -261,16 +303,16 @@ | ||
| 261 | 303 | |
| 262 | 304 | // load scripts |
| 263 | 305 | wp_enqueue_script( 'boxzilla-admin' ); |
| 264 | 306 | |
| 265 | - wp_localize_script( 'boxzilla-admin' ,'boxzilla_i18n', array( | |
| 266 | - 'enterCommaSeparatedValues' => __( 'Enter a comma-separated list of values.', 'boxzilla' ), | |
| 267 | - 'enterCommaSeparatedPosts' => __( "Enter a comma-separated list of post slugs or post ID's..", 'boxzilla' ), | |
| 268 | - 'enterCommaSeparatedPages' => __( "Enter a comma-separated list of page slugs or page ID's..", 'boxzilla' ), | |
| 269 | - 'enterCommaSeparatedPostTypes' => __( "Enter a comma-separated list of post types..", 'boxzilla' ), | |
| 270 | - 'enterCommaSeparatedRelativeUrls' => __( "Enter a comma-separated list of relative URL's, eg /contact/", 'boxzilla' ), | |
| 271 | - ) | |
| 307 | + $data = array( | |
| 308 | + 'enterCommaSeparatedValues' => __( 'Enter a comma-separated list of values.', 'boxzilla' ), | |
| 309 | + 'enterCommaSeparatedPosts' => __( "Enter a comma-separated list of post slugs or post ID's..", 'boxzilla' ), | |
| 310 | + 'enterCommaSeparatedPages' => __( "Enter a comma-separated list of page slugs or page ID's..", 'boxzilla' ), | |
| 311 | + 'enterCommaSeparatedPostTypes' => __( "Enter a comma-separated list of post types..", 'boxzilla' ), | |
| 312 | + 'enterCommaSeparatedRelativeUrls' => __( "Enter a comma-separated list of relative URL's, eg /contact/", 'boxzilla' ), | |
| 272 | 313 | ); |
| 314 | + wp_localize_script( 'boxzilla-admin' ,'boxzilla_i18n', $data ); | |
| 273 | 315 | |
| 274 | 316 | // load stylesheets |
| 275 | 317 | wp_enqueue_style( 'boxzilla-admin' ); |
| 276 | 318 | |
| @@ -278,9 +320,8 @@ | ||
| 278 | 320 | do_action( 'boxzilla_load_admin_assets' ); |
| 279 | 321 | } |
| 280 | 322 | |
| 281 | 323 | if ( isset( $_GET['page'] ) && $_GET['page'] === 'boxzilla-settings' ) { |
| 282 | - // load stylesheets | |
| 283 | 324 | wp_enqueue_style( 'boxzilla-admin' ); |
| 284 | 325 | } |
| 285 | 326 | |
| 286 | 327 | } |
| @@ -467,9 +508,9 @@ | ||
| 467 | 508 | $url_string = parse_url( $url_string, PHP_URL_PATH ); |
| 468 | 509 | } |
| 469 | 510 | |
| 470 | 511 | // leading slash it |
| 471 | - return '/' . ltrim( $url_string, '/' ); | |
| 512 | + return $url_string; | |
| 472 | 513 | } |
| 473 | 514 | |
| 474 | 515 | /** |
| 475 | 516 | * @param array $rule |
| @@ -475,8 +516,9 @@ | ||
| 475 | 516 | * @param array $rule |
| 476 | 517 | * @return array The sanitized rule array |
| 477 | 518 | */ |
| 478 | 519 | public function sanitize_box_rule( $rule) { |
| 520 | + | |
| 479 | 521 | $rule['value'] = trim( $rule['value'] ); |
| 480 | 522 | |
| 481 | 523 | // convert to array |
| 482 | 524 | $rule['value'] = explode( ',', trim( $rule['value'], ',' ) ); |
| @@ -498,10 +540,8 @@ | ||
| 498 | 540 | if ( is_array( $rule['value'] ) ) { |
| 499 | 541 | $rule['value'] = join( ',', $rule['value'] ); |
| 500 | 542 | } |
| 501 | 543 | |
| 502 | - $rule['qualifier'] = isset( $rule['qualifier'] ) && ! $rule['qualifier'] ? 0 : 1; | |
| 503 | - | |
| 504 | 544 | return $rule; |
| 505 | 545 | } |
| 506 | 546 | |
| 507 | 547 | /** |
| @@ -552,12 +592,14 @@ | ||
| 552 | 592 | $opts = array_replace_recursive( $defaults, $opts ); |
| 553 | 593 | |
| 554 | 594 | $opts['rules'] = array_map( array( $this, 'sanitize_box_rule' ), $opts['rules'] ); |
| 555 | 595 | $opts['css'] = $this->sanitize_box_css( $opts['css'] ); |
| 556 | - $opts['cookie'] = absint( $opts['cookie'] ); | |
| 596 | + $opts['cookie']['triggered'] = absint( $opts['cookie']['triggered'] ); | |
| 597 | + $opts['cookie']['dismissed'] = absint( $opts['cookie']['dismissed'] ); | |
| 557 | 598 | $opts['trigger'] = sanitize_text_field( $opts['trigger'] ); |
| 558 | 599 | $opts['trigger_percentage'] = absint( $opts['trigger_percentage'] ); |
| 559 | 600 | $opts['trigger_element'] = sanitize_text_field( $opts['trigger_element'] ); |
| 601 | + $opts['screen_size_condition']['value'] = intval( $opts['screen_size_condition']['value'] ); | |
| 560 | 602 | |
| 561 | 603 | return $opts; |
| 562 | 604 | } |
| 563 | 605 | |
| @@ -569,9 +611,9 @@ | ||
| 569 | 611 | * |
| 570 | 612 | * @return array |
| 571 | 613 | */ |
| 572 | 614 | public function add_plugin_settings_link( $links, $slug ) { |
| 573 | - if ( $slug !== $this->plugin->slug() ) { | |
| 615 | + if ( $slug !== $this->plugin->slug() || ! is_array( $links ) ) { | |
| 574 | 616 | return $links; |
| 575 | 617 | } |
| 576 | 618 | |
| 577 | 619 | $settings_link = '<a href="' . admin_url( 'edit.php?post_type=boxzilla-box' ) . '">' . __( 'Boxes' ) . '</a>'; |
| @@ -609,9 +651,9 @@ | ||
| 609 | 651 | public function flush_rules( $post_id ) { |
| 610 | 652 | |
| 611 | 653 | // only act on our own post type |
| 612 | 654 | $post = get_post( $post_id ); |
| 613 | - if ( $post instanceof WP_Post && $post->post_type !== 'boxzilla-box' ) { | |
| 655 | + if ( ! $post instanceof WP_Post || $post->post_type !== 'boxzilla-box' ) { | |
| 614 | 656 | return; |
| 615 | 657 | } |
| 616 | 658 | |
| 617 | 659 | // get all published boxes |
| @@ -634,9 +676,9 @@ | ||
| 634 | 676 | $box_meta = get_post_meta( $box->ID, 'boxzilla_options', true ); |
| 635 | 677 | |
| 636 | 678 | // add box rules to all rules |
| 637 | 679 | $rules[ $box->ID ] = $box_meta['rules']; |
| 638 | - $rules[ $box->ID ]['comparision'] = $box_meta['rules_comparision']; | |
| 680 | + $rules[ $box->ID ]['comparision'] = isset( $box_meta['rules_comparision'] ) ? $box_meta['rules_comparision'] : 'any'; | |
| 639 | 681 | |
| 640 | 682 | } |
| 641 | 683 | |
| 642 | 684 | } |
| @@ -649,14 +691,13 @@ | ||
| 649 | 691 | * |
| 650 | 692 | * @return array |
| 651 | 693 | */ |
| 652 | 694 | protected function fetch_extensions() { |
| 653 | - | |
| 695 | + | |
| 654 | 696 | $extensions = get_transient( 'boxzilla_remote_extensions' ); |
| 655 | 697 | if ( $extensions ) { |
| 656 | 698 | return $extensions; |
| 657 | 699 | } |
| 658 | - | |
| 659 | 700 | $request = wp_remote_get( 'https://api.boxzillaplugin.com/v1/plugins' ); |
| 660 | 701 | |
| 661 | 702 | if ( is_wp_error( $request ) ) { |
| 662 | 703 | return array(); |
| @@ -665,9 +706,9 @@ | ||
| 665 | 706 | $response = wp_remote_retrieve_body( $request ); |
| 666 | 707 | $response = json_decode( $response ); |
| 667 | 708 | |
| 668 | 709 | if ( is_array( $response->data ) ) { |
| 669 | - set_transient( 'boxzilla_remote_extensions', $response->data, HOUR_IN_SECONDS ); | |
| 710 | + set_transient( 'boxzilla_remote_extensions', $response->data, 24 * HOUR_IN_SECONDS ); | |
| 670 | 711 | |
| 671 | 712 | return $response->data; |
| 672 | 713 | } |
| 673 | 714 | |