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 +54 -24 3.0.13.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();
@@ -46,16 +53,42 @@
46 53 */
47 54 protected function add_hooks() {
48 55 add_action( 'admin_init', array( $this, 'lazy_add_hooks' ) );
49 56 add_action( 'admin_init', array( $this, 'register' ) );
57 + add_action( 'init', array( $this, 'listen_for_actions' ) );
50 58 add_action( 'admin_menu', array( $this, 'menu' ) );
51 59 add_action( 'admin_notices', array( $this, 'notices' ) );
52 60 add_action( 'save_post_boxzilla-box', array( $this, 'save_box_options' ), 20, 2 );
53 61 add_action( 'trashed_post', array( $this, 'flush_rules' ) );
54 62 add_action( 'untrashed_post', array( $this, 'flush_rules' ) );
63 +
64 + $this->review_notice->add_hooks();
55 65 }
56 66
57 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;
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;
88 + }
89 +
90 + /**
58 91 * All logic for admin notices lives here.
59 92 */
60 93 public function notices() {
61 94 global $pagenow,
@@ -101,15 +134,11 @@
101 134 add_action( 'admin_enqueue_scripts', array( $this, 'load_assets' ) );
102 135 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
103 136 add_filter( 'tiny_mce_before_init', array( $this, 'tinymce_init' ) );
104 137 add_filter( 'manage_edit-boxzilla-box_columns', array( $this, 'post_type_column_titles' ) );
105 - add_action( 'manage_boxzilla-box_posts_custom_column', array(
106 - $this,
107 - 'post_type_column_content'
108 - ), 10, 2 );
138 + add_action( 'manage_boxzilla-box_posts_custom_column', array( $this, 'post_type_column_content' ), 10, 2 );
109 139 add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
110 140
111 -
112 141 if ( $pagenow === 'plugins.php' ) {
113 142 add_filter( 'plugin_action_links', array( $this, 'add_plugin_settings_link' ), 10, 2 );
114 143 add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 );
115 144 }
@@ -126,10 +155,11 @@
126 155 * @param $column
127 156 * @param $post_id
128 157 */
129 158 public function post_type_column_content( $column, $post_id ) {
130 - if ( method_exists( $this, 'post_type_column_' . $column . '_content' ) ) {
131 - 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 );
132 162 }
133 163 }
134 164
135 165 /**
@@ -207,9 +237,9 @@
207 237 /**
208 238 * Shows the extensions page
209 239 */
210 240 public function show_extensions_page() {
211 - $extensions = $this->fetch_extensions();
241 + $extensions = $this->fetch_extensions();
212 242 require __DIR__ . '/views/extensions.php';
213 243 }
214 244
215 245 /**
@@ -263,9 +293,8 @@
263 293 return false;
264 294 }
265 295
266 296 if ( $screen->base === 'edit' && $screen->post_type === 'boxzilla-box' ) {
267 - // load stylesheets
268 297 wp_enqueue_style( 'boxzilla-admin' );
269 298 }
270 299
271 300 if ( $screen->base === 'post' && $screen->post_type === 'boxzilla-box' ) {
@@ -274,16 +303,16 @@
274 303
275 304 // load scripts
276 305 wp_enqueue_script( 'boxzilla-admin' );
277 306
278 - wp_localize_script( 'boxzilla-admin' ,'boxzilla_i18n', array(
279 - 'enterCommaSeparatedValues' => __( 'Enter a comma-separated list of values.', 'boxzilla' ),
280 - 'enterCommaSeparatedPosts' => __( "Enter a comma-separated list of post slugs or post ID's..", 'boxzilla' ),
281 - 'enterCommaSeparatedPages' => __( "Enter a comma-separated list of page slugs or page ID's..", 'boxzilla' ),
282 - 'enterCommaSeparatedPostTypes' => __( "Enter a comma-separated list of post types..", 'boxzilla' ),
283 - 'enterCommaSeparatedRelativeUrls' => __( "Enter a comma-separated list of relative URL's, eg /contact/", 'boxzilla' ),
284 - )
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' ),
285 313 );
314 + wp_localize_script( 'boxzilla-admin' ,'boxzilla_i18n', $data );
286 315
287 316 // load stylesheets
288 317 wp_enqueue_style( 'boxzilla-admin' );
289 318
@@ -291,9 +320,8 @@
291 320 do_action( 'boxzilla_load_admin_assets' );
292 321 }
293 322
294 323 if ( isset( $_GET['page'] ) && $_GET['page'] === 'boxzilla-settings' ) {
295 - // load stylesheets
296 324 wp_enqueue_style( 'boxzilla-admin' );
297 325 }
298 326
299 327 }
@@ -488,8 +516,9 @@
488 516 * @param array $rule
489 517 * @return array The sanitized rule array
490 518 */
491 519 public function sanitize_box_rule( $rule) {
520 +
492 521 $rule['value'] = trim( $rule['value'] );
493 522
494 523 // convert to array
495 524 $rule['value'] = explode( ',', trim( $rule['value'], ',' ) );
@@ -565,12 +594,14 @@
565 594 $opts = array_replace_recursive( $defaults, $opts );
566 595
567 596 $opts['rules'] = array_map( array( $this, 'sanitize_box_rule' ), $opts['rules'] );
568 597 $opts['css'] = $this->sanitize_box_css( $opts['css'] );
569 - $opts['cookie'] = absint( $opts['cookie'] );
598 + $opts['cookie']['triggered'] = absint( $opts['cookie']['triggered'] );
599 + $opts['cookie']['dismissed'] = absint( $opts['cookie']['dismissed'] );
570 600 $opts['trigger'] = sanitize_text_field( $opts['trigger'] );
571 601 $opts['trigger_percentage'] = absint( $opts['trigger_percentage'] );
572 602 $opts['trigger_element'] = sanitize_text_field( $opts['trigger_element'] );
603 + $opts['screen_size_condition']['value'] = intval( $opts['screen_size_condition']['value'] );
573 604
574 605 return $opts;
575 606 }
576 607
@@ -582,9 +613,9 @@
582 613 *
583 614 * @return array
584 615 */
585 616 public function add_plugin_settings_link( $links, $slug ) {
586 - if ( $slug !== $this->plugin->slug() ) {
617 + if ( $slug !== $this->plugin->slug() || ! is_array( $links ) ) {
587 618 return $links;
588 619 }
589 620
590 621 $settings_link = '<a href="' . admin_url( 'edit.php?post_type=boxzilla-box' ) . '">' . __( 'Boxes' ) . '</a>';
@@ -622,9 +653,9 @@
622 653 public function flush_rules( $post_id ) {
623 654
624 655 // only act on our own post type
625 656 $post = get_post( $post_id );
626 - if ( $post instanceof WP_Post && $post->post_type !== 'boxzilla-box' ) {
657 + if ( ! $post instanceof WP_Post || $post->post_type !== 'boxzilla-box' ) {
627 658 return;
628 659 }
629 660
630 661 // get all published boxes
@@ -662,14 +693,13 @@
662 693 *
663 694 * @return array
664 695 */
665 696 protected function fetch_extensions() {
666 -
697 +
667 698 $extensions = get_transient( 'boxzilla_remote_extensions' );
668 699 if ( $extensions ) {
669 700 return $extensions;
670 701 }
671 -
672 702 $request = wp_remote_get( 'https://api.boxzillaplugin.com/v1/plugins' );
673 703
674 704 if ( is_wp_error( $request ) ) {
675 705 return array();
@@ -678,9 +708,9 @@
678 708 $response = wp_remote_retrieve_body( $request );
679 709 $response = json_decode( $response );
680 710
681 711 if ( is_array( $response->data ) ) {
682 - set_transient( 'boxzilla_remote_extensions', $response->data, HOUR_IN_SECONDS );
712 + set_transient( 'boxzilla_remote_extensions', $response->data, 24 * HOUR_IN_SECONDS );
683 713
684 714 return $response->data;
685 715 }
686 716