PluginProbe
Boxzilla – WordPress Popup Builder / 3.2
Boxzilla – WordPress Popup Builder v3.2
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
← All changes | src/admin/class-admin.php +75 -32 3.03.2 View file →
@@ -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 }
@@ -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'], ',' ) );
@@ -552,12 +594,14 @@
552 594 $opts = array_replace_recursive( $defaults, $opts );
553 595
554 596 $opts['rules'] = array_map( array( $this, 'sanitize_box_rule' ), $opts['rules'] );
555 597 $opts['css'] = $this->sanitize_box_css( $opts['css'] );
556 - $opts['cookie'] = absint( $opts['cookie'] );
598 + $opts['cookie']['triggered'] = absint( $opts['cookie']['triggered'] );
599 + $opts['cookie']['dismissed'] = absint( $opts['cookie']['dismissed'] );
557 600 $opts['trigger'] = sanitize_text_field( $opts['trigger'] );
558 601 $opts['trigger_percentage'] = absint( $opts['trigger_percentage'] );
559 602 $opts['trigger_element'] = sanitize_text_field( $opts['trigger_element'] );
603 + $opts['screen_size_condition']['value'] = intval( $opts['screen_size_condition']['value'] );
560 604
561 605 return $opts;
562 606 }
563 607
@@ -569,9 +613,9 @@
569 613 *
570 614 * @return array
571 615 */
572 616 public function add_plugin_settings_link( $links, $slug ) {
573 - if ( $slug !== $this->plugin->slug() ) {
617 + if ( $slug !== $this->plugin->slug() || ! is_array( $links ) ) {
574 618 return $links;
575 619 }
576 620
577 621 $settings_link = '<a href="' . admin_url( 'edit.php?post_type=boxzilla-box' ) . '">' . __( 'Boxes' ) . '</a>';
@@ -609,9 +653,9 @@
609 653 public function flush_rules( $post_id ) {
610 654
611 655 // only act on our own post type
612 656 $post = get_post( $post_id );
613 - if ( $post instanceof WP_Post && $post->post_type !== 'boxzilla-box' ) {
657 + if ( ! $post instanceof WP_Post || $post->post_type !== 'boxzilla-box' ) {
614 658 return;
615 659 }
616 660
617 661 // get all published boxes
@@ -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 }
@@ -649,14 +693,13 @@
649 693 *
650 694 * @return array
651 695 */
652 696 protected function fetch_extensions() {
653 -
697 +
654 698 $extensions = get_transient( 'boxzilla_remote_extensions' );
655 699 if ( $extensions ) {
656 700 return $extensions;
657 701 }
658 -
659 702 $request = wp_remote_get( 'https://api.boxzillaplugin.com/v1/plugins' );
660 703
661 704 if ( is_wp_error( $request ) ) {
662 705 return array();
@@ -665,9 +708,9 @@
665 708 $response = wp_remote_retrieve_body( $request );
666 709 $response = json_decode( $response );
667 710
668 711 if ( is_array( $response->data ) ) {
669 - set_transient( 'boxzilla_remote_extensions', $response->data, HOUR_IN_SECONDS );
712 + set_transient( 'boxzilla_remote_extensions', $response->data, 24 * HOUR_IN_SECONDS );
670 713
671 714 return $response->data;
672 715 }
673 716