| @@ -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'; |
| @@ -23,9 +24,9 @@ | ||
| 23 | 24 | */ |
| 24 | 25 | const ALERTS_TRIGGERED_META_KEY = 'wp_stream_alerts_triggered'; |
| 25 | 26 | |
| 26 | 27 | /** |
| 27 | - * Hold Plugin class | |
| 28 | + * Holds Instance of plugin object | |
| 28 | 29 | * |
| 29 | 30 | * @var Plugin |
| 30 | 31 | */ |
| 31 | 32 | public $plugin; |
| @@ -53,9 +54,9 @@ | ||
| 53 | 54 | |
| 54 | 55 | /** |
| 55 | 56 | * Class constructor. |
| 56 | 57 | * |
| 57 | - * @param Plugin $plugin The main Plugin class. | |
| 58 | + * @param Plugin $plugin Instance of plugin object. | |
| 58 | 59 | */ |
| 59 | 60 | public function __construct( $plugin ) { |
| 60 | 61 | $this->plugin = $plugin; |
| 61 | 62 | |
| @@ -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: %s: 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: %s: 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,24 +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 | - $meta = get_post_custom( $post_id ); | |
| 370 | 418 | |
| 419 | + $alert_type = get_post_meta( $post_id, 'alert_type', true ); | |
| 420 | + $alert_meta = get_post_meta( $post_id, 'alert_meta', true ); | |
| 421 | + | |
| 371 | 422 | $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(), | |
| 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, | |
| 381 | 429 | ); |
| 382 | 430 | |
| 383 | 431 | return new Alert( $obj, $this->plugin ); |
| 384 | 432 | |
| @@ -390,9 +438,9 @@ | ||
| 390 | 438 | * @action admin_menu |
| 391 | 439 | * |
| 392 | 440 | * @return void |
| 393 | 441 | */ |
| 394 | - function register_menu() { | |
| 442 | + public function register_menu() { | |
| 395 | 443 | add_submenu_page( |
| 396 | 444 | $this->plugin->admin->records_page_slug, |
| 397 | 445 | __( 'Alerts', 'stream' ), |
| 398 | 446 | __( 'Alerts', 'stream' ), |
| @@ -413,9 +461,9 @@ | ||
| 413 | 461 | * |
| 414 | 462 | * @action network_admin_menu |
| 415 | 463 | * @return bool |
| 416 | 464 | */ |
| 417 | - function change_menu_link_url() { | |
| 465 | + public function change_menu_link_url() { | |
| 418 | 466 | global $submenu; |
| 419 | 467 | |
| 420 | 468 | $parent = 'wp_stream'; |
| 421 | 469 | $page = 'edit.php?post_type=wp_stream_alerts'; |
| @@ -425,10 +473,9 @@ | ||
| 425 | 473 | return false; |
| 426 | 474 | } |
| 427 | 475 | |
| 428 | 476 | // Get the first existing Site in the Network. |
| 429 | - // @todo: Switch to use wp_stream_get_sites() | |
| 430 | - $sites = wp_get_sites( | |
| 477 | + $sites = wp_stream_get_sites( | |
| 431 | 478 | array( |
| 432 | 479 | 'limit' => 5, // Limit the size of the query. |
| 433 | 480 | ) |
| 434 | 481 | ); |
| @@ -435,19 +482,19 @@ | ||
| 435 | 482 | |
| 436 | 483 | $site_id = '1'; |
| 437 | 484 | |
| 438 | 485 | // Function wp_get_sites() can return an empty array if the network is too large. |
| 439 | - if ( ! empty( $sites ) && ! empty( $sites[0]['blog_id'] ) ) { | |
| 440 | - $site_id = $sites[0]['blog_id']; | |
| 486 | + if ( ! empty( $sites ) && ! empty( $sites[0]->blog_id ) ) { | |
| 487 | + $site_id = $sites[0]->blog_id; | |
| 441 | 488 | } |
| 442 | 489 | |
| 443 | 490 | $new_url = get_admin_url( $site_id, $page ); |
| 444 | 491 | |
| 445 | 492 | foreach ( $submenu[ $parent ] as $key => $value ) { |
| 446 | - | |
| 447 | 493 | // Set correct URL for the menu item. |
| 448 | 494 | if ( $page === $value[2] ) { |
| 449 | - $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; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | |
| 450 | 497 | break; |
| 451 | 498 | } |
| 452 | 499 | } |
| 453 | 500 | |
| @@ -460,24 +507,27 @@ | ||
| 460 | 507 | * @param \WP_Post|array $post Post object for current alert. |
| 461 | 508 | * |
| 462 | 509 | * @return void |
| 463 | 510 | */ |
| 464 | - function display_notification_box( $post = array() ) { | |
| 511 | + public function display_notification_box( $post = array() ) { | |
| 465 | 512 | $alert_type = 'none'; |
| 466 | 513 | if ( is_object( $post ) ) { |
| 467 | 514 | $alert = $this->get_alert( $post->ID ); |
| 468 | 515 | $alert_type = $alert->alert_type; |
| 469 | 516 | } |
| 470 | - $form = new Form_Generator; | |
| 517 | + $form = new Form_Generator(); | |
| 471 | 518 | |
| 472 | - $field_html = $form->render_field( 'select', array( | |
| 473 | - 'id' => 'wp_stream_alert_type', | |
| 474 | - 'name' => 'wp_stream_alert_type', | |
| 475 | - 'value' => $alert_type, | |
| 476 | - 'options' => $this->get_notification_values(), | |
| 477 | - 'placeholder' => __( 'No Alert', 'stream' ), | |
| 478 | - 'title' => 'Alert Type:', | |
| 479 | - ) ); | |
| 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 | + ); | |
| 480 | 530 | |
| 481 | 531 | echo '<label>' . esc_html__( 'Alert me by', 'stream' ) . '</label>'; |
| 482 | 532 | echo $field_html; // Xss ok. |
| 483 | 533 | |
| @@ -497,17 +547,19 @@ | ||
| 497 | 547 | * @action wp_ajax_load_alerts_settings |
| 498 | 548 | * |
| 499 | 549 | * @return void |
| 500 | 550 | */ |
| 501 | - function load_alerts_settings() { | |
| 502 | - $alert = array(); | |
| 551 | + public function load_alerts_settings() { | |
| 552 | + $alert = array(); | |
| 503 | 553 | $post_id = wp_stream_filter_input( INPUT_POST, 'post_id' ); |
| 504 | 554 | if ( ! empty( $post_id ) ) { |
| 505 | 555 | $alert = $this->get_alert( $post_id ); |
| 506 | 556 | if ( ! $alert ) { |
| 507 | - wp_send_json_error( array( | |
| 508 | - 'message' => 'Could not find alert.', | |
| 509 | - ) ); | |
| 557 | + wp_send_json_error( | |
| 558 | + array( | |
| 559 | + 'message' => 'Could not find alert.', | |
| 560 | + ) | |
| 561 | + ); | |
| 510 | 562 | } |
| 511 | 563 | } |
| 512 | 564 | |
| 513 | 565 | $alert_type = wp_stream_filter_input( INPUT_POST, 'alert_type' ); |
| @@ -514,11 +566,13 @@ | ||
| 514 | 566 | if ( empty( $alert_type ) ) { |
| 515 | 567 | $alert_type = 'none'; |
| 516 | 568 | } |
| 517 | 569 | if ( ! array_key_exists( $alert_type, $this->alert_types ) ) { |
| 518 | - wp_send_json_error( array( | |
| 519 | - 'message' => 'Could not find alert type.', | |
| 520 | - ) ); | |
| 570 | + wp_send_json_error( | |
| 571 | + array( | |
| 572 | + 'message' => 'Could not find alert type.', | |
| 573 | + ) | |
| 574 | + ); | |
| 521 | 575 | } |
| 522 | 576 | |
| 523 | 577 | ob_start(); |
| 524 | 578 | $this->alert_types[ $alert_type ]->display_fields( $alert ); |
| @@ -524,9 +578,11 @@ | ||
| 524 | 578 | $this->alert_types[ $alert_type ]->display_fields( $alert ); |
| 525 | 579 | $output = ob_get_contents(); |
| 526 | 580 | ob_end_clean(); |
| 527 | 581 | |
| 528 | - $data = array( 'html' => $output ); | |
| 582 | + $data = array( | |
| 583 | + 'html' => $output, | |
| 584 | + ); | |
| 529 | 585 | wp_send_json_success( $data ); |
| 530 | 586 | } |
| 531 | 587 | |
| 532 | 588 | /** |
| @@ -535,15 +591,15 @@ | ||
| 535 | 591 | * @param \WP_Post|array $post Post object for current alert. |
| 536 | 592 | * |
| 537 | 593 | * @return void |
| 538 | 594 | */ |
| 539 | - function display_triggers_box( $post = array() ) { | |
| 595 | + public function display_triggers_box( $post = array() ) { | |
| 540 | 596 | if ( is_object( $post ) ) { |
| 541 | 597 | $alert = $this->get_alert( $post->ID ); |
| 542 | 598 | } else { |
| 543 | 599 | $alert = array(); |
| 544 | 600 | } |
| 545 | - $form = new Form_Generator; | |
| 601 | + $form = new Form_Generator(); | |
| 546 | 602 | do_action( 'wp_stream_alert_trigger_form_display', $form, $alert ); |
| 547 | 603 | // @TODO use human readable text. |
| 548 | 604 | echo '<label>' . esc_html__( 'Alert me when', 'stream' ) . '</label>'; |
| 549 | 605 | echo $form->render_fields(); // Xss ok. |
| @@ -556,9 +612,9 @@ | ||
| 556 | 612 | * @param \WP_Post $post Post object for current alert. |
| 557 | 613 | * |
| 558 | 614 | * @return void |
| 559 | 615 | */ |
| 560 | - function display_submit_box( $post ) { | |
| 616 | + public function display_submit_box( $post ) { | |
| 561 | 617 | if ( empty( $post ) ) { |
| 562 | 618 | return; |
| 563 | 619 | } |
| 564 | 620 | |
| @@ -570,14 +626,14 @@ | ||
| 570 | 626 | <div class="submitbox" id="submitpost"> |
| 571 | 627 | <div id="minor-publishing"> |
| 572 | 628 | <div id="misc-publishing-actions"> |
| 573 | 629 | <div class="misc-pub-section misc-pub-post-status"> |
| 574 | - <label for="wp_stream_alert_status"><?php esc_html_e( 'Status', 'stream' ) ?></label> | |
| 630 | + <label for="wp_stream_alert_status"><?php esc_html_e( 'Status', 'stream' ); ?></label> | |
| 575 | 631 | <select name='wp_stream_alert_status' id='wp_stream_alert_status'> |
| 576 | 632 | <option<?php selected( $post_status, 'wp_stream_enabled' ); ?> |
| 577 | - value='wp_stream_enabled'><?php esc_html_e( 'Enabled', 'stream' ) ?></option> | |
| 633 | + value='wp_stream_enabled'><?php esc_html_e( 'Enabled', 'stream' ); ?></option> | |
| 578 | 634 | <option<?php selected( $post_status, 'wp_stream_disabled' ); ?> |
| 579 | - value='wp_stream_disabled'><?php esc_html_e( 'Disabled', 'stream' ) ?></option> | |
| 635 | + value='wp_stream_disabled'><?php esc_html_e( 'Disabled', 'stream' ); ?></option> | |
| 580 | 636 | </select> |
| 581 | 637 | </div> |
| 582 | 638 | </div> |
| 583 | 639 | <div class="clear"></div> |
| @@ -592,11 +648,14 @@ | ||
| 592 | 648 | } else { |
| 593 | 649 | $delete_text = __( 'Move to Trash', 'stream' ); |
| 594 | 650 | } |
| 595 | 651 | ?> |
| 596 | - <a class="submitdelete deletion" | |
| 597 | - href="<?php echo get_delete_post_link( $post->ID ); ?>"><?php esc_html( $delete_text ); ?></a><?php | |
| 598 | - } ?> | |
| 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 | + ?> | |
| 599 | 658 | </div> |
| 600 | 659 | <div id="publishing-action"> |
| 601 | 660 | <span class="spinner"></span> |
| 602 | 661 | <?php submit_button( __( 'Save' ), 'primary button-large', 'publish', false ); ?> |
| @@ -611,19 +670,19 @@ | ||
| 611 | 670 | * Display Status Box |
| 612 | 671 | * |
| 613 | 672 | * @return void |
| 614 | 673 | */ |
| 615 | - function display_status_box() { | |
| 674 | + public function display_status_box() { | |
| 616 | 675 | ?> |
| 617 | 676 | <div id="minor-publishing"> |
| 618 | 677 | <div id="misc-publishing-actions"> |
| 619 | 678 | <div class="misc-pub-section misc-pub-post-status"> |
| 620 | 679 | <label for="wp_stream_alert_status"> |
| 621 | - <span class="title"><?php esc_html_e( 'Status:', 'stream' ) ?></span> | |
| 680 | + <span class="title"><?php esc_html_e( 'Status:', 'stream' ); ?></span> | |
| 622 | 681 | <span class="input-text-wrap"> |
| 623 | 682 | <select name='wp_stream_alert_status' id='wp_stream_alert_status'> |
| 624 | - <option selected value='wp_stream_enabled'><?php esc_html_e( 'Enabled', 'stream' ) ?></option> | |
| 625 | - <option value='wp_stream_disabled'><?php esc_html_e( 'Disabled', 'stream' ) ?></option> | |
| 683 | + <option selected value='wp_stream_enabled'><?php esc_html_e( 'Enabled', 'stream' ); ?></option> | |
| 684 | + <option value='wp_stream_disabled'><?php esc_html_e( 'Disabled', 'stream' ); ?></option> | |
| 626 | 685 | </select> |
| 627 | 686 | </span> |
| 628 | 687 | </label> |
| 629 | 688 | </div> |
| @@ -637,9 +696,9 @@ | ||
| 637 | 696 | * Return all notification values |
| 638 | 697 | * |
| 639 | 698 | * @return array |
| 640 | 699 | */ |
| 641 | - function get_notification_values() { | |
| 700 | + public function get_notification_values() { | |
| 642 | 701 | $result = array(); |
| 643 | 702 | $names = wp_list_pluck( $this->alert_types, 'name', 'slug' ); |
| 644 | 703 | foreach ( $names as $slug => $name ) { |
| 645 | 704 | $result[ $slug ] = $name; |
| @@ -650,9 +709,9 @@ | ||
| 650 | 709 | |
| 651 | 710 | /** |
| 652 | 711 | * Update actions dropdown options based on the connector selected. |
| 653 | 712 | */ |
| 654 | - function get_actions() { | |
| 713 | + public function get_actions() { | |
| 655 | 714 | $connector_name = wp_stream_filter_input( INPUT_POST, 'connector' ); |
| 656 | 715 | $stream_connectors = wp_stream_get_instance()->connectors; |
| 657 | 716 | if ( ! empty( $connector_name ) ) { |
| 658 | 717 | if ( isset( $stream_connectors->connectors[ $connector_name ] ) ) { |
| @@ -670,9 +729,9 @@ | ||
| 670 | 729 | |
| 671 | 730 | /** |
| 672 | 731 | * Save a new alert |
| 673 | 732 | */ |
| 674 | - function save_new_alert() { | |
| 733 | + public function save_new_alert() { | |
| 675 | 734 | check_ajax_referer( 'save_alert', 'wp_stream_alerts_nonce' ); |
| 676 | 735 | $trigger_author = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_author' ); |
| 677 | 736 | $trigger_connector_and_context = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_context' ); |
| 678 | 737 | if ( false !== strpos( $trigger_connector_and_context, '-' ) ) { |
| @@ -695,12 +754,12 @@ | ||
| 695 | 754 | $trigger_action = wp_stream_filter_input( INPUT_POST, 'wp_stream_trigger_action' ); |
| 696 | 755 | $alert_type = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_type' ); |
| 697 | 756 | $alert_status = wp_stream_filter_input( INPUT_POST, 'wp_stream_alert_status' ); |
| 698 | 757 | |
| 699 | - // Insert the post into the database | |
| 700 | - $item = (object) array( | |
| 701 | - 'alert_type' => $alert_type, | |
| 702 | - 'alert_meta' => array( | |
| 758 | + // Insert the post into the database. | |
| 759 | + $item = (object) array( | |
| 760 | + 'alert_type' => $alert_type, | |
| 761 | + 'alert_meta' => array( | |
| 703 | 762 | 'trigger_author' => $trigger_author, |
| 704 | 763 | 'trigger_connector' => $trigger_connector, |
| 705 | 764 | 'trigger_action' => $trigger_action, |
| 706 | 765 | 'trigger_context' => $trigger_context, |
| @@ -706,15 +765,17 @@ | ||
| 706 | 765 | 'trigger_context' => $trigger_context, |
| 707 | 766 | ), |
| 708 | 767 | 'alert_status' => $alert_status, |
| 709 | 768 | ); |
| 710 | - $alert = new Alert( $item, $this->plugin ); | |
| 711 | - $title = $alert->get_title(); | |
| 712 | - $post_id = wp_insert_post( array( | |
| 713 | - 'post_status' => $alert_status, | |
| 714 | - 'post_type' => 'wp_stream_alerts', | |
| 715 | - 'post_title' => $title, | |
| 716 | - ) ); | |
| 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 | + ); | |
| 717 | 778 | if ( empty( $post_id ) ) { |
| 718 | 779 | wp_send_json_error(); |
| 719 | 780 | } |
| 720 | 781 | add_post_meta( $post_id, 'alert_type', $alert_type ); |
| @@ -726,15 +787,19 @@ | ||
| 726 | 787 | 'trigger_context' => $trigger_context, |
| 727 | 788 | ); |
| 728 | 789 | $alert_meta = apply_filters( 'wp_stream_alerts_save_meta', $alert_meta, $alert_type ); |
| 729 | 790 | add_post_meta( $post_id, 'alert_meta', $alert_meta ); |
| 730 | - wp_send_json_success( array( 'success' => true ) ); | |
| 791 | + wp_send_json_success( | |
| 792 | + array( | |
| 793 | + 'success' => true, | |
| 794 | + ) | |
| 795 | + ); | |
| 731 | 796 | } |
| 732 | 797 | |
| 733 | 798 | /** |
| 734 | - * | |
| 799 | + * Return HTML string of the Alert page controls. | |
| 735 | 800 | */ |
| 736 | - function get_new_alert_triggers_notifications() { | |
| 801 | + public function get_new_alert_triggers_notifications() { | |
| 737 | 802 | ob_start(); |
| 738 | 803 | ?> |
| 739 | 804 | <fieldset class="inline-edit-col inline-edit-wp_stream_alerts inline-edit-add-new-triggers"> |
| 740 | 805 | <legend class="inline-edit-legend">Add New</legend> |
| @@ -747,31 +812,39 @@ | ||
| 747 | 812 | <?php $GLOBALS['wp_stream']->alerts->display_status_box(); ?> |
| 748 | 813 | </fieldset> |
| 749 | 814 | <?php |
| 750 | 815 | $html = ob_get_clean(); |
| 751 | - wp_send_json_success( array( 'success' => true, 'html' => $html ) ); | |
| 816 | + wp_send_json_success( | |
| 817 | + array( | |
| 818 | + 'success' => true, | |
| 819 | + 'html' => $html, | |
| 820 | + ) | |
| 821 | + ); | |
| 752 | 822 | } |
| 823 | + | |
| 753 | 824 | /** |
| 754 | 825 | * Add action links to Stream drop row in admin list screen |
| 755 | 826 | * |
| 756 | 827 | * @filter wp_stream_action_links_{connector} |
| 757 | 828 | * |
| 758 | - * @param array $links Previous links registered | |
| 759 | - * @param Record $record Stream record | |
| 829 | + * @param array $links Previous links registered. | |
| 830 | + * @param Record $record Stream record. | |
| 760 | 831 | * |
| 761 | 832 | * @return array Action links |
| 762 | 833 | */ |
| 763 | - function change_alert_action_links( $links, $record ) { | |
| 834 | + public function change_alert_action_links( $links, $record ) { | |
| 764 | 835 | $post = get_post( $record->object_id ); |
| 765 | 836 | |
| 766 | 837 | if ( $post && self::POST_TYPE === $post->post_type && $post->post_status === $record->get_meta( 'new_status', true ) ) { |
| 767 | 838 | if ( 'trash' !== $post->post_status ) { |
| 768 | - $connector_posts = new \WP_Stream\Connector_Posts; | |
| 769 | - $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 ) ); | |
| 770 | 841 | |
| 842 | + /* translators: %s: the post type singular name (e.g. "Post") */ | |
| 771 | 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 ); |
| 772 | 844 | unset( $links[ esc_html__( 'View', 'stream' ) ] ); |
| 773 | 845 | } |
| 774 | 846 | } |
| 847 | + | |
| 775 | 848 | return $links; |
| 776 | 849 | } |
| 777 | 850 | } |