PluginProbe
Boxzilla – WordPress Popup Builder / 3.4.11
Boxzilla – WordPress Popup Builder v3.4.11
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 +105 -73 3.4.33.4.11 View file →
@@ -7,8 +7,12 @@
7 7 use Boxzilla\Boxzilla;
8 8 use WP_Post;
9 9 use WP_Screen;
10 10
11 +if (! defined('ABSPATH')) {
12 + exit;
13 +}
14 +
11 15 class Admin
12 16 {
13 17 /**
14 18 * @var Plugin $plugin
@@ -52,9 +56,8 @@
52 56 protected function add_hooks()
53 57 {
54 58 add_action('admin_init', [ $this, 'lazy_add_hooks' ]);
55 59 add_action('admin_init', [ $this, 'register' ]);
56 - add_action('init', [ $this, 'listen_for_actions' ]);
57 60 add_action('admin_menu', [ $this, 'menu' ]);
58 61 add_action('admin_notices', [ $this, 'notices' ]);
59 62 add_action('save_post_boxzilla-box', [ $this, 'save_box_options' ], 20, 2);
60 63 add_action('trashed_post', [ $this, 'flush_rules' ]);
@@ -62,31 +65,8 @@
62 65 add_filter('bulk_actions-edit-boxzilla-box', [ $this, 'bulk_action_add' ]);
63 66 add_filter('handle_bulk_actions-edit-boxzilla-box', [ $this, 'bulk_action_handle' ], 10, 3);
64 67 }
65 68
66 - /**
67 - * Listen for admin actions.
68 - */
69 - public function listen_for_actions()
70 - {
71 - // triggered?
72 - $vars = array_merge($_POST, $_GET);
73 - if (empty($vars['_boxzilla_admin_action'])) {
74 - return false;
75 - }
76 -
77 - // authorized?
78 - if (! current_user_can('edit_posts')) {
79 - return false;
80 - }
81 -
82 - // fire action
83 - $action = $vars['_boxzilla_admin_action'];
84 - do_action('boxzilla_admin_' . $action);
85 -
86 - return true;
87 - }
88 -
89 69 public function bulk_action_add($bulk_actions)
90 70 {
91 71 $bulk_actions['boxzilla_duplicate_box'] = esc_attr__('Duplicate box', 'boxzilla');
92 72 return $bulk_actions;
@@ -129,9 +109,10 @@
129 109 {
130 110 global $pagenow,
131 111 $current_screen;
132 112
133 - if (( $pagenow === 'plugins.php' || ( $current_screen && $current_screen->post_type === 'boxzilla-box' ) )
113 + if (
114 + ( $pagenow === 'plugins.php' || ( $current_screen && $current_screen->post_type === 'boxzilla-box' ) )
134 115 && current_user_can('install_plugins')
135 116 && is_plugin_active('scroll-triggered-boxes/index.php')
136 117 ) {
137 118 ?>
@@ -143,10 +124,8 @@
143 124 }
144 125
145 126 /**
146 127 * Checks current version against stored version & runs necessary update routines.
147 - *
148 - * @return bool
149 128 */
150 129 protected function run_migrations()
151 130 {
152 131
@@ -154,9 +133,9 @@
154 133 $previous_version = get_option('boxzilla_version', '0');
155 134 $current_version = $this->plugin->version();
156 135
157 136 if (version_compare($current_version, $previous_version, '<=')) {
158 - return false;
137 + return;
159 138 }
160 139
161 140 $upgrade_routines = new Migrations($previous_version, $current_version, __DIR__ . '/migrations');
162 141 $upgrade_routines->run();
@@ -184,9 +163,9 @@
184 163 * @param $post_id
185 164 */
186 165 public function post_type_column_box_id_content($post_id)
187 166 {
188 - echo $post_id;
167 + echo absint($post_id);
189 168 }
190 169
191 170 /**
192 171 * @param $column
@@ -219,11 +198,8 @@
219 198
220 199 return $columns;
221 200 }
222 201
223 - /**
224 - * Register stuffs
225 - */
226 202 public function register()
227 203 {
228 204
229 205 register_setting('boxzilla_settings', 'boxzilla_settings', [ $this, 'sanitize_settings' ]);
@@ -313,9 +289,9 @@
313 289 return false;
314 290 }
315 291
316 292 /**
317 - * @param $args
293 + * @param array $args
318 294 *
319 295 * @return mixed
320 296 */
321 297 public function tinymce_init($args)
@@ -379,15 +355,13 @@
379 355 /**
380 356 * Register meta boxes
381 357 *
382 358 * @param string $post_type
383 - *
384 - * @return bool
385 359 */
386 360 public function add_meta_boxes($post_type)
387 361 {
388 362 if ($post_type !== 'boxzilla-box') {
389 - return false;
363 + return;
390 364 }
391 365
392 366 add_meta_box(
393 367 'boxzilla-box-appearance-controls',
@@ -421,10 +395,8 @@
421 395 [ $this, 'metabox_our_other_plugins' ],
422 396 'boxzilla-box',
423 397 'side'
424 398 );
425 -
426 - return true;
427 399 }
428 400
429 401 /**
430 402 * @param \WP_Post $post
@@ -487,36 +459,35 @@
487 459 /**
488 460 * Saves box options and rules
489 461 *
490 462 * @param int $box_id
491 - *
492 - * @return bool
463 + * @param \WP_Post $post
493 464 */
494 465 public function save_box_options($box_id, $post)
495 466 {
496 -
497 467 // Only act on our own post type
498 468 if ($post->post_type !== 'boxzilla-box') {
499 - return false;
469 + return;
500 470 }
501 471
502 472 // is this a revision save?
503 473 if (wp_is_post_revision($box_id) || ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )) {
504 - return false;
474 + return;
505 475 }
506 476
507 477 // can user edit this post?
508 478 if (! current_user_can('edit_post', $box_id)) {
509 - return false;
479 + return;
510 480 }
511 481
482 + // phpcs:disable WordPress.Security.NonceVerification
512 483 // make sure options array is set
513 484 if (! isset($_POST['boxzilla_box']) || ! is_array($_POST['boxzilla_box'])) {
514 - return false;
485 + return;
515 486 }
516 487
517 488 // get new options from $_POST
518 - $opts = $this->sanitize_box_options($_POST['boxzilla_box']);
489 + $opts = $this->sanitize_box_options(wp_unslash($_POST['boxzilla_box']));
519 490
520 491 // allow extensions to filter the saved options
521 492 $opts = apply_filters('boxzilla_saved_options', $opts, $box_id);
522 493
@@ -524,19 +495,22 @@
524 495 update_post_meta($box_id, 'boxzilla_options', $opts);
525 496
526 497 // update global settings if given
527 498 if (! empty($_POST['boxzilla_global_settings'])) {
499 + $raw_global_settings = wp_unslash($_POST['boxzilla_global_settings']);
528 500 $global_settings = get_option('boxzilla_settings', []);
529 501 if (! is_array($global_settings)) {
530 502 $global_settings = [];
531 503 }
532 - $global_settings = array_merge($global_settings, $_POST['boxzilla_global_settings']);
504 + if (isset($raw_global_settings['test_mode'])) {
505 + $global_settings['test_mode'] = absint($raw_global_settings['test_mode']);
506 + }
533 507 update_option('boxzilla_settings', $global_settings);
534 508 }
535 509
536 510 $this->flush_rules($box_id);
537 511
538 - return true;
512 + // phpcs:enable WordPress.Security.NonceVerification
539 513 }
540 514
541 515 /**
542 516 * @param array $opts
@@ -544,8 +518,11 @@
544 518 * @return array
545 519 */
546 520 public function sanitize_settings($opts)
547 521 {
522 + if (isset($opts['test_mode'])) {
523 + $opts['test_mode'] = (int) $opts['test_mode'] ? 1 : 0;
524 + }
548 525 return $opts;
549 526 }
550 527
551 528 /**
@@ -554,9 +531,8 @@
554 531 * @return string
555 532 */
556 533 public function sanitize_url($url_string)
557 534 {
558 -
559 535 // if empty, just return a slash
560 536 if (empty($url_string)) {
561 537 return '/';
562 538 }
@@ -569,9 +545,8 @@
569 545 // get just the path
570 546 $url_string = parse_url($url_string, PHP_URL_PATH);
571 547 }
572 548
573 - // leading slash it
574 549 return $url_string;
575 550 }
576 551
577 552 /**
@@ -660,9 +635,9 @@
660 635 $opts['cookie']['dismissed'] = absint($opts['cookie']['dismissed']);
661 636 $opts['trigger'] = sanitize_text_field($opts['trigger']);
662 637 $opts['trigger_percentage'] = absint($opts['trigger_percentage']);
663 638 $opts['trigger_element'] = sanitize_text_field($opts['trigger_element']);
664 - $opts['screen_size_condition']['value'] = intval($opts['screen_size_condition']['value']);
639 + $opts['screen_size_condition']['value'] = (int) ($opts['screen_size_condition']['value']);
665 640
666 641 return $opts;
667 642 }
668 643
@@ -679,11 +654,9 @@
679 654 if ($slug !== $this->plugin->slug() || ! is_array($links)) {
680 655 return $links;
681 656 }
682 657
683 - $href = admin_url('edit.php?post_type=boxzilla-box');
684 - $label = esc_html__('Boxes', 'boxzilla');
685 - $settings_link = "<a href=\"{$href}\">{$label}</a>";
658 + $settings_link = '<a href="' . esc_url(admin_url('edit.php?post_type=boxzilla-box')) . '">' . esc_html__('Boxes', 'boxzilla') . '</a>';
686 659 array_unshift($links, $settings_link);
687 660 return $links;
688 661 }
689 662
@@ -700,9 +673,9 @@
700 673 if ($slug !== $this->plugin->slug()) {
701 674 return $links;
702 675 }
703 676
704 - $links[] = '<a href="https://kb.boxzillaplugin.com/">Documentation</a>';
677 + $links[] = '<a href="https://boxzillaplugin.com/kb/">Documentation</a>';
705 678 $links[] = '<a href="https://boxzillaplugin.com/add-ons/">Add-ons</a>';
706 679
707 680 return $links;
708 681 }
@@ -742,8 +715,11 @@
742 715 if (is_array($boxes)) {
743 716 foreach ($boxes as $box) {
744 717 // get box meta data
745 718 $box_meta = get_post_meta($box->ID, 'boxzilla_options', true);
719 + if (! $box_meta || ! is_array($box_meta) || empty($box_meta['rules'])) {
720 + continue;
721 + }
746 722
747 723 // add box rules to all rules
748 724 $rules[ $box->ID ] = (array) $box_meta['rules'];
749 725 $rules[ $box->ID ]['comparision'] = isset($box_meta['rules_comparision']) ? $box_meta['rules_comparision'] : 'any';
@@ -759,26 +735,82 @@
759 735 * @return array
760 736 */
761 737 protected function fetch_extensions()
762 738 {
763 - $extensions = get_transient('boxzilla_remote_extensions');
764 - if ($extensions) {
765 - return $extensions;
766 - }
767 -
768 - $response = wp_remote_get('https://my.boxzillaplugin.com/api/v2/plugins');
769 - if (is_wp_error($response) || wp_remote_retrieve_response_code($response) >= 400) {
770 - return [];
771 - }
772 -
773 - $body = wp_remote_retrieve_body($response);
774 - $data = json_decode($body);
775 - if (is_array($data)) {
776 - set_transient('boxzilla_remote_extensions', $data, 24 * HOUR_IN_SECONDS);
777 - return $data;
778 - }
779 -
780 - return [];
739 + return [
740 + 0 =>
741 + (object) [
742 + 'name' => 'Theme Pack',
743 + 'description' => 'A beautiful set of eye-catching themes for your boxes',
744 + 'url' => 'https://boxzillaplugin.com/add-ons/theme-pack',
745 + 'image_url' => plugins_url("assets/img/theme-pack.png", BOXZILLA_FILE),
746 + 'page_url' => 'https://boxzillaplugin.com/add-ons/theme-pack',
747 + ],
748 + 1 =>
749 + (object) [
750 + 'name' => 'MailChimp',
751 + 'description' => 'Hide boxes for MailChimp subscribers.',
752 + 'url' => 'https://boxzillaplugin.com/add-ons/mailchimp',
753 + 'image_url' => plugins_url("assets/img/mailchimp.png", BOXZILLA_FILE),
754 + 'page_url' => 'https://boxzillaplugin.com/add-ons/mailchimp',
755 + ],
756 + 2 =>
757 + (object) [
758 + 'name' => 'Google Analytics',
759 + 'description' => 'Track box events in Google Analytics.',
760 + 'url' => 'https://boxzillaplugin.com/add-ons/google-analytics',
761 + 'image_url' => plugins_url("assets/img/google-analytics.png", BOXZILLA_FILE),
762 + 'page_url' => 'https://boxzillaplugin.com/add-ons/google-analytics',
763 + ],
764 + 3 =>
765 + (object) [
766 + 'name' => 'Exit Intent',
767 + 'description' => 'Trigger a box when a visitor intents to leave your webpage.',
768 + 'url' => 'https://boxzillaplugin.com/add-ons/exit-intent',
769 + 'image_url' => plugins_url("assets/img/exit-intent.png", BOXZILLA_FILE),
770 + 'page_url' => 'https://boxzillaplugin.com/add-ons/exit-intent',
771 + ],
772 + 4 =>
773 + (object) [
774 + 'name' => 'Time on Site',
775 + 'description' => 'Trigger a box after a visitor spent an amount of time on your site.',
776 + 'url' => 'https://boxzillaplugin.com/add-ons/time-on-site',
777 + 'image_url' => plugins_url("assets/img/time-on-site.png", BOXZILLA_FILE),
778 + 'page_url' => 'https://boxzillaplugin.com/add-ons/time-on-site',
779 + ],
780 + 5 =>
781 + (object) [
782 + 'name' => 'Pageviews',
783 + 'description' => 'Allows you to trigger a box after a certain number of pageviews.',
784 + 'url' => 'https://boxzillaplugin.com/add-ons/pageviews',
785 + 'image_url' => plugins_url("assets/img/pageviews.png", BOXZILLA_FILE),
786 + 'page_url' => 'https://boxzillaplugin.com/add-ons/pageviews',
787 + ],
788 + 6 =>
789 + (object) [
790 + 'name' => 'WooCommerce',
791 + 'description' => 'Offers advanced integration with WooCommerce.',
792 + 'url' => 'https://boxzillaplugin.com/add-ons/woocommerce',
793 + 'image_url' => plugins_url("assets/img/woocommerce.png", BOXZILLA_FILE),
794 + 'page_url' => 'https://boxzillaplugin.com/add-ons/woocommerce',
795 + ],
796 + 7 =>
797 + (object) [
798 + 'name' => 'Stats',
799 + 'description' => 'Measure how well your boxes are performing with simple statistics.',
800 + 'url' => 'https://boxzillaplugin.com/add-ons/stats',
801 + 'image_url' => plugins_url("assets/img/stats.png", BOXZILLA_FILE),
802 + 'page_url' => 'https://boxzillaplugin.com/add-ons/stats',
803 + ],
804 + 8 =>
805 + (object) [
806 + 'name' => 'Date Range',
807 + 'description' => 'Only load a box when date is within a certain range of one or two dates.',
808 + 'url' => 'https://boxzillaplugin.com/add-ons/date-range/',
809 + 'image_url' => plugins_url("assets/img/date-range.png", BOXZILLA_FILE),
810 + 'page_url' => 'https://boxzillaplugin.com/add-ons/date-range/',
811 + ],
812 + ];
781 813 }
782 814
783 815 /**
784 816 * @param $arr