| @@ -19,18 +19,8 @@ | ||
| 19 | 19 | */ |
| 20 | 20 | const POST_TYPE = 'wp_stream_alerts'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Enabled alert post status slug. | |
| 24 | - */ | |
| 25 | - const STATUS_ENABLED = 'wp_stream_enabled'; | |
| 26 | - | |
| 27 | - /** | |
| 28 | - * Disabled alert post status slug. | |
| 29 | - */ | |
| 30 | - const STATUS_DISABLED = 'wp_stream_disabled'; | |
| 31 | - | |
| 32 | - /** | |
| 33 | 23 | * Triggered Alerts meta key for Records |
| 34 | 24 | */ |
| 35 | 25 | const ALERTS_TRIGGERED_META_KEY = 'wp_stream_alerts_triggered'; |
| 36 | 26 | |
| @@ -36,9 +26,9 @@ | ||
| 36 | 26 | |
| 37 | 27 | /** |
| 38 | 28 | * Capability required to access alerts. |
| 39 | 29 | */ |
| 40 | - const CAPABILITY = WP_STREAM_SETTINGS_CAPABILITY; | |
| 30 | + const CAPABILITY = 'manage_options'; | |
| 41 | 31 | |
| 42 | 32 | /** |
| 43 | 33 | * Holds Instance of plugin object |
| 44 | 34 | * |
| @@ -315,24 +305,35 @@ | ||
| 315 | 305 | * @return void |
| 316 | 306 | */ |
| 317 | 307 | public function register_scripts() { |
| 318 | 308 | $screen = get_current_screen(); |
| 319 | - if ( 'edit-wp_stream_alerts' !== $screen->id ) { | |
| 320 | - return; | |
| 309 | + if ( 'edit-wp_stream_alerts' === $screen->id ) { | |
| 310 | + | |
| 311 | + $min = wp_stream_min_suffix(); | |
| 312 | + | |
| 313 | + wp_register_script( | |
| 314 | + 'wp-stream-alerts', | |
| 315 | + $this->plugin->locations['url'] . 'ui/js/alerts.' . $min . 'js', | |
| 316 | + array( | |
| 317 | + 'wp-stream-select2', | |
| 318 | + 'jquery', | |
| 319 | + 'inline-edit-post', | |
| 320 | + ), | |
| 321 | + $this->plugin->get_version(), | |
| 322 | + false | |
| 323 | + ); | |
| 324 | + | |
| 325 | + wp_localize_script( | |
| 326 | + 'wp-stream-alerts', | |
| 327 | + 'streamAlerts', | |
| 328 | + array( | |
| 329 | + 'any' => __( 'Any', 'stream' ), | |
| 330 | + 'anyContext' => __( 'Any Context', 'stream' ), | |
| 331 | + ) | |
| 332 | + ); | |
| 333 | + wp_enqueue_script( 'wp-stream-alerts' ); | |
| 334 | + wp_enqueue_style( 'wp-stream-select2' ); | |
| 321 | 335 | } |
| 322 | - | |
| 323 | - $this->plugin->enqueue_asset( | |
| 324 | - 'alerts', | |
| 325 | - array( | |
| 326 | - $this->plugin->with_select2(), | |
| 327 | - 'inline-edit-post', | |
| 328 | - ), | |
| 329 | - array( | |
| 330 | - 'any' => __( 'Any', 'stream' ), | |
| 331 | - 'anyContext' => __( 'Any Context', 'stream' ), | |
| 332 | - 'getActionsNonce' => wp_create_nonce( 'stream_get_actions' ), | |
| 333 | - ) | |
| 334 | - ); | |
| 335 | 336 | } |
| 336 | 337 | |
| 337 | 338 | /** |
| 338 | 339 | * Register custom post type |
| @@ -363,9 +364,8 @@ | ||
| 363 | 364 | 'labels' => $labels, |
| 364 | 365 | 'description' => __( 'Alerts for Stream.', 'stream' ), |
| 365 | 366 | 'public' => false, |
| 366 | 367 | 'publicly_queryable' => false, |
| 367 | - 'rewrite' => false, | |
| 368 | 368 | 'exclude_from_search' => true, |
| 369 | 369 | 'show_ui' => true, |
| 370 | 370 | 'show_in_menu' => false, // @see modify_admin_menu |
| 371 | 371 | 'supports' => false, |
| @@ -439,37 +439,8 @@ | ||
| 439 | 439 | return new Alert( $obj, $this->plugin ); |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
| 443 | - * Return a list of alerts, optionally filtered by post status. | |
| 444 | - * | |
| 445 | - * @param array $statuses Optional list of alert post statuses to include. | |
| 446 | - * Defaults to enabled + disabled. | |
| 447 | - * | |
| 448 | - * @return Alert[] | |
| 449 | - */ | |
| 450 | - public function get_alerts( array $statuses = array() ) { | |
| 451 | - if ( empty( $statuses ) ) { | |
| 452 | - $statuses = array( self::STATUS_ENABLED, self::STATUS_DISABLED ); | |
| 453 | - } | |
| 454 | - | |
| 455 | - $posts = get_posts( | |
| 456 | - array( | |
| 457 | - 'post_type' => self::POST_TYPE, | |
| 458 | - 'post_status' => $statuses, | |
| 459 | - 'posts_per_page' => -1, // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page | |
| 460 | - ) | |
| 461 | - ); | |
| 462 | - | |
| 463 | - $alerts = array(); | |
| 464 | - foreach ( $posts as $post ) { | |
| 465 | - $alerts[] = $this->get_alert( $post->ID ); | |
| 466 | - } | |
| 467 | - | |
| 468 | - return $alerts; | |
| 469 | - } | |
| 470 | - | |
| 471 | - /** | |
| 472 | 443 | * Add custom post type to menu |
| 473 | 444 | * |
| 474 | 445 | * @action admin_menu |
| 475 | 446 | * |
| @@ -650,26 +621,8 @@ | ||
| 650 | 621 | // @TODO use human readable text. |
| 651 | 622 | echo '<label>' . esc_html__( 'Alert me when', 'stream' ) . '</label>'; |
| 652 | 623 | $form->render_fields(); |
| 653 | 624 | wp_nonce_field( 'save_alert', 'wp_stream_alerts_nonce' ); |
| 654 | - | |
| 655 | - if ( $post instanceof \WP_Post ) : | |
| 656 | - /** | |
| 657 | - * These fields are required for the post to be saved, as the Admin AJAX inline_save action is fired. | |
| 658 | - * | |
| 659 | - * @see get_inline_data() | |
| 660 | - * @see wp_ajax_inline_save() | |
| 661 | - */ | |
| 662 | - ?> | |
| 663 | - <input type="hidden" name="_status" value="<?php echo esc_attr( get_post_status( $post->ID ) ); ?>" /> | |
| 664 | - <input type="hidden" name="jj" value="<?php echo esc_attr( mysql2date( 'd', $post->post_date, false ) ); ?>" /> | |
| 665 | - <input type="hidden" name="mm" value="<?php echo esc_attr( mysql2date( 'm', $post->post_date, false ) ); ?>" /> | |
| 666 | - <input type="hidden" name="aa" value="<?php echo esc_attr( mysql2date( 'Y', $post->post_date, false ) ); ?>" /> | |
| 667 | - <input type="hidden" name="hh" value="<?php echo esc_attr( mysql2date( 'H', $post->post_date, false ) ); ?>" /> | |
| 668 | - <input type="hidden" name="mn" value="<?php echo esc_attr( mysql2date( 'i', $post->post_date, false ) ); ?>" /> | |
| 669 | - <input type="hidden" name="ss" value="<?php echo esc_attr( mysql2date( 's', $post->post_date, false ) ); ?>" /> | |
| 670 | - <?php | |
| 671 | - endif; | |
| 672 | 625 | } |
| 673 | 626 | |
| 674 | 627 | /** |
| 675 | 628 | * Display Submit Box |
| @@ -722,9 +675,9 @@ | ||
| 722 | 675 | ?> |
| 723 | 676 | </div> |
| 724 | 677 | <div id="publishing-action"> |
| 725 | 678 | <span class="spinner"></span> |
| 726 | - <?php submit_button( __( 'Save', 'stream' ), 'primary button-large', 'publish', false ); ?> | |
| 679 | + <?php submit_button( __( 'Save' ), 'primary button-large', 'publish', false ); ?> | |
| 727 | 680 | </div> |
| 728 | 681 | <div class="clear"></div> |
| 729 | 682 | </div> |
| 730 | 683 | </div> |
| @@ -775,18 +728,8 @@ | ||
| 775 | 728 | /** |
| 776 | 729 | * Update actions dropdown options based on the connector selected. |
| 777 | 730 | */ |
| 778 | 731 | public function get_actions() { |
| 779 | - if ( ! current_user_can( self::CAPABILITY ) ) { | |
| 780 | - wp_send_json_error( | |
| 781 | - array( | |
| 782 | - 'message' => 'You do not have permission to do this.', | |
| 783 | - ) | |
| 784 | - ); | |
| 785 | - } | |
| 786 | - | |
| 787 | - check_ajax_referer( 'stream_get_actions', 'nonce' ); | |
| 788 | - | |
| 789 | 732 | $connector_name = wp_stream_filter_input( INPUT_POST, 'connector' ); |
| 790 | 733 | $stream_connectors = wp_stream_get_instance()->connectors; |
| 791 | 734 | if ( ! empty( $connector_name ) ) { |
| 792 | 735 | if ( isset( $stream_connectors->connectors[ $connector_name ] ) ) { |