| @@ -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; |
| @@ -183,9 +163,9 @@ | ||
| 183 | 163 | * @param $post_id |
| 184 | 164 | */ |
| 185 | 165 | public function post_type_column_box_id_content($post_id) |
| 186 | 166 | { |
| 187 | - echo $post_id; | |
| 167 | + echo absint($post_id); | |
| 188 | 168 | } |
| 189 | 169 | |
| 190 | 170 | /** |
| 191 | 171 | * @param $column |
| @@ -218,11 +198,8 @@ | ||
| 218 | 198 | |
| 219 | 199 | return $columns; |
| 220 | 200 | } |
| 221 | 201 | |
| 222 | - /** | |
| 223 | - * Register stuffs | |
| 224 | - */ | |
| 225 | 202 | public function register() |
| 226 | 203 | { |
| 227 | 204 | |
| 228 | 205 | register_setting('boxzilla_settings', 'boxzilla_settings', [ $this, 'sanitize_settings' ]); |
| @@ -312,9 +289,9 @@ | ||
| 312 | 289 | return false; |
| 313 | 290 | } |
| 314 | 291 | |
| 315 | 292 | /** |
| 316 | - * @param $args | |
| 293 | + * @param array $args | |
| 317 | 294 | * |
| 318 | 295 | * @return mixed |
| 319 | 296 | */ |
| 320 | 297 | public function tinymce_init($args) |
| @@ -501,8 +478,9 @@ | ||
| 501 | 478 | if (! current_user_can('edit_post', $box_id)) { |
| 502 | 479 | return; |
| 503 | 480 | } |
| 504 | 481 | |
| 482 | + // phpcs:disable WordPress.Security.NonceVerification | |
| 505 | 483 | // make sure options array is set |
| 506 | 484 | if (! isset($_POST['boxzilla_box']) || ! is_array($_POST['boxzilla_box'])) { |
| 507 | 485 | return; |
| 508 | 486 | } |
| @@ -507,9 +485,9 @@ | ||
| 507 | 485 | return; |
| 508 | 486 | } |
| 509 | 487 | |
| 510 | 488 | // get new options from $_POST |
| 511 | - $opts = $this->sanitize_box_options($_POST['boxzilla_box']); | |
| 489 | + $opts = $this->sanitize_box_options(wp_unslash($_POST['boxzilla_box'])); | |
| 512 | 490 | |
| 513 | 491 | // allow extensions to filter the saved options |
| 514 | 492 | $opts = apply_filters('boxzilla_saved_options', $opts, $box_id); |
| 515 | 493 | |
| @@ -517,9 +495,9 @@ | ||
| 517 | 495 | update_post_meta($box_id, 'boxzilla_options', $opts); |
| 518 | 496 | |
| 519 | 497 | // update global settings if given |
| 520 | 498 | if (! empty($_POST['boxzilla_global_settings'])) { |
| 521 | - $raw_global_settings = $_POST['boxzilla_global_settings']; | |
| 499 | + $raw_global_settings = wp_unslash($_POST['boxzilla_global_settings']); | |
| 522 | 500 | $global_settings = get_option('boxzilla_settings', []); |
| 523 | 501 | if (! is_array($global_settings)) { |
| 524 | 502 | $global_settings = []; |
| 525 | 503 | } |
| @@ -529,8 +507,10 @@ | ||
| 529 | 507 | update_option('boxzilla_settings', $global_settings); |
| 530 | 508 | } |
| 531 | 509 | |
| 532 | 510 | $this->flush_rules($box_id); |
| 511 | + | |
| 512 | + // phpcs:enable WordPress.Security.NonceVerification | |
| 533 | 513 | } |
| 534 | 514 | |
| 535 | 515 | /** |
| 536 | 516 | * @param array $opts |
| @@ -538,9 +518,11 @@ | ||
| 538 | 518 | * @return array |
| 539 | 519 | */ |
| 540 | 520 | public function sanitize_settings($opts) |
| 541 | 521 | { |
| 542 | - $opts['test_mode'] = (int) $opts['test_mode'] ? 1 : 0; | |
| 522 | + if (isset($opts['test_mode'])) { | |
| 523 | + $opts['test_mode'] = (int) $opts['test_mode'] ? 1 : 0; | |
| 524 | + } | |
| 543 | 525 | return $opts; |
| 544 | 526 | } |
| 545 | 527 | |
| 546 | 528 | /** |
| @@ -549,9 +531,8 @@ | ||
| 549 | 531 | * @return string |
| 550 | 532 | */ |
| 551 | 533 | public function sanitize_url($url_string) |
| 552 | 534 | { |
| 553 | - | |
| 554 | 535 | // if empty, just return a slash |
| 555 | 536 | if (empty($url_string)) { |
| 556 | 537 | return '/'; |
| 557 | 538 | } |
| @@ -564,9 +545,8 @@ | ||
| 564 | 545 | // get just the path |
| 565 | 546 | $url_string = parse_url($url_string, PHP_URL_PATH); |
| 566 | 547 | } |
| 567 | 548 | |
| 568 | - // leading slash it | |
| 569 | 549 | return $url_string; |
| 570 | 550 | } |
| 571 | 551 | |
| 572 | 552 | /** |
| @@ -655,9 +635,9 @@ | ||
| 655 | 635 | $opts['cookie']['dismissed'] = absint($opts['cookie']['dismissed']); |
| 656 | 636 | $opts['trigger'] = sanitize_text_field($opts['trigger']); |
| 657 | 637 | $opts['trigger_percentage'] = absint($opts['trigger_percentage']); |
| 658 | 638 | $opts['trigger_element'] = sanitize_text_field($opts['trigger_element']); |
| 659 | - $opts['screen_size_condition']['value'] = intval($opts['screen_size_condition']['value']); | |
| 639 | + $opts['screen_size_condition']['value'] = (int) ($opts['screen_size_condition']['value']); | |
| 660 | 640 | |
| 661 | 641 | return $opts; |
| 662 | 642 | } |
| 663 | 643 | |
| @@ -674,11 +654,9 @@ | ||
| 674 | 654 | if ($slug !== $this->plugin->slug() || ! is_array($links)) { |
| 675 | 655 | return $links; |
| 676 | 656 | } |
| 677 | 657 | |
| 678 | - $href = admin_url('edit.php?post_type=boxzilla-box'); | |
| 679 | - $label = esc_html__('Boxes', 'boxzilla'); | |
| 680 | - $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>'; | |
| 681 | 659 | array_unshift($links, $settings_link); |
| 682 | 660 | return $links; |
| 683 | 661 | } |
| 684 | 662 | |
| @@ -757,26 +735,82 @@ | ||
| 757 | 735 | * @return array |
| 758 | 736 | */ |
| 759 | 737 | protected function fetch_extensions() |
| 760 | 738 | { |
| 761 | - $extensions = get_transient('boxzilla_remote_extensions'); | |
| 762 | - if ($extensions) { | |
| 763 | - return $extensions; | |
| 764 | - } | |
| 765 | - | |
| 766 | - $response = wp_remote_get('https://my.boxzillaplugin.com/api/v2/plugins'); | |
| 767 | - if (is_wp_error($response) || wp_remote_retrieve_response_code($response) >= 400) { | |
| 768 | - return []; | |
| 769 | - } | |
| 770 | - | |
| 771 | - $body = wp_remote_retrieve_body($response); | |
| 772 | - $data = json_decode($body); | |
| 773 | - if (is_array($data)) { | |
| 774 | - set_transient('boxzilla_remote_extensions', $data, 24 * HOUR_IN_SECONDS); | |
| 775 | - return $data; | |
| 776 | - } | |
| 777 | - | |
| 778 | - 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 | + ]; | |
| 779 | 813 | } |
| 780 | 814 | |
| 781 | 815 | /** |
| 782 | 816 | * @param $arr |