PluginProbe
Stream – Activity Log & Audit Trail / 3.4.2
Stream – Activity Log & Audit Trail v3.4.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 +167 -92 3.2.23.4.2 View file →
@@ -12,8 +12,9 @@
12 12 *
13 13 * @package WP_Stream
14 14 */
15 15 class Alerts {
16 +
16 17 /**
17 18 * Alerts post type slug
18 19 */
19 20 const POST_TYPE = 'wp_stream_alerts';
@@ -65,26 +66,70 @@
65 66 // Add custom post type to menu.
66 67 add_action( 'wp_stream_admin_menu', array( $this, 'register_menu' ) );
67 68
68 69 // Add scripts to post screens.
69 - add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
70 + add_action(
71 + 'admin_enqueue_scripts',
72 + array(
73 + $this,
74 + 'register_scripts',
75 + )
76 + );
70 77
71 - add_action( 'network_admin_menu', array( $this, 'change_menu_link_url' ), 99 );
78 + add_action(
79 + 'network_admin_menu',
80 + array(
81 + $this,
82 + 'change_menu_link_url',
83 + ),
84 + 99
85 + );
72 86
73 - add_filter( 'wp_stream_record_inserted', array( $this, 'check_records' ), 10, 2 );
87 + add_filter(
88 + 'wp_stream_record_inserted',
89 + array(
90 + $this,
91 + 'check_records',
92 + ),
93 + 10,
94 + 2
95 + );
74 96
75 - add_action( 'wp_ajax_load_alerts_settings', array( $this, 'load_alerts_settings' ) );
97 + add_action(
98 + 'wp_ajax_load_alerts_settings',
99 + array(
100 + $this,
101 + 'load_alerts_settings',
102 + )
103 + );
76 104 add_action( 'wp_ajax_get_actions', array( $this, 'get_actions' ) );
77 - add_action( 'wp_ajax_save_new_alert', array( $this, 'save_new_alert' ) );
78 - add_action( 'wp_ajax_get_new_alert_triggers_notifications', array(
79 - $this,
80 - 'get_new_alert_triggers_notifications',
81 - ) );
105 + add_action(
106 + 'wp_ajax_save_new_alert',
107 + array(
108 + $this,
109 + 'save_new_alert',
110 + )
111 + );
112 + add_action(
113 + 'wp_ajax_get_new_alert_triggers_notifications',
114 + array(
115 + $this,
116 + 'get_new_alert_triggers_notifications',
117 + )
118 + );
82 119
83 120 $this->load_alert_types();
84 121 $this->load_alert_triggers();
85 122
86 - add_filter( 'wp_stream_action_links_posts', array( $this, 'change_alert_action_links' ), 11, 2 );
123 + add_filter(
124 + 'wp_stream_action_links_posts',
125 + array(
126 + $this,
127 + 'change_alert_action_links',
128 + ),
129 + 11,
130 + 2
131 + );
87 132
88 133 }
89 134
90 135 /**
@@ -91,14 +136,15 @@
91 136 * Load alert_type classes
92 137 *
93 138 * @return void
94 139 */
95 - function load_alert_types() {
140 + public function load_alert_types() {
96 141 $alert_types = array(
97 142 'none',
98 143 'highlight',
99 144 'email',
100 145 'ifttt',
146 + 'slack',
101 147 );
102 148
103 149 $classes = array();
104 150 foreach ( $alert_types as $alert_type ) {
@@ -127,14 +173,8 @@
127 173 // Ensure that all alert_types extend Notifier.
128 174 foreach ( $this->alert_types as $key => $alert_type ) {
129 175 if ( ! $this->is_valid_alert_type( $alert_type ) ) {
130 176 unset( $this->alert_types[ $key ] );
131 - trigger_error(
132 - sprintf(
133 - esc_html__( 'Registered alert_type %s does not extend WP_Stream\Alert_Type.', 'stream' ),
134 - esc_html( get_class( $alert_type ) )
135 - )
136 - );
137 177 }
138 178 }
139 179 }
140 180
@@ -142,9 +182,9 @@
142 182 * Load alert_type classes
143 183 *
144 184 * @return void
145 185 */
146 - function load_alert_triggers() {
186 + public function load_alert_triggers() {
147 187 $alert_triggers = array(
148 188 'author',
149 189 'context',
150 190 'action',
@@ -177,14 +217,8 @@
177 217 // Ensure that all alert_triggers extend Notifier.
178 218 foreach ( $this->alert_triggers as $key => $alert_trigger ) {
179 219 if ( ! $this->is_valid_alert_trigger( $alert_trigger ) ) {
180 220 unset( $this->alert_triggers[ $key ] );
181 - trigger_error(
182 - sprintf(
183 - esc_html__( 'Registered alert_trigger %s does not extend WP_Stream\Alert_Trigger.', 'stream' ),
184 - esc_html( get_class( $alert_trigger ) )
185 - )
186 - );
187 221 }
188 222 }
189 223 }
190 224
@@ -235,9 +269,9 @@
235 269 * @param array $recordarr Record data.
236 270 *
237 271 * @return array
238 272 */
239 - function check_records( $record_id, $recordarr ) {
273 + public function check_records( $record_id, $recordarr ) {
240 274 $args = array(
241 275 'post_type' => self::POST_TYPE,
242 276 'post_status' => 'wp_stream_enabled',
243 277 );
@@ -262,18 +296,30 @@
262 296 * @action admin_enqueue_scripts
263 297 *
264 298 * @return void
265 299 */
266 - function register_scripts() {
300 + public function register_scripts() {
267 301 $screen = get_current_screen();
268 302 if ( 'edit-wp_stream_alerts' === $screen->id ) {
269 - wp_register_script( 'wp-stream-alerts', $this->plugin->locations['url'] . 'ui/js/alerts.js', array(
270 - 'wp-stream-select2',
271 - 'jquery',
272 - 'inline-edit-post',
273 - ) );
274 - wp_localize_script( 'wp-stream-alerts', 'streamAlerts',
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',
275 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(
276 322 'any' => __( 'Any', 'stream' ),
277 323 'anyContext' => __( 'Any Context', 'stream' ),
278 324 )
279 325 );
@@ -334,8 +380,9 @@
334 380 'label' => _x( 'Enabled', 'alert', 'stream' ),
335 381 'public' => false,
336 382 'show_in_admin_all_list' => true,
337 383 'show_in_admin_status_list' => true,
384 + // translators: Placeholder refers to a number of items (e.g. "42")
338 385 'label_count' => _n_noop( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', 'stream' ),
339 386 );
340 387
341 388 register_post_status( 'wp_stream_enabled', $args );
@@ -345,8 +392,9 @@
345 392 'public' => false,
346 393 'internal' => false,
347 394 'show_in_admin_all_list' => true,
348 395 'show_in_admin_status_list' => true,
396 + // translators: Placeholder refers to a number of items (e.g. "42")
349 397 'label_count' => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'stream' ),
350 398 );
351 399
352 400 register_post_status( 'wp_stream_disabled', $args );
@@ -361,23 +409,24 @@
361 409 */
362 410 public function get_alert( $post_id = '' ) {
363 411 if ( ! $post_id ) {
364 412 $obj = new Alert( null, $this->plugin );
413 +
365 414 return $obj;
366 415 }
367 416
368 417 $post = get_post( $post_id );
369 418
370 - $alert_type = get_post_meta( $post_id, 'alert_type', true );
371 - $alert_meta = get_post_meta( $post_id, 'alert_meta', true );
419 + $alert_type = get_post_meta( $post_id, 'alert_type', true );
420 + $alert_meta = get_post_meta( $post_id, 'alert_meta', true );
372 421
373 422 $obj = (object) array(
374 - 'ID' => $post->ID,
375 - 'status' => $post->post_status,
376 - 'date' => $post->post_date,
377 - 'author' => $post->post_author,
378 - 'alert_type' => $alert_type,
379 - 'alert_meta' => $alert_meta,
423 + 'ID' => $post->ID,
424 + 'status' => $post->post_status,
425 + 'date' => $post->post_date,
426 + 'author' => $post->post_author,
427 + 'alert_type' => $alert_type,
428 + 'alert_meta' => $alert_meta,
380 429 );
381 430
382 431 return new Alert( $obj, $this->plugin );
383 432
@@ -389,9 +438,9 @@
389 438 * @action admin_menu
390 439 *
391 440 * @return void
392 441 */
393 - function register_menu() {
442 + public function register_menu() {
394 443 add_submenu_page(
395 444 $this->plugin->admin->records_page_slug,
396 445 __( 'Alerts', 'stream' ),
397 446 __( 'Alerts', 'stream' ),
@@ -412,9 +461,9 @@
412 461 *
413 462 * @action network_admin_menu
414 463 * @return bool
415 464 */
416 - function change_menu_link_url() {
465 + public function change_menu_link_url() {
417 466 global $submenu;
418 467
419 468 $parent = 'wp_stream';
420 469 $page = 'edit.php?post_type=wp_stream_alerts';
@@ -440,12 +489,12 @@
440 489
441 490 $new_url = get_admin_url( $site_id, $page );
442 491
443 492 foreach ( $submenu[ $parent ] as $key => $value ) {
444 -
445 493 // Set correct URL for the menu item.
446 494 if ( $page === $value[2] ) {
447 - $submenu[ $parent ][ $key ][2] = $new_url;
495 + // This hack is not kosher, see the docblock for an explanation.
496 + $submenu[ $parent ][ $key ][2] = $new_url; // override okay
448 497 break;
449 498 }
450 499 }
451 500
@@ -458,24 +507,27 @@
458 507 * @param \WP_Post|array $post Post object for current alert.
459 508 *
460 509 * @return void
461 510 */
462 - function display_notification_box( $post = array() ) {
511 + public function display_notification_box( $post = array() ) {
463 512 $alert_type = 'none';
464 513 if ( is_object( $post ) ) {
465 514 $alert = $this->get_alert( $post->ID );
466 515 $alert_type = $alert->alert_type;
467 516 }
468 - $form = new Form_Generator;
517 + $form = new Form_Generator();
469 518
470 - $field_html = $form->render_field( 'select', array(
471 - 'id' => 'wp_stream_alert_type',
472 - 'name' => 'wp_stream_alert_type',
473 - 'value' => $alert_type,
474 - 'options' => $this->get_notification_values(),
475 - 'placeholder' => __( 'No Alert', 'stream' ),
476 - 'title' => 'Alert Type:',
477 - ) );
519 + $field_html = $form->render_field(
520 + 'select',
521 + array(
522 + 'id' => 'wp_stream_alert_type',
523 + 'name' => 'wp_stream_alert_type',
524 + 'value' => $alert_type,
525 + 'options' => $this->get_notification_values(),
526 + 'placeholder' => __( 'No Alert', 'stream' ),
527 + 'title' => 'Alert Type:',
528 + )
529 + );
478 530
479 531 echo '<label>' . esc_html__( 'Alert me by', 'stream' ) . '</label>';
480 532 echo $field_html; // Xss ok.
481 533
@@ -495,17 +547,19 @@
495 547 * @action wp_ajax_load_alerts_settings
496 548 *
497 549 * @return void
498 550 */
499 - function load_alerts_settings() {
500 - $alert = array();
551 + public function load_alerts_settings() {
552 + $alert = array();
501 553 $post_id = wp_stream_filter_input( INPUT_POST, 'post_id' );
502 554 if ( ! empty( $post_id ) ) {
503 555 $alert = $this->get_alert( $post_id );
504 556 if ( ! $alert ) {
505 - wp_send_json_error( array(
506 - 'message' => 'Could not find alert.',
507 - ) );
557 + wp_send_json_error(
558 + array(
559 + 'message' => 'Could not find alert.',
560 + )
561 + );
508 562 }
509 563 }
510 564
511 565 $alert_type = wp_stream_filter_input( INPUT_POST, 'alert_type' );
@@ -512,11 +566,13 @@
512 566 if ( empty( $alert_type ) ) {
513 567 $alert_type = 'none';
514 568 }
515 569 if ( ! array_key_exists( $alert_type, $this->alert_types ) ) {
516 - wp_send_json_error( array(
517 - 'message' => 'Could not find alert type.',
518 - ) );
570 + wp_send_json_error(
571 + array(
572 + 'message' => 'Could not find alert type.',
573 + )
574 + );
519 575 }
520 576
521 577 ob_start();
522 578 $this->alert_types[ $alert_type ]->display_fields( $alert );
@@ -522,9 +578,11 @@
522 578 $this->alert_types[ $alert_type ]->display_fields( $alert );
523 579 $output = ob_get_contents();
524 580 ob_end_clean();
525 581
526 - $data = array( 'html' => $output );
582 + $data = array(
583 + 'html' => $output,
584 + );
527 585 wp_send_json_success( $data );
528 586 }
529 587
530 588 /**
@@ -533,15 +591,15 @@
533 591 * @param \WP_Post|array $post Post object for current alert.
534 592 *
535 593 * @return void
536 594 */
537 - function display_triggers_box( $post = array() ) {
595 + public function display_triggers_box( $post = array() ) {
538 596 if ( is_object( $post ) ) {
539 597 $alert = $this->get_alert( $post->ID );
540 598 } else {
541 599 $alert = array();
542 600 }
543 - $form = new Form_Generator;
601 + $form = new Form_Generator();
544 602 do_action( 'wp_stream_alert_trigger_form_display', $form, $alert );
545 603 // @TODO use human readable text.
546 604 echo '<label>' . esc_html__( 'Alert me when', 'stream' ) . '</label>';
547 605 echo $form->render_fields(); // Xss ok.
@@ -554,9 +612,9 @@
554 612 * @param \WP_Post $post Post object for current alert.
555 613 *
556 614 * @return void
557 615 */
558 - function display_submit_box( $post ) {
616 + public function display_submit_box( $post ) {
559 617 if ( empty( $post ) ) {
560 618 return;
561 619 }
562 620
@@ -571,11 +629,11 @@
571 629 <div class="misc-pub-section misc-pub-post-status">
572 630 <label for="wp_stream_alert_status"><?php esc_html_e( 'Status', 'stream' ); ?></label>
573 631 <select name='wp_stream_alert_status' id='wp_stream_alert_status'>
574 632 <option<?php selected( $post_status, 'wp_stream_enabled' ); ?>
575 - value='wp_stream_enabled'><?php esc_html_e( 'Enabled', 'stream' ); ?></option>
633 + value='wp_stream_enabled'><?php esc_html_e( 'Enabled', 'stream' ); ?></option>
576 634 <option<?php selected( $post_status, 'wp_stream_disabled' ); ?>
577 - value='wp_stream_disabled'><?php esc_html_e( 'Disabled', 'stream' ); ?></option>
635 + value='wp_stream_disabled'><?php esc_html_e( 'Disabled', 'stream' ); ?></option>
578 636 </select>
579 637 </div>
580 638 </div>
581 639 <div class="clear"></div>
@@ -590,11 +648,14 @@
590 648 } else {
591 649 $delete_text = __( 'Move to Trash', 'stream' );
592 650 }
593 651 ?>
594 - <a class="submitdelete deletion"
595 - href="<?php echo get_delete_post_link( $post->ID ); ?>"><?php esc_html( $delete_text ); ?></a><?php
596 - } ?>
652 + <a class="submitdelete deletion" href="<?php echo get_delete_post_link( $post->ID ); ?>">
653 + <?php esc_html( $delete_text ); ?>
654 + </a>
655 + <?php
656 + }
657 + ?>
597 658 </div>
598 659 <div id="publishing-action">
599 660 <span class="spinner"></span>
600 661 <?php submit_button( __( 'Save' ), 'primary button-large', 'publish', false ); ?>
@@ -609,9 +670,9 @@
609 670 * Display Status Box
610 671 *
611 672 * @return void
612 673 */
613 - function display_status_box() {
674 + public function display_status_box() {
614 675 ?>
615 676 <div id="minor-publishing">
616 677 <div id="misc-publishing-actions">
617 678 <div class="misc-pub-section misc-pub-post-status">
@@ -635,9 +696,9 @@
635 696 * Return all notification values
636 697 *
637 698 * @return array
638 699 */
639 - function get_notification_values() {
700 + public function get_notification_values() {
640 701 $result = array();
641 702 $names = wp_list_pluck( $this->alert_types, 'name', 'slug' );
642 703 foreach ( $names as $slug => $name ) {
643 704 $result[ $slug ] = $name;
@@ -648,9 +709,9 @@
648 709
649 710 /**
650 711 * Update actions dropdown options based on the connector selected.
651 712 */
652 - function get_actions() {
713 + public function get_actions() {
653 714 $connector_name = wp_stream_filter_input( INPUT_POST, 'connector' );
654 715 $stream_connectors = wp_stream_get_instance()->connectors;
655 716 if ( ! empty( $connector_name ) ) {
656 717 if ( isset( $stream_connectors->connectors[ $connector_name ] ) ) {
@@ -668,9 +729,9 @@
668 729
669 730 /**
670 731 * Save a new alert
671 732 */
672 - function save_new_alert() {
733 + public function save_new_alert() {
673 734 check_ajax_referer( 'save_alert', 'wp_stream_alerts_nonce' );
674 735 $trigger_author = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_author' );
675 736 $trigger_connector_and_context = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_context' );
676 737 if ( false !== strpos( $trigger_connector_and_context, '-' ) ) {
@@ -694,11 +755,11 @@
694 755 $alert_type = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_type' );
695 756 $alert_status = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_status' );
696 757
697 758 // Insert the post into the database
698 - $item = (object) array(
699 - 'alert_type' => $alert_type,
700 - 'alert_meta' => array(
759 + $item = (object) array(
760 + 'alert_type' => $alert_type,
761 + 'alert_meta' => array(
701 762 'trigger_author' => $trigger_author,
702 763 'trigger_connector' => $trigger_connector,
703 764 'trigger_action' => $trigger_action,
704 765 'trigger_context' => $trigger_context,
@@ -704,15 +765,17 @@
704 765 'trigger_context' => $trigger_context,
705 766 ),
706 767 'alert_status' => $alert_status,
707 768 );
708 - $alert = new Alert( $item, $this->plugin );
709 - $title = $alert->get_title();
710 - $post_id = wp_insert_post( array(
711 - 'post_status' => $alert_status,
712 - 'post_type' => 'wp_stream_alerts',
713 - 'post_title' => $title,
714 - ) );
769 + $alert = new Alert( $item, $this->plugin );
770 + $title = $alert->get_title();
771 + $post_id = wp_insert_post(
772 + array(
773 + 'post_status' => $alert_status,
774 + 'post_type' => 'wp_stream_alerts',
775 + 'post_title' => $title,
776 + )
777 + );
715 778 if ( empty( $post_id ) ) {
716 779 wp_send_json_error();
717 780 }
718 781 add_post_meta( $post_id, 'alert_type', $alert_type );
@@ -724,15 +787,19 @@
724 787 'trigger_context' => $trigger_context,
725 788 );
726 789 $alert_meta = apply_filters( 'wp_stream_alerts_save_meta', $alert_meta, $alert_type );
727 790 add_post_meta( $post_id, 'alert_meta', $alert_meta );
728 - wp_send_json_success( array( 'success' => true ) );
791 + wp_send_json_success(
792 + array(
793 + 'success' => true,
794 + )
795 + );
729 796 }
730 797
731 798 /**
732 799 *
733 800 */
734 - function get_new_alert_triggers_notifications() {
801 + public function get_new_alert_triggers_notifications() {
735 802 ob_start();
736 803 ?>
737 804 <fieldset class="inline-edit-col inline-edit-wp_stream_alerts inline-edit-add-new-triggers">
738 805 <legend class="inline-edit-legend">Add New</legend>
@@ -745,31 +812,39 @@
745 812 <?php $GLOBALS['wp_stream']->alerts->display_status_box(); ?>
746 813 </fieldset>
747 814 <?php
748 815 $html = ob_get_clean();
749 - wp_send_json_success( array( 'success' => true, 'html' => $html ) );
816 + wp_send_json_success(
817 + array(
818 + 'success' => true,
819 + 'html' => $html,
820 + )
821 + );
750 822 }
823 +
751 824 /**
752 825 * Add action links to Stream drop row in admin list screen
753 826 *
754 827 * @filter wp_stream_action_links_{connector}
755 828 *
756 - * @param array $links Previous links registered
829 + * @param array $links Previous links registered
757 830 * @param Record $record Stream record
758 831 *
759 832 * @return array Action links
760 833 */
761 - function change_alert_action_links( $links, $record ) {
834 + public function change_alert_action_links( $links, $record ) {
762 835 $post = get_post( $record->object_id );
763 836
764 837 if ( $post && self::POST_TYPE === $post->post_type && $post->post_status === $record->get_meta( 'new_status', true ) ) {
765 838 if ( 'trash' !== $post->post_status ) {
766 - $connector_posts = new \WP_Stream\Connector_Posts;
767 - $post_type_name = $connector_posts->get_post_type_name( get_post_type( $post->ID ) );
839 + $connector_posts = new \WP_Stream\Connector_Posts();
840 + $post_type_name = $connector_posts->get_post_type_name( get_post_type( $post->ID ) );
768 841
842 + // translators: Placeholder refers to the post type singular name (e.g. "Post")
769 843 $links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = admin_url( 'edit.php?post_type=wp_stream_alerts#post-' . $post->ID );
770 844 unset( $links[ esc_html__( 'View', 'stream' ) ] );
771 845 }
772 846 }
847 +
773 848 return $links;
774 849 }
775 850 }