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 +102 -71 3.4.63.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;
@@ -144,10 +124,8 @@
144 124 }
145 125
146 126 /**
147 127 * Checks current version against stored version & runs necessary update routines.
148 - *
149 - * @return bool
150 128 */
151 129 protected function run_migrations()
152 130 {
153 131
@@ -155,9 +133,9 @@
155 133 $previous_version = get_option('boxzilla_version', '0');
156 134 $current_version = $this->plugin->version();
157 135
158 136 if (version_compare($current_version, $previous_version, '<=')) {
159 - return false;
137 + return;
160 138 }
161 139
162 140 $upgrade_routines = new Migrations($previous_version, $current_version, __DIR__ . '/migrations');
163 141 $upgrade_routines->run();
@@ -185,9 +163,9 @@
185 163 * @param $post_id
186 164 */
187 165 public function post_type_column_box_id_content($post_id)
188 166 {
189 - echo $post_id;
167 + echo absint($post_id);
190 168 }
191 169
192 170 /**
193 171 * @param $column
@@ -220,11 +198,8 @@
220 198
221 199 return $columns;
222 200 }
223 201
224 - /**
225 - * Register stuffs
226 - */
227 202 public function register()
228 203 {
229 204
230 205 register_setting('boxzilla_settings', 'boxzilla_settings', [ $this, 'sanitize_settings' ]);
@@ -314,9 +289,9 @@
314 289 return false;
315 290 }
316 291
317 292 /**
318 - * @param $args
293 + * @param array $args
319 294 *
320 295 * @return mixed
321 296 */
322 297 public function tinymce_init($args)
@@ -380,15 +355,13 @@
380 355 /**
381 356 * Register meta boxes
382 357 *
383 358 * @param string $post_type
384 - *
385 - * @return bool
386 359 */
387 360 public function add_meta_boxes($post_type)
388 361 {
389 362 if ($post_type !== 'boxzilla-box') {
390 - return false;
363 + return;
391 364 }
392 365
393 366 add_meta_box(
394 367 'boxzilla-box-appearance-controls',
@@ -422,10 +395,8 @@
422 395 [ $this, 'metabox_our_other_plugins' ],
423 396 'boxzilla-box',
424 397 'side'
425 398 );
426 -
427 - return true;
428 399 }
429 400
430 401 /**
431 402 * @param \WP_Post $post
@@ -488,36 +459,35 @@
488 459 /**
489 460 * Saves box options and rules
490 461 *
491 462 * @param int $box_id
492 - *
493 - * @return bool
463 + * @param \WP_Post $post
494 464 */
495 465 public function save_box_options($box_id, $post)
496 466 {
497 -
498 467 // Only act on our own post type
499 468 if ($post->post_type !== 'boxzilla-box') {
500 - return false;
469 + return;
501 470 }
502 471
503 472 // is this a revision save?
504 473 if (wp_is_post_revision($box_id) || ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )) {
505 - return false;
474 + return;
506 475 }
507 476
508 477 // can user edit this post?
509 478 if (! current_user_can('edit_post', $box_id)) {
510 - return false;
479 + return;
511 480 }
512 481
482 + // phpcs:disable WordPress.Security.NonceVerification
513 483 // make sure options array is set
514 484 if (! isset($_POST['boxzilla_box']) || ! is_array($_POST['boxzilla_box'])) {
515 - return false;
485 + return;
516 486 }
517 487
518 488 // get new options from $_POST
519 - $opts = $this->sanitize_box_options($_POST['boxzilla_box']);
489 + $opts = $this->sanitize_box_options(wp_unslash($_POST['boxzilla_box']));
520 490
521 491 // allow extensions to filter the saved options
522 492 $opts = apply_filters('boxzilla_saved_options', $opts, $box_id);
523 493
@@ -525,19 +495,22 @@
525 495 update_post_meta($box_id, 'boxzilla_options', $opts);
526 496
527 497 // update global settings if given
528 498 if (! empty($_POST['boxzilla_global_settings'])) {
499 + $raw_global_settings = wp_unslash($_POST['boxzilla_global_settings']);
529 500 $global_settings = get_option('boxzilla_settings', []);
530 501 if (! is_array($global_settings)) {
531 502 $global_settings = [];
532 503 }
533 - $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 + }
534 507 update_option('boxzilla_settings', $global_settings);
535 508 }
536 509
537 510 $this->flush_rules($box_id);
538 511
539 - return true;
512 + // phpcs:enable WordPress.Security.NonceVerification
540 513 }
541 514
542 515 /**
543 516 * @param array $opts
@@ -545,8 +518,11 @@
545 518 * @return array
546 519 */
547 520 public function sanitize_settings($opts)
548 521 {
522 + if (isset($opts['test_mode'])) {
523 + $opts['test_mode'] = (int) $opts['test_mode'] ? 1 : 0;
524 + }
549 525 return $opts;
550 526 }
551 527
552 528 /**
@@ -555,9 +531,8 @@
555 531 * @return string
556 532 */
557 533 public function sanitize_url($url_string)
558 534 {
559 -
560 535 // if empty, just return a slash
561 536 if (empty($url_string)) {
562 537 return '/';
563 538 }
@@ -570,9 +545,8 @@
570 545 // get just the path
571 546 $url_string = parse_url($url_string, PHP_URL_PATH);
572 547 }
573 548
574 - // leading slash it
575 549 return $url_string;
576 550 }
577 551
578 552 /**
@@ -661,9 +635,9 @@
661 635 $opts['cookie']['dismissed'] = absint($opts['cookie']['dismissed']);
662 636 $opts['trigger'] = sanitize_text_field($opts['trigger']);
663 637 $opts['trigger_percentage'] = absint($opts['trigger_percentage']);
664 638 $opts['trigger_element'] = sanitize_text_field($opts['trigger_element']);
665 - $opts['screen_size_condition']['value'] = intval($opts['screen_size_condition']['value']);
639 + $opts['screen_size_condition']['value'] = (int) ($opts['screen_size_condition']['value']);
666 640
667 641 return $opts;
668 642 }
669 643
@@ -680,11 +654,9 @@
680 654 if ($slug !== $this->plugin->slug() || ! is_array($links)) {
681 655 return $links;
682 656 }
683 657
684 - $href = admin_url('edit.php?post_type=boxzilla-box');
685 - $label = esc_html__('Boxes', 'boxzilla');
686 - $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>';
687 659 array_unshift($links, $settings_link);
688 660 return $links;
689 661 }
690 662
@@ -743,8 +715,11 @@
743 715 if (is_array($boxes)) {
744 716 foreach ($boxes as $box) {
745 717 // get box meta data
746 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 + }
747 722
748 723 // add box rules to all rules
749 724 $rules[ $box->ID ] = (array) $box_meta['rules'];
750 725 $rules[ $box->ID ]['comparision'] = isset($box_meta['rules_comparision']) ? $box_meta['rules_comparision'] : 'any';
@@ -760,26 +735,82 @@
760 735 * @return array
761 736 */
762 737 protected function fetch_extensions()
763 738 {
764 - $extensions = get_transient('boxzilla_remote_extensions');
765 - if ($extensions) {
766 - return $extensions;
767 - }
768 -
769 - $response = wp_remote_get('https://my.boxzillaplugin.com/api/v2/plugins');
770 - if (is_wp_error($response) || wp_remote_retrieve_response_code($response) >= 400) {
771 - return [];
772 - }
773 -
774 - $body = wp_remote_retrieve_body($response);
775 - $data = json_decode($body);
776 - if (is_array($data)) {
777 - set_transient('boxzilla_remote_extensions', $data, 24 * HOUR_IN_SECONDS);
778 - return $data;
779 - }
780 -
781 - 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 + ];
782 813 }
783 814
784 815 /**
785 816 * @param $arr