| @@ -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 |
| @@ -47,16 +53,42 @@ | ||
| 47 | 53 | */ |
| 48 | 54 | protected function add_hooks() { |
| 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' ) ); |
| 63 | + | |
| 64 | + $this->review_notice->add_hooks(); | |
| 56 | 65 | } |
| 57 | 66 | |
| 58 | 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 | + /** | |
| 59 | 91 | * All logic for admin notices lives here. |
| 60 | 92 | */ |
| 61 | 93 | public function notices() { |
| 62 | 94 | global $pagenow, |
| @@ -102,15 +134,11 @@ | ||
| 102 | 134 | add_action( 'admin_enqueue_scripts', array( $this, 'load_assets' ) ); |
| 103 | 135 | add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); |
| 104 | 136 | add_filter( 'tiny_mce_before_init', array( $this, 'tinymce_init' ) ); |
| 105 | 137 | add_filter( 'manage_edit-boxzilla-box_columns', array( $this, 'post_type_column_titles' ) ); |
| 106 | - add_action( 'manage_boxzilla-box_posts_custom_column', array( | |
| 107 | - $this, | |
| 108 | - 'post_type_column_content' | |
| 109 | - ), 10, 2 ); | |
| 138 | + add_action( 'manage_boxzilla-box_posts_custom_column', array( $this, 'post_type_column_content' ), 10, 2 ); | |
| 110 | 139 | add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
| 111 | 140 | |
| 112 | - | |
| 113 | 141 | if ( $pagenow === 'plugins.php' ) { |
| 114 | 142 | add_filter( 'plugin_action_links', array( $this, 'add_plugin_settings_link' ), 10, 2 ); |
| 115 | 143 | add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 ); |
| 116 | 144 | } |
| @@ -127,10 +155,11 @@ | ||
| 127 | 155 | * @param $column |
| 128 | 156 | * @param $post_id |
| 129 | 157 | */ |
| 130 | 158 | public function post_type_column_content( $column, $post_id ) { |
| 131 | - if ( method_exists( $this, 'post_type_column_' . $column . '_content' ) ) { | |
| 132 | - 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 ); | |
| 133 | 162 | } |
| 134 | 163 | } |
| 135 | 164 | |
| 136 | 165 | /** |
| @@ -208,9 +237,9 @@ | ||
| 208 | 237 | /** |
| 209 | 238 | * Shows the extensions page |
| 210 | 239 | */ |
| 211 | 240 | public function show_extensions_page() { |
| 212 | - $extensions = $this->fetch_extensions(); | |
| 241 | + $extensions = $this->fetch_extensions(); | |
| 213 | 242 | require __DIR__ . '/views/extensions.php'; |
| 214 | 243 | } |
| 215 | 244 | |
| 216 | 245 | /** |
| @@ -264,9 +293,8 @@ | ||
| 264 | 293 | return false; |
| 265 | 294 | } |
| 266 | 295 | |
| 267 | 296 | if ( $screen->base === 'edit' && $screen->post_type === 'boxzilla-box' ) { |
| 268 | - // load stylesheets | |
| 269 | 297 | wp_enqueue_style( 'boxzilla-admin' ); |
| 270 | 298 | } |
| 271 | 299 | |
| 272 | 300 | if ( $screen->base === 'post' && $screen->post_type === 'boxzilla-box' ) { |
| @@ -275,16 +303,16 @@ | ||
| 275 | 303 | |
| 276 | 304 | // load scripts |
| 277 | 305 | wp_enqueue_script( 'boxzilla-admin' ); |
| 278 | 306 | |
| 279 | - wp_localize_script( 'boxzilla-admin' ,'boxzilla_i18n', array( | |
| 280 | - 'enterCommaSeparatedValues' => __( 'Enter a comma-separated list of values.', 'boxzilla' ), | |
| 281 | - 'enterCommaSeparatedPosts' => __( "Enter a comma-separated list of post slugs or post ID's..", 'boxzilla' ), | |
| 282 | - 'enterCommaSeparatedPages' => __( "Enter a comma-separated list of page slugs or page ID's..", 'boxzilla' ), | |
| 283 | - 'enterCommaSeparatedPostTypes' => __( "Enter a comma-separated list of post types..", 'boxzilla' ), | |
| 284 | - 'enterCommaSeparatedRelativeUrls' => __( "Enter a comma-separated list of relative URL's, eg /contact/", 'boxzilla' ), | |
| 285 | - ) | |
| 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' ), | |
| 286 | 313 | ); |
| 314 | + wp_localize_script( 'boxzilla-admin' ,'boxzilla_i18n', $data ); | |
| 287 | 315 | |
| 288 | 316 | // load stylesheets |
| 289 | 317 | wp_enqueue_style( 'boxzilla-admin' ); |
| 290 | 318 | |
| @@ -292,9 +320,8 @@ | ||
| 292 | 320 | do_action( 'boxzilla_load_admin_assets' ); |
| 293 | 321 | } |
| 294 | 322 | |
| 295 | 323 | if ( isset( $_GET['page'] ) && $_GET['page'] === 'boxzilla-settings' ) { |
| 296 | - // load stylesheets | |
| 297 | 324 | wp_enqueue_style( 'boxzilla-admin' ); |
| 298 | 325 | } |
| 299 | 326 | |
| 300 | 327 | } |
| @@ -481,9 +508,9 @@ | ||
| 481 | 508 | $url_string = parse_url( $url_string, PHP_URL_PATH ); |
| 482 | 509 | } |
| 483 | 510 | |
| 484 | 511 | // leading slash it |
| 485 | - return '/' . ltrim( $url_string, '/' ); | |
| 512 | + return $url_string; | |
| 486 | 513 | } |
| 487 | 514 | |
| 488 | 515 | /** |
| 489 | 516 | * @param array $rule |
| @@ -513,10 +540,8 @@ | ||
| 513 | 540 | if ( is_array( $rule['value'] ) ) { |
| 514 | 541 | $rule['value'] = join( ',', $rule['value'] ); |
| 515 | 542 | } |
| 516 | 543 | |
| 517 | - $rule['qualifier'] = isset( $rule['qualifier'] ) && ! $rule['qualifier'] ? 0 : 1; | |
| 518 | - | |
| 519 | 544 | return $rule; |
| 520 | 545 | } |
| 521 | 546 | |
| 522 | 547 | /** |
| @@ -572,8 +597,9 @@ | ||
| 572 | 597 | $opts['cookie']['dismissed'] = absint( $opts['cookie']['dismissed'] ); |
| 573 | 598 | $opts['trigger'] = sanitize_text_field( $opts['trigger'] ); |
| 574 | 599 | $opts['trigger_percentage'] = absint( $opts['trigger_percentage'] ); |
| 575 | 600 | $opts['trigger_element'] = sanitize_text_field( $opts['trigger_element'] ); |
| 601 | + $opts['screen_size_condition']['value'] = intval( $opts['screen_size_condition']['value'] ); | |
| 576 | 602 | |
| 577 | 603 | return $opts; |
| 578 | 604 | } |
| 579 | 605 | |
| @@ -585,9 +611,9 @@ | ||
| 585 | 611 | * |
| 586 | 612 | * @return array |
| 587 | 613 | */ |
| 588 | 614 | public function add_plugin_settings_link( $links, $slug ) { |
| 589 | - if ( $slug !== $this->plugin->slug() ) { | |
| 615 | + if ( $slug !== $this->plugin->slug() || ! is_array( $links ) ) { | |
| 590 | 616 | return $links; |
| 591 | 617 | } |
| 592 | 618 | |
| 593 | 619 | $settings_link = '<a href="' . admin_url( 'edit.php?post_type=boxzilla-box' ) . '">' . __( 'Boxes' ) . '</a>'; |
| @@ -625,9 +651,9 @@ | ||
| 625 | 651 | public function flush_rules( $post_id ) { |
| 626 | 652 | |
| 627 | 653 | // only act on our own post type |
| 628 | 654 | $post = get_post( $post_id ); |
| 629 | - if ( $post instanceof WP_Post && $post->post_type !== 'boxzilla-box' ) { | |
| 655 | + if ( ! $post instanceof WP_Post || $post->post_type !== 'boxzilla-box' ) { | |
| 630 | 656 | return; |
| 631 | 657 | } |
| 632 | 658 | |
| 633 | 659 | // get all published boxes |
| @@ -665,14 +691,13 @@ | ||
| 665 | 691 | * |
| 666 | 692 | * @return array |
| 667 | 693 | */ |
| 668 | 694 | protected function fetch_extensions() { |
| 669 | - | |
| 695 | + | |
| 670 | 696 | $extensions = get_transient( 'boxzilla_remote_extensions' ); |
| 671 | 697 | if ( $extensions ) { |
| 672 | 698 | return $extensions; |
| 673 | 699 | } |
| 674 | - | |
| 675 | 700 | $request = wp_remote_get( 'https://api.boxzillaplugin.com/v1/plugins' ); |
| 676 | 701 | |
| 677 | 702 | if ( is_wp_error( $request ) ) { |
| 678 | 703 | return array(); |
| @@ -681,9 +706,9 @@ | ||
| 681 | 706 | $response = wp_remote_retrieve_body( $request ); |
| 682 | 707 | $response = json_decode( $response ); |
| 683 | 708 | |
| 684 | 709 | if ( is_array( $response->data ) ) { |
| 685 | - set_transient( 'boxzilla_remote_extensions', $response->data, HOUR_IN_SECONDS ); | |
| 710 | + set_transient( 'boxzilla_remote_extensions', $response->data, 24 * HOUR_IN_SECONDS ); | |
| 686 | 711 | |
| 687 | 712 | return $response->data; |
| 688 | 713 | } |
| 689 | 714 | |