PluginProbe
Stream – Activity Log & Audit Trail / 3.9.2
Stream – Activity Log & Audit Trail v3.9.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-alerts.php +59 -131 trunk3.9.2 View file →
@@ -19,28 +19,13 @@
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
37 27 /**
38 - * Capability required to access alerts.
39 - */
40 - const CAPABILITY = WP_STREAM_SETTINGS_CAPABILITY;
41 -
42 - /**
43 28 * Holds Instance of plugin object
44 29 *
45 30 * @var Plugin
46 31 */
@@ -143,8 +128,9 @@
143 128 ),
144 129 11,
145 130 2
146 131 );
132 +
147 133 }
148 134
149 135 /**
150 136 * Load alert_type classes
@@ -293,12 +279,8 @@
293 279 $alerts = new \WP_Query( $args );
294 280 foreach ( $alerts->posts as $alert ) {
295 281 $alert = $this->get_alert( $alert->ID );
296 282
297 - if ( false === $alert ) {
298 - continue;
299 - }
300 -
301 283 $status = $alert->check_record( $record_id, $recordarr );
302 284 if ( $status ) {
303 285 $alert->send_alert( $record_id, $recordarr ); // @todo send_alert expects int, not array.
304 286 }
@@ -304,8 +286,9 @@
304 286 }
305 287 }
306 288
307 289 return $recordarr;
290 +
308 291 }
309 292
310 293 /**
311 294 * Register scripts for page load
@@ -315,24 +298,35 @@
315 298 * @return void
316 299 */
317 300 public function register_scripts() {
318 301 $screen = get_current_screen();
319 - if ( 'edit-wp_stream_alerts' !== $screen->id ) {
320 - return;
302 + if ( 'edit-wp_stream_alerts' === $screen->id ) {
303 +
304 + $min = wp_stream_min_suffix();
305 +
306 + wp_register_script(
307 + 'wp-stream-alerts',
308 + $this->plugin->locations['url'] . 'ui/js/alerts.' . $min . 'js',
309 + array(
310 + 'wp-stream-select2',
311 + 'jquery',
312 + 'inline-edit-post',
313 + ),
314 + $this->plugin->get_version(),
315 + false
316 + );
317 +
318 + wp_localize_script(
319 + 'wp-stream-alerts',
320 + 'streamAlerts',
321 + array(
322 + 'any' => __( 'Any', 'stream' ),
323 + 'anyContext' => __( 'Any Context', 'stream' ),
324 + )
325 + );
326 + wp_enqueue_script( 'wp-stream-alerts' );
327 + wp_enqueue_style( 'wp-stream-select2' );
321 328 }
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 329 }
336 330
337 331 /**
338 332 * Register custom post type
@@ -363,22 +357,21 @@
363 357 'labels' => $labels,
364 358 'description' => __( 'Alerts for Stream.', 'stream' ),
365 359 'public' => false,
366 360 'publicly_queryable' => false,
367 - 'rewrite' => false,
368 361 'exclude_from_search' => true,
369 362 'show_ui' => true,
370 363 'show_in_menu' => false, // @see modify_admin_menu
371 364 'supports' => false,
372 365 'capabilities' => array(
373 - 'publish_posts' => self::CAPABILITY,
374 - 'edit_others_posts' => self::CAPABILITY,
375 - 'delete_posts' => self::CAPABILITY,
376 - 'delete_others_posts' => self::CAPABILITY,
377 - 'read_private_posts' => self::CAPABILITY,
378 - 'edit_post' => self::CAPABILITY,
379 - 'delete_post' => self::CAPABILITY,
380 - 'read_post' => self::CAPABILITY,
366 + 'publish_posts' => 'manage_options',
367 + 'edit_others_posts' => 'manage_options',
368 + 'delete_posts' => 'manage_options',
369 + 'delete_others_posts' => 'manage_options',
370 + 'read_private_posts' => 'manage_options',
371 + 'edit_post' => 'manage_options',
372 + 'delete_post' => 'manage_options',
373 + 'read_post' => 'manage_options',
381 374 ),
382 375 );
383 376
384 377 register_post_type( self::POST_TYPE, $args );
@@ -409,21 +402,20 @@
409 402
410 403 /**
411 404 * Return alert object of the given ID
412 405 *
413 - * @param string|int $post_id Post ID for the alert.
406 + * @param string $post_id Post ID for the alert.
414 407 *
415 408 * @return Alert
416 409 */
417 410 public function get_alert( $post_id = '' ) {
418 411 if ( ! $post_id ) {
419 - return new Alert( null, $this->plugin );
412 + $obj = new Alert( null, $this->plugin );
413 +
414 + return $obj;
420 415 }
421 416
422 417 $post = get_post( $post_id );
423 - if ( ! ( $post instanceof \WP_Post ) ) {
424 - return new Alert( null, $this->plugin );
425 - }
426 418
427 419 $alert_type = get_post_meta( $post_id, 'alert_type', true );
428 420 $alert_meta = get_post_meta( $post_id, 'alert_meta', true );
429 421
@@ -436,37 +428,9 @@
436 428 'alert_meta' => $alert_meta,
437 429 );
438 430
439 431 return new Alert( $obj, $this->plugin );
440 - }
441 432
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 433 }
470 434
471 435 /**
472 436 * Add custom post type to menu
@@ -479,9 +443,9 @@
479 443 add_submenu_page(
480 444 $this->plugin->admin->records_page_slug,
481 445 __( 'Alerts', 'stream' ),
482 446 __( 'Alerts', 'stream' ),
483 - self::CAPABILITY,
447 + 'manage_options',
484 448 'edit.php?post_type=wp_stream_alerts'
485 449 );
486 450 }
487 451
@@ -547,17 +511,14 @@
547 511 public function display_notification_box( $post = array() ) {
548 512 $alert = null;
549 513 $alert_type = 'none';
550 514 if ( is_object( $post ) ) {
551 - $alert = $this->get_alert( $post->ID );
552 - if ( false !== $alert ) {
553 - $alert_type = $alert->alert_type;
554 - }
515 + $alert = $this->get_alert( $post->ID );
516 + $alert_type = $alert->alert_type;
555 517 }
556 518 $form = new Form_Generator();
557 519
558 - echo '<label>' . esc_html__( 'Alert me by', 'stream' ) . '</label>';
559 - $form->render_field(
520 + $field_html = $form->render_field(
560 521 'select',
561 522 array(
562 523 'id' => 'wp_stream_alert_type',
563 524 'name' => 'wp_stream_alert_type',
@@ -567,8 +528,11 @@
567 528 'title' => 'Alert Type:',
568 529 )
569 530 );
570 531
532 + echo '<label>' . esc_html__( 'Alert me by', 'stream' ) . '</label>';
533 + echo $field_html; // Xss ok.
534 +
571 535 echo '<div id="wp_stream_alert_type_form">';
572 536 if ( is_object( $alert ) ) {
573 537 $alert->get_alert_type_obj()->display_fields( $alert );
574 538 } else {
@@ -585,20 +549,13 @@
585 549 *
586 550 * @return void
587 551 */
588 552 public function load_alerts_settings() {
589 - if ( ! current_user_can( self::CAPABILITY ) ) {
590 - wp_send_json_error(
591 - array(
592 - 'message' => 'You do not have permission to do this.',
593 - )
594 - );
595 - }
596 553 $alert = array();
597 554 $post_id = wp_stream_filter_input( INPUT_POST, 'post_id' );
598 - if ( ! empty( $post_id ) && 'new' !== $post_id ) {
555 + if ( ! empty( $post_id ) ) {
599 556 $alert = $this->get_alert( $post_id );
600 - if ( false === $alert ) {
557 + if ( ! $alert ) {
601 558 wp_send_json_error(
602 559 array(
603 560 'message' => 'Could not find alert.',
604 561 )
@@ -636,40 +593,19 @@
636 593 *
637 594 * @return void
638 595 */
639 596 public function display_triggers_box( $post = array() ) {
640 - $alert = false;
641 597 if ( is_object( $post ) ) {
642 598 $alert = $this->get_alert( $post->ID );
643 - }
644 - if ( false === $alert ) {
599 + } else {
645 600 $alert = array();
646 601 }
647 -
648 602 $form = new Form_Generator();
649 603 do_action( 'wp_stream_alert_trigger_form_display', $form, $alert );
650 604 // @TODO use human readable text.
651 605 echo '<label>' . esc_html__( 'Alert me when', 'stream' ) . '</label>';
652 - $form->render_fields();
606 + echo $form->render_fields(); // Xss ok.
653 607 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 608 }
673 609
674 610 /**
675 611 * Display Submit Box
@@ -722,9 +658,9 @@
722 658 ?>
723 659 </div>
724 660 <div id="publishing-action">
725 661 <span class="spinner"></span>
726 - <?php submit_button( __( 'Save', 'stream' ), 'primary button-large', 'publish', false ); ?>
662 + <?php submit_button( __( 'Save' ), 'primary button-large', 'publish', false ); ?>
727 663 </div>
728 664 <div class="clear"></div>
729 665 </div>
730 666 </div>
@@ -775,18 +711,8 @@
775 711 /**
776 712 * Update actions dropdown options based on the connector selected.
777 713 */
778 714 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 715 $connector_name = wp_stream_filter_input( INPUT_POST, 'connector' );
790 716 $stream_connectors = wp_stream_get_instance()->connectors;
791 717 if ( ! empty( $connector_name ) ) {
792 718 if ( isset( $stream_connectors->connectors[ $connector_name ] ) ) {
@@ -820,16 +746,18 @@
820 746 // This is a connector with a context such as posts-post.
821 747 $trigger_connector_and_context_split = explode( '-', $trigger_connector_and_context );
822 748 $trigger_connector = $trigger_connector_and_context_split[0];
823 749 $trigger_context = $trigger_connector_and_context_split[1];
824 - } elseif ( ! empty( $trigger_connector_and_context ) ) {
750 + } else {
751 + if ( ! empty( $trigger_connector_and_context ) ) {
825 752 // This is a parent connector with no dash such as posts.
826 753 $trigger_connector = $trigger_connector_and_context;
827 754 $trigger_context = '';
828 - } else {
829 - // There is no connector or context.
830 - $trigger_connector = '';
831 - $trigger_context = '';
755 + } else {
756 + // There is no connector or context.
757 + $trigger_connector = '';
758 + $trigger_context = '';
759 + }
832 760 }
833 761
834 762 $trigger_action = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_action' );
835 763 $alert_type = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_type' );