| @@ -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 | } |
| @@ -475,8 +517,9 @@ | ||
| 475 | 517 | * @param array $rule |
| 476 | 518 | * @return array The sanitized rule array |
| 477 | 519 | */ |
| 478 | 520 | public function sanitize_box_rule( $rule) { |
| 521 | + | |
| 479 | 522 | $rule['value'] = trim( $rule['value'] ); |
| 480 | 523 | |
| 481 | 524 | // convert to array |
| 482 | 525 | $rule['value'] = explode( ',', trim( $rule['value'], ',' ) ); |
| @@ -552,9 +595,10 @@ | ||
| 552 | 595 | $opts = array_replace_recursive( $defaults, $opts ); |
| 553 | 596 | |
| 554 | 597 | $opts['rules'] = array_map( array( $this, 'sanitize_box_rule' ), $opts['rules'] ); |
| 555 | 598 | $opts['css'] = $this->sanitize_box_css( $opts['css'] ); |
| 556 | - $opts['cookie'] = absint( $opts['cookie'] ); | |
| 599 | + $opts['cookie']['triggered'] = absint( $opts['cookie']['triggered'] ); | |
| 600 | + $opts['cookie']['dismissed'] = absint( $opts['cookie']['dismissed'] ); | |
| 557 | 601 | $opts['trigger'] = sanitize_text_field( $opts['trigger'] ); |
| 558 | 602 | $opts['trigger_percentage'] = absint( $opts['trigger_percentage'] ); |
| 559 | 603 | $opts['trigger_element'] = sanitize_text_field( $opts['trigger_element'] ); |
| 560 | 604 | |
| @@ -634,9 +678,9 @@ | ||
| 634 | 678 | $box_meta = get_post_meta( $box->ID, 'boxzilla_options', true ); |
| 635 | 679 | |
| 636 | 680 | // add box rules to all rules |
| 637 | 681 | $rules[ $box->ID ] = $box_meta['rules']; |
| 638 | - $rules[ $box->ID ]['comparision'] = $box_meta['rules_comparision']; | |
| 682 | + $rules[ $box->ID ]['comparision'] = isset( $box_meta['rules_comparision'] ) ? $box_meta['rules_comparision'] : 'any'; | |
| 639 | 683 | |
| 640 | 684 | } |
| 641 | 685 | |
| 642 | 686 | } |