PluginProbe
Stream – Activity Log & Audit Trail / 3.2.0
Stream – Activity Log & Audit Trail v3.2.0
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
stream / classes / class-alerts.php

class-alerts.php in Stream – Activity Log & Audit Trail 3.2.0, at classes/class-alerts.php

777 lines 22.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Alerts feature class.
4 *
5 * @package WP_Stream
6 */
7
8 namespace WP_Stream;
9
10 /**
11 * Class Alerts
12 *
13 * @package WP_Stream
14 */
15 class Alerts {
16 /**
17 * Alerts post type slug
18 */
19 const POST_TYPE = 'wp_stream_alerts';
20
21 /**
22 * Triggered Alerts meta key for Records
23 */
24 const ALERTS_TRIGGERED_META_KEY = 'wp_stream_alerts_triggered';
25
26 /**
27 * Hold Plugin class
28 *
29 * @var Plugin
30 */
31 public $plugin;
32
33 /**
34 * Post meta prefix
35 *
36 * @var string
37 */
38 public $meta_prefix = 'wp_stream';
39
40 /**
41 * Alert Types
42 *
43 * @var array
44 */
45 public $alert_types = array();
46
47 /**
48 * Alert Triggers
49 *
50 * @var array
51 */
52 public $alert_triggers = array();
53
54 /**
55 * Class constructor.
56 *
57 * @param Plugin $plugin The main Plugin class.
58 */
59 public function __construct( $plugin ) {
60 $this->plugin = $plugin;
61
62 // Register custom post type.
63 add_action( 'init', array( $this, 'register_post_type' ) );
64
65 // Add custom post type to menu.
66 add_action( 'wp_stream_admin_menu', array( $this, 'register_menu' ) );
67
68 // Add scripts to post screens.
69 add_action( 'admin_enqueue_scripts', array( $this, 'register_scripts' ) );
70
71 add_action( 'network_admin_menu', array( $this, 'change_menu_link_url' ), 99 );
72
73 add_filter( 'wp_stream_record_inserted', array( $this, 'check_records' ), 10, 2 );
74
75 add_action( 'wp_ajax_load_alerts_settings', array( $this, 'load_alerts_settings' ) );
76 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 ) );
82
83 $this->load_alert_types();
84 $this->load_alert_triggers();
85
86 add_filter( 'wp_stream_action_links_posts', array( $this, 'change_alert_action_links' ), 11, 2 );
87
88 }
89
90 /**
91 * Load alert_type classes
92 *
93 * @return void
94 */
95 function load_alert_types() {
96 $alert_types = array(
97 'none',
98 'highlight',
99 'email',
100 'ifttt',
101 );
102
103 $classes = array();
104 foreach ( $alert_types as $alert_type ) {
105 $file_location = $this->plugin->locations['dir'] . '/alerts/class-alert-type-' . $alert_type . '.php';
106 if ( file_exists( $file_location ) ) {
107 include_once $file_location;
108 $class_name = sprintf( '\WP_Stream\Alert_Type_%s', str_replace( '-', '_', $alert_type ) );
109 if ( ! class_exists( $class_name ) ) {
110 continue;
111 }
112 $class = new $class_name( $this->plugin );
113 if ( ! property_exists( $class, 'slug' ) ) {
114 continue;
115 }
116 $classes[ $class->slug ] = $class;
117 }
118 }
119
120 /**
121 * Allows for adding additional alert_types via classes that extend Notifier.
122 *
123 * @param array $classes An array of Notifier objects. In the format alert_type_slug => Notifier_Class()
124 */
125 $this->alert_types = apply_filters( 'wp_stream_alert_types', $classes );
126
127 // Ensure that all alert_types extend Notifier.
128 foreach ( $this->alert_types as $key => $alert_type ) {
129 if ( ! $this->is_valid_alert_type( $alert_type ) ) {
130 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 }
138 }
139 }
140
141 /**
142 * Load alert_type classes
143 *
144 * @return void
145 */
146 function load_alert_triggers() {
147 $alert_triggers = array(
148 'author',
149 'context',
150 'action',
151 );
152
153 $classes = array();
154 foreach ( $alert_triggers as $alert_trigger ) {
155 $file_location = $this->plugin->locations['dir'] . '/alerts/class-alert-trigger-' . $alert_trigger . '.php';
156 if ( file_exists( $file_location ) ) {
157 include_once $file_location;
158 $class_name = sprintf( '\WP_Stream\Alert_Trigger_%s', str_replace( '-', '_', $alert_trigger ) );
159 if ( ! class_exists( $class_name ) ) {
160 continue;
161 }
162 $class = new $class_name( $this->plugin );
163 if ( ! property_exists( $class, 'slug' ) ) {
164 continue;
165 }
166 $classes[ $class->slug ] = $class;
167 }
168 }
169
170 /**
171 * Allows for adding additional alert_triggers via classes that extend Notifier.
172 *
173 * @param array $classes An array of Notifier objects. In the format alert_trigger_slug => Notifier_Class()
174 */
175 $this->alert_triggers = apply_filters( 'wp_stream_alert_triggers', $classes );
176
177 // Ensure that all alert_triggers extend Notifier.
178 foreach ( $this->alert_triggers as $key => $alert_trigger ) {
179 if ( ! $this->is_valid_alert_trigger( $alert_trigger ) ) {
180 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 }
188 }
189 }
190
191 /**
192 * Checks whether a Alert Type class is valid
193 *
194 * @param Alert_Type $alert_type The class to check.
195 *
196 * @return bool
197 */
198 public function is_valid_alert_type( $alert_type ) {
199 if ( ! is_a( $alert_type, 'WP_Stream\Alert_Type' ) ) {
200 return false;
201 }
202
203 if ( ! method_exists( $alert_type, 'is_dependency_satisfied' ) || ! $alert_type->is_dependency_satisfied() ) {
204 return false;
205 }
206
207 return true;
208 }
209
210 /**
211 * Checks whether a Alert Trigger class is valid
212 *
213 * @param Alert_Trigger $alert_trigger The class to check.
214 *
215 * @return bool
216 */
217 public function is_valid_alert_trigger( $alert_trigger ) {
218 if ( ! is_a( $alert_trigger, 'WP_Stream\Alert_Trigger' ) ) {
219 return false;
220 }
221
222 if ( ! method_exists( $alert_trigger, 'is_dependency_satisfied' ) || ! $alert_trigger->is_dependency_satisfied() ) {
223 return false;
224 }
225
226 return true;
227 }
228
229 /**
230 * Checks record being processed against active alerts.
231 *
232 * @filter wp_stream_record_inserted
233 *
234 * @param int $record_id The record being processed.
235 * @param array $recordarr Record data.
236 *
237 * @return array
238 */
239 function check_records( $record_id, $recordarr ) {
240 $args = array(
241 'post_type' => self::POST_TYPE,
242 'post_status' => 'wp_stream_enabled',
243 );
244
245 $alerts = new \WP_Query( $args );
246 foreach ( $alerts->posts as $alert ) {
247 $alert = $this->get_alert( $alert->ID );
248
249 $status = $alert->check_record( $record_id, $recordarr );
250 if ( $status ) {
251 $alert->send_alert( $record_id, $recordarr ); // @todo send_alert expects int, not array.
252 }
253 }
254
255 return $recordarr;
256
257 }
258
259 /**
260 * Register scripts for page load
261 *
262 * @action admin_enqueue_scripts
263 *
264 * @return void
265 */
266 function register_scripts() {
267 $screen = get_current_screen();
268 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',
275 array(
276 'any' => __( 'Any', 'stream' ),
277 'anyContext' => __( 'Any Context', 'stream' ),
278 )
279 );
280 wp_enqueue_script( 'wp-stream-alerts' );
281 wp_enqueue_style( 'wp-stream-select2' );
282 }
283 }
284
285 /**
286 * Register custom post type
287 *
288 * @action init
289 *
290 * @return void
291 */
292 public function register_post_type() {
293 $labels = array(
294 'name' => _x( 'Alerts', 'post type general name', 'stream' ),
295 'singular_name' => _x( 'Alert', 'post type singular name', 'stream' ),
296 'menu_name' => _x( 'Alerts', 'admin menu', 'stream' ),
297 'name_admin_bar' => _x( 'Alert', 'add new on admin bar', 'stream' ),
298 'add_new' => _x( 'Add New', 'book', 'stream' ),
299 'add_new_item' => __( 'Add New Alert', 'stream' ),
300 'new_item' => __( 'New Alert', 'stream' ),
301 'edit_item' => __( 'Edit Alert', 'stream' ),
302 'view_item' => __( 'View Alert', 'stream' ),
303 'all_items' => __( 'Alerts', 'stream' ),
304 'search_items' => __( 'Search Alerts', 'stream' ),
305 'parent_item_colon' => __( 'Parent Alerts:', 'stream' ),
306 'not_found' => __( 'No alerts found.', 'stream' ),
307 'not_found_in_trash' => __( 'No alerts found in Trash.', 'stream' ),
308 );
309
310 $args = array(
311 'labels' => $labels,
312 'description' => __( 'Alerts for Stream.', 'stream' ),
313 'public' => false,
314 'publicly_queryable' => false,
315 'exclude_from_search' => true,
316 'show_ui' => true,
317 'show_in_menu' => false, // @see modify_admin_menu
318 'supports' => false,
319 'capabilities' => array(
320 'publish_posts' => 'manage_options',
321 'edit_others_posts' => 'manage_options',
322 'delete_posts' => 'manage_options',
323 'delete_others_posts' => 'manage_options',
324 'read_private_posts' => 'manage_options',
325 'edit_post' => 'manage_options',
326 'delete_post' => 'manage_options',
327 'read_post' => 'manage_options',
328 ),
329 );
330
331 register_post_type( self::POST_TYPE, $args );
332
333 $args = array(
334 'label' => _x( 'Enabled', 'alert', 'stream' ),
335 'public' => false,
336 'show_in_admin_all_list' => true,
337 'show_in_admin_status_list' => true,
338 'label_count' => _n_noop( 'Enabled <span class="count">(%s)</span>', 'Enabled <span class="count">(%s)</span>', 'stream' ),
339 );
340
341 register_post_status( 'wp_stream_enabled', $args );
342
343 $args = array(
344 'label' => _x( 'Disabled', 'alert', 'stream' ),
345 'public' => false,
346 'internal' => false,
347 'show_in_admin_all_list' => true,
348 'show_in_admin_status_list' => true,
349 'label_count' => _n_noop( 'Disabled <span class="count">(%s)</span>', 'Disabled <span class="count">(%s)</span>', 'stream' ),
350 );
351
352 register_post_status( 'wp_stream_disabled', $args );
353 }
354
355 /**
356 * Return alert object of the given ID
357 *
358 * @param string $post_id Post ID for the alert.
359 *
360 * @return Alert
361 */
362 public function get_alert( $post_id = '' ) {
363 if ( ! $post_id ) {
364 $obj = new Alert( null, $this->plugin );
365 return $obj;
366 }
367
368 $post = get_post( $post_id );
369 $meta = get_post_custom( $post_id );
370
371 $obj = (object) array(
372 'ID' => $post->ID,
373 'status' => $post->post_status,
374 'date' => $post->post_date,
375 'author' => $post->post_author,
376 'filter_action' => isset( $meta['filter_action'] ) ? $meta['filter_action'][0] : null,
377 'filter_author' => isset( $meta['filter_author'] ) ? $meta['filter_author'][0] : null,
378 'filter_context' => isset( $meta['filter_context'] ) ? $meta['filter_context'][0] : null,
379 'alert_type' => isset( $meta['alert_type'] ) ? $meta['alert_type'][0] : null,
380 'alert_meta' => isset( $meta['alert_meta'] ) ? (array) maybe_unserialize( $meta['alert_meta'][0] ) : array(),
381 );
382
383 return new Alert( $obj, $this->plugin );
384
385 }
386
387 /**
388 * Add custom post type to menu
389 *
390 * @action admin_menu
391 *
392 * @return void
393 */
394 function register_menu() {
395 add_submenu_page(
396 $this->plugin->admin->records_page_slug,
397 __( 'Alerts', 'stream' ),
398 __( 'Alerts', 'stream' ),
399 'manage_options',
400 'edit.php?post_type=wp_stream_alerts'
401 );
402 }
403
404 /**
405 * Modify the Stream > Alerts Network Admin Menu link.
406 *
407 * In self::register_menu(), the Alerts submenu item
408 * is essentially set to go to the Site's admin area.
409 *
410 * However, on the Network admin, we need to redirect
411 * it to the first site in the network, as this is
412 * where the true Network Alerts settings page is located.
413 *
414 * @action network_admin_menu
415 * @return bool
416 */
417 function change_menu_link_url() {
418 global $submenu;
419
420 $parent = 'wp_stream';
421 $page = 'edit.php?post_type=wp_stream_alerts';
422
423 // If we're not on the Stream menu item, return.
424 if ( ! isset( $submenu[ $parent ] ) ) {
425 return false;
426 }
427
428 // Get the first existing Site in the Network.
429 $sites = wp_stream_get_sites(
430 array(
431 'limit' => 5, // Limit the size of the query.
432 )
433 );
434
435 $site_id = '1';
436
437 // Function wp_get_sites() can return an empty array if the network is too large.
438 if ( ! empty( $sites ) && ! empty( $sites[0]->blog_id ) ) {
439 $site_id = $sites[0]->blog_id;
440 }
441
442 $new_url = get_admin_url( $site_id, $page );
443
444 foreach ( $submenu[ $parent ] as $key => $value ) {
445
446 // Set correct URL for the menu item.
447 if ( $page === $value[2] ) {
448 $submenu[ $parent ][ $key ][2] = $new_url;
449 break;
450 }
451 }
452
453 return true;
454 }
455
456 /**
457 * Display Alert Type Meta Box
458 *
459 * @param \WP_Post|array $post Post object for current alert.
460 *
461 * @return void
462 */
463 function display_notification_box( $post = array() ) {
464 $alert_type = 'none';
465 if ( is_object( $post ) ) {
466 $alert = $this->get_alert( $post->ID );
467 $alert_type = $alert->alert_type;
468 }
469 $form = new Form_Generator;
470
471 $field_html = $form->render_field( 'select', array(
472 'id' => 'wp_stream_alert_type',
473 'name' => 'wp_stream_alert_type',
474 'value' => $alert_type,
475 'options' => $this->get_notification_values(),
476 'placeholder' => __( 'No Alert', 'stream' ),
477 'title' => 'Alert Type:',
478 ) );
479
480 echo '<label>' . esc_html__( 'Alert me by', 'stream' ) . '</label>';
481 echo $field_html; // Xss ok.
482
483 echo '<div id="wp_stream_alert_type_form">';
484 if ( is_object( $alert ) ) {
485 $alert->get_alert_type_obj()->display_fields( $alert );
486 } else {
487 $this->plugin->alerts->alert_types['none']->display_fields( array() );
488 }
489
490 echo '</div>';
491 }
492
493 /**
494 * Returns settings form HTML for AJAX use
495 *
496 * @action wp_ajax_load_alerts_settings
497 *
498 * @return void
499 */
500 function load_alerts_settings() {
501 $alert = array();
502 $post_id = wp_stream_filter_input( INPUT_POST, 'post_id' );
503 if ( ! empty( $post_id ) ) {
504 $alert = $this->get_alert( $post_id );
505 if ( ! $alert ) {
506 wp_send_json_error( array(
507 'message' => 'Could not find alert.',
508 ) );
509 }
510 }
511
512 $alert_type = wp_stream_filter_input( INPUT_POST, 'alert_type' );
513 if ( empty( $alert_type ) ) {
514 $alert_type = 'none';
515 }
516 if ( ! array_key_exists( $alert_type, $this->alert_types ) ) {
517 wp_send_json_error( array(
518 'message' => 'Could not find alert type.',
519 ) );
520 }
521
522 ob_start();
523 $this->alert_types[ $alert_type ]->display_fields( $alert );
524 $output = ob_get_contents();
525 ob_end_clean();
526
527 $data = array( 'html' => $output );
528 wp_send_json_success( $data );
529 }
530
531 /**
532 * Display Trigger Meta Box
533 *
534 * @param \WP_Post|array $post Post object for current alert.
535 *
536 * @return void
537 */
538 function display_triggers_box( $post = array() ) {
539 if ( is_object( $post ) ) {
540 $alert = $this->get_alert( $post->ID );
541 } else {
542 $alert = array();
543 }
544 $form = new Form_Generator;
545 do_action( 'wp_stream_alert_trigger_form_display', $form, $alert );
546 // @TODO use human readable text.
547 echo '<label>' . esc_html__( 'Alert me when', 'stream' ) . '</label>';
548 echo $form->render_fields(); // Xss ok.
549 wp_nonce_field( 'save_alert', 'wp_stream_alerts_nonce' );
550 }
551
552 /**
553 * Display Submit Box
554 *
555 * @param \WP_Post $post Post object for current alert.
556 *
557 * @return void
558 */
559 function display_submit_box( $post ) {
560 if ( empty( $post ) ) {
561 return;
562 }
563
564 $post_status = $post->post_status;
565 if ( 'auto-draft' === $post_status ) {
566 $post_status = 'wp_stream_enabled';
567 }
568 ?>
569 <div class="submitbox" id="submitpost">
570 <div id="minor-publishing">
571 <div id="misc-publishing-actions">
572 <div class="misc-pub-section misc-pub-post-status">
573 <label for="wp_stream_alert_status"><?php esc_html_e( 'Status', 'stream' ) ?></label>
574 <select name='wp_stream_alert_status' id='wp_stream_alert_status'>
575 <option<?php selected( $post_status, 'wp_stream_enabled' ); ?>
576 value='wp_stream_enabled'><?php esc_html_e( 'Enabled', 'stream' ) ?></option>
577 <option<?php selected( $post_status, 'wp_stream_disabled' ); ?>
578 value='wp_stream_disabled'><?php esc_html_e( 'Disabled', 'stream' ) ?></option>
579 </select>
580 </div>
581 </div>
582 <div class="clear"></div>
583 </div>
584
585 <div id="major-publishing-actions">
586 <div id="delete-action">
587 <?php
588 if ( current_user_can( 'delete_post', $post->ID ) ) {
589 if ( ! EMPTY_TRASH_DAYS ) {
590 $delete_text = __( 'Delete Permanently', 'stream' );
591 } else {
592 $delete_text = __( 'Move to Trash', 'stream' );
593 }
594 ?>
595 <a class="submitdelete deletion"
596 href="<?php echo get_delete_post_link( $post->ID ); ?>"><?php esc_html( $delete_text ); ?></a><?php
597 } ?>
598 </div>
599 <div id="publishing-action">
600 <span class="spinner"></span>
601 <?php submit_button( __( 'Save' ), 'primary button-large', 'publish', false ); ?>
602 </div>
603 <div class="clear"></div>
604 </div>
605 </div>
606 <?php
607 }
608
609 /**
610 * Display Status Box
611 *
612 * @return void
613 */
614 function display_status_box() {
615 ?>
616 <div id="minor-publishing">
617 <div id="misc-publishing-actions">
618 <div class="misc-pub-section misc-pub-post-status">
619 <label for="wp_stream_alert_status">
620 <span class="title"><?php esc_html_e( 'Status:', 'stream' ) ?></span>
621 <span class="input-text-wrap">
622 <select name='wp_stream_alert_status' id='wp_stream_alert_status'>
623 <option selected value='wp_stream_enabled'><?php esc_html_e( 'Enabled', 'stream' ) ?></option>
624 <option value='wp_stream_disabled'><?php esc_html_e( 'Disabled', 'stream' ) ?></option>
625 </select>
626 </span>
627 </label>
628 </div>
629 </div>
630 <div class="clear"></div>
631 </div>
632 <?php
633 }
634
635 /**
636 * Return all notification values
637 *
638 * @return array
639 */
640 function get_notification_values() {
641 $result = array();
642 $names = wp_list_pluck( $this->alert_types, 'name', 'slug' );
643 foreach ( $names as $slug => $name ) {
644 $result[ $slug ] = $name;
645 }
646
647 return $result;
648 }
649
650 /**
651 * Update actions dropdown options based on the connector selected.
652 */
653 function get_actions() {
654 $connector_name = wp_stream_filter_input( INPUT_POST, 'connector' );
655 $stream_connectors = wp_stream_get_instance()->connectors;
656 if ( ! empty( $connector_name ) ) {
657 if ( isset( $stream_connectors->connectors[ $connector_name ] ) ) {
658 $connector = $stream_connectors->connectors[ $connector_name ];
659 if ( method_exists( $connector, 'get_action_labels' ) ) {
660 $actions = $connector->get_action_labels();
661 }
662 }
663 } else {
664 $actions = $stream_connectors->term_labels['stream_action'];
665 }
666 ksort( $actions );
667 wp_send_json_success( $actions );
668 }
669
670 /**
671 * Save a new alert
672 */
673 function save_new_alert() {
674 check_ajax_referer( 'save_alert', 'wp_stream_alerts_nonce' );
675 $trigger_author = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_author' );
676 $trigger_connector_and_context = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_context' );
677 if ( false !== strpos( $trigger_connector_and_context, '-' ) ) {
678 // This is a connector with a context such as posts-post.
679 $trigger_connector_and_context_split = explode( '-', $trigger_connector_and_context );
680 $trigger_connector = $trigger_connector_and_context_split[0];
681 $trigger_context = $trigger_connector_and_context_split[1];
682 } else {
683 if ( ! empty( $trigger_connector_and_context ) ) {
684 // This is a parent connector with no dash such as posts.
685 $trigger_connector = $trigger_connector_and_context;
686 $trigger_context = '';
687 } else {
688 // There is no connector or context.
689 $trigger_connector = '';
690 $trigger_context = '';
691 }
692 }
693
694 $trigger_action = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_action' );
695 $alert_type = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_type' );
696 $alert_status = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_status' );
697
698 // Insert the post into the database
699 $item = (object) array(
700 'alert_type' => $alert_type,
701 'alert_meta' => array(
702 'trigger_author' => $trigger_author,
703 'trigger_connector' => $trigger_connector,
704 'trigger_action' => $trigger_action,
705 'trigger_context' => $trigger_context,
706 ),
707 'alert_status' => $alert_status,
708 );
709 $alert = new Alert( $item, $this->plugin );
710 $title = $alert->get_title();
711 $post_id = wp_insert_post( array(
712 'post_status' => $alert_status,
713 'post_type' => 'wp_stream_alerts',
714 'post_title' => $title,
715 ) );
716 if ( empty( $post_id ) ) {
717 wp_send_json_error();
718 }
719 add_post_meta( $post_id, 'alert_type', $alert_type );
720
721 $alert_meta = array(
722 'trigger_author' => $trigger_author,
723 'trigger_connector' => $trigger_connector,
724 'trigger_action' => $trigger_action,
725 'trigger_context' => $trigger_context,
726 );
727 $alert_meta = apply_filters( 'wp_stream_alerts_save_meta', $alert_meta, $alert_type );
728 add_post_meta( $post_id, 'alert_meta', $alert_meta );
729 wp_send_json_success( array( 'success' => true ) );
730 }
731
732 /**
733 *
734 */
735 function get_new_alert_triggers_notifications() {
736 ob_start();
737 ?>
738 <fieldset class="inline-edit-col inline-edit-wp_stream_alerts inline-edit-add-new-triggers">
739 <legend class="inline-edit-legend">Add New</legend>
740 <?php $GLOBALS['wp_stream']->alerts->display_triggers_box(); ?>
741 </fieldset>
742 <fieldset class="inline-edit-col inline-edit-wp_stream_alerts inline-edit-add-new-notifications">
743 <?php $GLOBALS['wp_stream']->alerts->display_notification_box(); ?>
744 </fieldset>
745 <fieldset class="inline-edit-col inline-edit-wp_stream_alerts inline-edit-add-new-status">
746 <?php $GLOBALS['wp_stream']->alerts->display_status_box(); ?>
747 </fieldset>
748 <?php
749 $html = ob_get_clean();
750 wp_send_json_success( array( 'success' => true, 'html' => $html ) );
751 }
752 /**
753 * Add action links to Stream drop row in admin list screen
754 *
755 * @filter wp_stream_action_links_{connector}
756 *
757 * @param array $links Previous links registered
758 * @param Record $record Stream record
759 *
760 * @return array Action links
761 */
762 function change_alert_action_links( $links, $record ) {
763 $post = get_post( $record->object_id );
764
765 if ( $post && self::POST_TYPE === $post->post_type && $post->post_status === $record->get_meta( 'new_status', true ) ) {
766 if ( 'trash' !== $post->post_status ) {
767 $connector_posts = new \WP_Stream\Connector_Posts;
768 $post_type_name = $connector_posts->get_post_type_name( get_post_type( $post->ID ) );
769
770 $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 );
771 unset( $links[ esc_html__( 'View', 'stream' ) ] );
772 }
773 }
774 return $links;
775 }
776 }
777