Ticket #6712: 6712.01.patch
File 6712.01.patch, 75.0 KB (added by , 8 years ago) |
---|
-
src/bp-activity/bp-activity-actions.php
746 746 } 747 747 748 748 /** 749 * Helper method to map action arguments to function parameters. 750 * 751 * @since 1.9.0 752 * 753 * @param int $comment_id ID of the comment being notified about. 754 * @param array $params Parameters to use with notification. 755 */ 756 function bp_activity_new_comment_notification_helper( $comment_id, $params ) { 757 bp_activity_new_comment_notification( $comment_id, $params['user_id'], $params ); 758 } 759 add_action( 'bp_activity_comment_posted', 'bp_activity_new_comment_notification_helper', 10, 2 ); 760 761 /** 749 762 * AJAX endpoint for Suggestions API lookups. 750 763 * 751 764 * @since 2.1.0 -
src/bp-activity/bp-activity-functions.php
3476 3476 do_action( 'bp_activity_mark_as_ham', $activity, $source ); 3477 3477 } 3478 3478 3479 /** Emails *******************************************************************/ 3480 3481 /** 3482 * Send email when a user is mentioned in an update. 3483 * 3484 * @since 1.2.0 3485 * 3486 * @uses bp_notifications_add_notification() 3487 * @uses bp_get_user_meta() 3488 * @uses bp_core_get_user_displayname() 3489 * @uses bp_activity_get_permalink() 3490 * @uses bp_core_get_user_domain() 3491 * @uses bp_get_settings_slug() 3492 * @uses bp_activity_filter_kses() 3493 * @uses bp_core_get_core_userdata() 3494 * @uses wp_specialchars_decode() 3495 * @uses get_blog_option() 3496 * @uses bp_is_active() 3497 * @uses bp_is_group() 3498 * @uses bp_get_current_group_name() 3499 * @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook. 3500 * @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook. 3501 * @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook. 3502 * @uses wp_mail() 3503 * @uses do_action() To call the 'bp_activity_sent_mention_email' hook. 3504 * 3505 * @param int $activity_id The ID of the activity update. 3506 * @param int $receiver_user_id The ID of the user who is receiving the update. 3507 */ 3508 function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) { 3509 $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' ); 3510 3511 // Don't leave multiple notifications for the same activity item. 3512 foreach( $notifications as $notification ) { 3513 if ( $activity_id == $notification->item_id ) { 3514 return; 3515 } 3516 } 3517 3518 $activity = new BP_Activity_Activity( $activity_id ); 3519 $email_type = 'activity-at-message'; 3520 $group_name = ''; 3521 $message_link = bp_activity_get_permalink( $activity_id ); 3522 $poster_name = bp_core_get_user_displayname( $activity->user_id ); 3523 3524 remove_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 3525 remove_filter( 'bp_get_activity_content_body', 'wpautop' ); 3526 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 3527 3528 /** This filter is documented in bp-activity/bp-activity-template.php */ 3529 $content = apply_filters( 'bp_get_activity_content_body', $activity->content ); 3530 3531 add_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 3532 add_filter( 'bp_get_activity_content_body', 'wpautop' ); 3533 add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 3534 3535 // Now email the user with the contents of the message (if they have enabled email notifications). 3536 if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) { 3537 if ( bp_is_active( 'groups' ) && bp_is_group() ) { 3538 $email_type = 'groups-at-message'; 3539 $group_name = bp_get_current_group_name(); 3540 } 3541 3542 $args = array( 3543 'tokens' => array( 3544 'activity' => $activity, 3545 'usermessage' => wp_strip_all_tags( $content ), 3546 'group.name' => $group_name, 3547 'mentioned.url' => $message_link, 3548 'poster.name' => $poster_name, 3549 'receiver-user.id' => $receiver_user_id, 3550 ), 3551 ); 3552 3553 bp_send_email( $email_type, $receiver_user_id, $args ); 3554 } 3555 3556 /** 3557 * Fires after the sending of an @mention email notification. 3558 * 3559 * @since 1.5.0 3560 * @since 2.5.0 $subject, $message, $content arguments unset and deprecated. 3561 * 3562 * @param BP_Activity_Activity $activity Activity Item object. 3563 * @param string $deprecated Removed in 2.5; now an empty string. 3564 * @param string $deprecated Removed in 2.5; now an empty string. 3565 * @param string $deprecated Removed in 2.5; now an empty string. 3566 * @param int $receiver_user_id The ID of the user who is receiving the update. 3567 */ 3568 do_action( 'bp_activity_sent_mention_email', $activity, '', '', '', $receiver_user_id ); 3569 } 3570 3571 /** 3572 * Send email when an activity item receives a comment. 3573 * 3574 * @since 1.2.0 3575 * @since 2.5.0 Updated to use new email APIs. 3576 * 3577 * @uses bp_get_user_meta() 3578 * @uses bp_core_get_user_displayname() 3579 * @uses bp_activity_get_permalink() 3580 * @uses bp_core_get_user_domain() 3581 * @uses bp_get_settings_slug() 3582 * @uses bp_activity_filter_kses() 3583 * @uses bp_core_get_core_userdata() 3584 * @uses wp_specialchars_decode() 3585 * @uses get_blog_option() 3586 * @uses bp_get_root_blog_id() 3587 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook. 3588 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook. 3589 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook. 3590 * @uses wp_mail() 3591 * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook. 3592 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook. 3593 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook. 3594 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook. 3595 * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook. 3596 * 3597 * @param int $comment_id The comment id. 3598 * @param int $commenter_id The ID of the user who posted the comment. 3599 * @param array $params {@link bp_activity_new_comment()}. 3600 */ 3601 function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) { 3602 $original_activity = new BP_Activity_Activity( $params['activity_id'] ); 3603 $poster_name = bp_core_get_user_displayname( $commenter_id ); 3604 $thread_link = bp_activity_get_permalink( $params['activity_id'] ); 3605 3606 remove_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 3607 remove_filter( 'bp_get_activity_content_body', 'wpautop' ); 3608 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 3609 3610 /** This filter is documented in bp-activity/bp-activity-template.php */ 3611 $content = apply_filters( 'bp_get_activity_content_body', $params['content'] ); 3612 3613 add_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 3614 add_filter( 'bp_get_activity_content_body', 'wpautop' ); 3615 add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 3616 3617 if ( $original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) { 3618 $args = array( 3619 'tokens' => array( 3620 'comment.id' => $comment_id, 3621 'commenter.id' => $commenter_id, 3622 'usermessage' => wp_strip_all_tags( $content ), 3623 'original_activity.user_id' => $original_activity->user_id, 3624 'poster.name' => $poster_name, 3625 'thread.url' => esc_url( $thread_link ), 3626 ), 3627 ); 3628 3629 bp_send_email( 'activity-comment', $original_activity->user_id, $args ); 3630 } 3631 3632 3633 /* 3634 * If this is a reply to another comment, send an email notification to the 3635 * author of the immediate parent comment. 3636 */ 3637 if ( empty( $params['parent_id'] ) || ( $params['activity_id'] == $params['parent_id'] ) ) { 3638 return; 3639 } 3640 3641 $parent_comment = new BP_Activity_Activity( $params['parent_id'] ); 3642 3643 if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) { 3644 $args = array( 3645 'tokens' => array( 3646 'comment.id' => $comment_id, 3647 'commenter.id' => $commenter_id, 3648 'usermessage' => wp_strip_all_tags( $content ), 3649 'parent-comment-user.id' => $parent_comment->user_id, 3650 'poster.name' => $poster_name, 3651 'thread.url' => esc_url( $thread_link ), 3652 ), 3653 ); 3654 3655 bp_send_email( 'activity-comment-author', $parent_comment->user_id, $args ); 3656 } 3657 } 3479 3658 3480 3659 /** Embeds *******************************************************************/ 3481 3660 -
src/bp-activity/bp-activity-notifications.php
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /* Emails *********************************************************************/14 15 13 /** 16 * Send email and BP notifications when a user is mentioned in an update. 17 * 18 * @since 1.2.0 19 * 20 * @uses bp_notifications_add_notification() 21 * @uses bp_get_user_meta() 22 * @uses bp_core_get_user_displayname() 23 * @uses bp_activity_get_permalink() 24 * @uses bp_core_get_user_domain() 25 * @uses bp_get_settings_slug() 26 * @uses bp_activity_filter_kses() 27 * @uses bp_core_get_core_userdata() 28 * @uses wp_specialchars_decode() 29 * @uses get_blog_option() 30 * @uses bp_is_active() 31 * @uses bp_is_group() 32 * @uses bp_get_current_group_name() 33 * @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook. 34 * @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook. 35 * @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook. 36 * @uses wp_mail() 37 * @uses do_action() To call the 'bp_activity_sent_mention_email' hook. 14 * Register screen notification actions with the Notifications component. 38 15 * 39 * @param int $activity_id The ID of the activity update. 40 * @param int $receiver_user_id The ID of the user who is receiving the update. 16 * @since 2.6.0 41 17 */ 42 function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) { 43 $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' ); 44 45 // Don't leave multiple notifications for the same activity item. 46 foreach( $notifications as $notification ) { 47 if ( $activity_id == $notification->item_id ) { 48 return; 49 } 50 } 51 52 $activity = new BP_Activity_Activity( $activity_id ); 53 $email_type = 'activity-at-message'; 54 $group_name = ''; 55 $message_link = bp_activity_get_permalink( $activity_id ); 56 $poster_name = bp_core_get_user_displayname( $activity->user_id ); 57 58 remove_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 59 remove_filter( 'bp_get_activity_content_body', 'wpautop' ); 60 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 61 62 /** This filter is documented in bp-activity/bp-activity-template.php */ 63 $content = apply_filters( 'bp_get_activity_content_body', $activity->content ); 64 65 add_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 66 add_filter( 'bp_get_activity_content_body', 'wpautop' ); 67 add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 68 69 // Now email the user with the contents of the message (if they have enabled email notifications). 70 if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) { 71 if ( bp_is_active( 'groups' ) && bp_is_group() ) { 72 $email_type = 'groups-at-message'; 73 $group_name = bp_get_current_group_name(); 74 } 75 76 $args = array( 77 'tokens' => array( 78 'activity' => $activity, 79 'usermessage' => wp_strip_all_tags( $content ), 80 'group.name' => $group_name, 81 'mentioned.url' => $message_link, 82 'poster.name' => $poster_name, 83 'receiver-user.id' => $receiver_user_id, 84 ), 85 ); 86 87 bp_send_email( $email_type, $receiver_user_id, $args ); 88 } 18 function bp_activity_register_notification_actions() { 19 // Set labels 20 bp_notifications_set_prop( 21 'settings_component_label', 22 _x( 'Activity', 'Settings > Notifications component label', 'buddypress' ), 23 'labels', 24 'activity' 25 ); 26 27 // Register actions. 28 bp_notifications_set_action( 'activity', array( 29 'action' => 'new_at_mention', 30 'settings_label' => sprintf( __( 'A member mentions you in an update using "@%s"', 'buddypress' ), bp_core_get_username( bp_displayed_user_id() ) ) 31 ) ); 89 32 90 33 /** 91 * Fires after the sending of an @mention email notification.34 * Fires after default activity notification actions are registered. 92 35 * 93 * @since 1.5.0 94 * @since 2.5.0 $subject, $message, $content arguments unset and deprecated. 95 * 96 * @param BP_Activity_Activity $activity Activity Item object. 97 * @param string $deprecated Removed in 2.5; now an empty string. 98 * @param string $deprecated Removed in 2.5; now an empty string. 99 * @param string $deprecated Removed in 2.5; now an empty string. 100 * @param int $receiver_user_id The ID of the user who is receiving the update. 36 * @since 2.6.0 101 37 */ 102 do_action( 'bp_activity_ sent_mention_email', $activity, '', '', '', $receiver_user_id);38 do_action( 'bp_activity_register_notification_actions' ); 103 39 } 104 40 105 41 /** 106 * Send email and BP notifications when an activity item receives a comment.107 *108 * @since 1.2.0109 * @since 2.5.0 Updated to use new email APIs.110 *111 * @uses bp_get_user_meta()112 * @uses bp_core_get_user_displayname()113 * @uses bp_activity_get_permalink()114 * @uses bp_core_get_user_domain()115 * @uses bp_get_settings_slug()116 * @uses bp_activity_filter_kses()117 * @uses bp_core_get_core_userdata()118 * @uses wp_specialchars_decode()119 * @uses get_blog_option()120 * @uses bp_get_root_blog_id()121 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_to' hook.122 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_subject' hook.123 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_message' hook.124 * @uses wp_mail()125 * @uses do_action() To call the 'bp_activity_sent_reply_to_update_email' hook.126 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_to' hook.127 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_subject' hook.128 * @uses apply_filters() To call the 'bp_activity_new_comment_notification_comment_author_message' hook.129 * @uses do_action() To call the 'bp_activity_sent_reply_to_reply_email' hook.130 *131 * @param int $comment_id The comment id.132 * @param int $commenter_id The ID of the user who posted the comment.133 * @param array $params {@link bp_activity_new_comment()}.134 */135 function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) {136 $original_activity = new BP_Activity_Activity( $params['activity_id'] );137 $poster_name = bp_core_get_user_displayname( $commenter_id );138 $thread_link = bp_activity_get_permalink( $params['activity_id'] );139 140 remove_filter( 'bp_get_activity_content_body', 'convert_smilies' );141 remove_filter( 'bp_get_activity_content_body', 'wpautop' );142 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );143 144 /** This filter is documented in bp-activity/bp-activity-template.php */145 $content = apply_filters( 'bp_get_activity_content_body', $params['content'] );146 147 add_filter( 'bp_get_activity_content_body', 'convert_smilies' );148 add_filter( 'bp_get_activity_content_body', 'wpautop' );149 add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );150 151 if ( $original_activity->user_id != $commenter_id && 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {152 $args = array(153 'tokens' => array(154 'comment.id' => $comment_id,155 'commenter.id' => $commenter_id,156 'usermessage' => wp_strip_all_tags( $content ),157 'original_activity.user_id' => $original_activity->user_id,158 'poster.name' => $poster_name,159 'thread.url' => esc_url( $thread_link ),160 ),161 );162 163 bp_send_email( 'activity-comment', $original_activity->user_id, $args );164 }165 166 167 /*168 * If this is a reply to another comment, send an email notification to the169 * author of the immediate parent comment.170 */171 if ( empty( $params['parent_id'] ) || ( $params['activity_id'] == $params['parent_id'] ) ) {172 return;173 }174 175 $parent_comment = new BP_Activity_Activity( $params['parent_id'] );176 177 if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id && 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) {178 $args = array(179 'tokens' => array(180 'comment.id' => $comment_id,181 'commenter.id' => $commenter_id,182 'usermessage' => wp_strip_all_tags( $content ),183 'parent-comment-user.id' => $parent_comment->user_id,184 'poster.name' => $poster_name,185 'thread.url' => esc_url( $thread_link ),186 ),187 );188 189 bp_send_email( 'activity-comment-author', $parent_comment->user_id, $args );190 }191 }192 193 /**194 * Helper method to map action arguments to function parameters.195 *196 * @since 1.9.0197 *198 * @param int $comment_id ID of the comment being notified about.199 * @param array $params Parameters to use with notification.200 */201 function bp_activity_new_comment_notification_helper( $comment_id, $params ) {202 bp_activity_new_comment_notification( $comment_id, $params['user_id'], $params );203 }204 add_action( 'bp_activity_comment_posted', 'bp_activity_new_comment_notification_helper', 10, 2 );205 206 /** Notifications *************************************************************/207 208 /**209 42 * Format notifications related to activity. 210 43 * 211 44 * @since 1.5.0 … … 317 150 * @param int $receiver_user_id ID of user receiving notification. 318 151 */ 319 152 function bp_activity_at_mention_add_notification( $activity, $subject, $message, $content, $receiver_user_id ) { 320 if ( bp_is_active( 'notifications' ) ) { 321 bp_notifications_add_notification( array( 322 'user_id' => $receiver_user_id, 323 'item_id' => $activity->id, 324 'secondary_item_id' => $activity->user_id, 325 'component_name' => buddypress()->activity->id, 326 'component_action' => 'new_at_mention', 327 'date_notified' => bp_core_current_time(), 328 'is_new' => 1, 329 ) ); 330 } 153 bp_notifications_add_notification( array( 154 'user_id' => $receiver_user_id, 155 'item_id' => $activity->id, 156 'secondary_item_id' => $activity->user_id, 157 'component_name' => buddypress()->activity->id, 158 'component_action' => 'new_at_mention', 159 'date_notified' => bp_core_current_time(), 160 'is_new' => 1, 161 ) ); 331 162 } 332 163 add_action( 'bp_activity_sent_mention_email', 'bp_activity_at_mention_add_notification', 10, 5 ); 333 164 … … 341 172 * @uses bp_notifications_mark_all_notifications_by_type() 342 173 */ 343 174 function bp_activity_remove_screen_notifications( $user_id = 0 ) { 344 if ( ! bp_is_active( 'notifications' ) ) {345 return;346 }347 348 175 // Only mark read if the current user is looking at his own mentions. 349 176 if ( empty( $user_id ) || (int) $user_id !== (int) bp_loggedin_user_id() ) { 350 177 return; … … 362 189 * @param BP_Activity_Activity $activity Activity object. 363 190 */ 364 191 function bp_activity_remove_screen_notifications_single_activity_permalink( $activity ) { 365 if ( ! bp_is_active( 'notifications' ) ) {366 return;367 }368 369 192 if ( ! is_user_logged_in() ) { 370 193 return; 371 194 } … … 385 208 function bp_activity_at_mention_delete_notification( $activity_ids_deleted = array() ) { 386 209 // Let's delete all without checking if content contains any mentions 387 210 // to avoid a query to get the activity. 388 if ( bp_is_active( 'notifications' ) &&! empty( $activity_ids_deleted ) ) {211 if ( ! empty( $activity_ids_deleted ) ) { 389 212 foreach ( $activity_ids_deleted as $activity_id ) { 390 213 bp_notifications_delete_all_notifications_by_type( $activity_id, buddypress()->activity->id ); 391 214 } -
src/bp-activity/classes/class-bp-activity-component.php
55 55 'filters', 56 56 'template', 57 57 'functions', 58 'notifications',59 58 'cache' 60 59 ); 61 60 61 // Notifications support. 62 if ( bp_is_active( 'notifications' ) ) { 63 $includes[] = 'notifications'; 64 } 65 62 66 if ( ! buddypress()->do_autoload ) { 63 67 $includes[] = 'classes'; 64 68 } … … 117 121 'has_directory' => true, 118 122 'directory_title' => _x( 'Site-Wide Activity', 'component directory title', 'buddypress' ), 119 123 'notification_callback' => 'bp_activity_format_notifications', 124 'notification_action_callback' => 'bp_activity_register_notification_actions', 120 125 'search_string' => __( 'Search Activity...', 'buddypress' ), 121 126 'global_tables' => $global_tables, 122 127 'meta_tables' => $meta_tables, -
src/bp-core/classes/class-bp-component.php
205 205 * Set up component global variables. 206 206 * 207 207 * @since 1.5.0 208 * @since 2.6.0 Added 'notification_action_callback' parameter to $args. 208 209 * 209 210 * @uses apply_filters() Calls 'bp_{@link bp_Component::name}_id'. 210 211 * @uses apply_filters() Calls 'bp_{@link bp_Component::name}_slug'. … … 223 224 * 'Search Groups...'. 224 225 * @type array $global_tables Optional. An array of database table names. 225 226 * @type array $meta_tables Optional. An array of metadata table names. 227 * @type callable $notification_action_callback Optional. The callable function that registers the component's 228 * notification actions. 226 229 * } 227 230 */ 228 231 public function setup_globals( $args = array() ) { … … 235 238 $default_root_slug = isset( buddypress()->pages->{$this->id}->slug ) ? buddypress()->pages->{$this->id}->slug : ''; 236 239 237 240 $r = wp_parse_args( $args, array( 238 'slug' => $this->id, 239 'root_slug' => $default_root_slug, 240 'has_directory' => false, 241 'directory_title' => '', 242 'notification_callback' => '', 243 'search_string' => '', 244 'global_tables' => '', 245 'meta_tables' => '', 241 'slug' => $this->id, 242 'root_slug' => $default_root_slug, 243 'has_directory' => false, 244 'directory_title' => '', 245 'notification_callback' => '', 246 'notification_action_callback' => '', 247 'search_string' => '', 248 'global_tables' => '', 249 'meta_tables' => '', 246 250 ) ); 247 251 248 252 /** … … 252 256 * 253 257 * @param string $value Slug to use in permalink URI chunk. 254 258 */ 255 $this->slug 259 $this->slug = apply_filters( 'bp_' . $this->id . '_slug', $r['slug'] ); 256 260 257 261 /** 258 262 * Filters the slug used for root directory. … … 261 265 * 262 266 * @param string $value Root directory slug. 263 267 */ 264 $this->root_slug 268 $this->root_slug = apply_filters( 'bp_' . $this->id . '_root_slug', $r['root_slug'] ); 265 269 266 270 /** 267 271 * Filters the component's top-level directory if available. … … 270 274 * 271 275 * @param bool $value Whether or not there is a top-level directory. 272 276 */ 273 $this->has_directory 277 $this->has_directory = apply_filters( 'bp_' . $this->id . '_has_directory', $r['has_directory'] ); 274 278 275 279 /** 276 280 * Filters the component's directory title. … … 279 283 * 280 284 * @param string $value Title to use for the directory. 281 285 */ 282 $this->directory_title 286 $this->directory_title = apply_filters( 'bp_' . $this->id . '_directory_title', $r['directory_title'] ); 283 287 284 288 /** 285 289 * Filters the placeholder text for search inputs for component. … … 288 292 * 289 293 * @param string $value Name to use in search input placeholders. 290 294 */ 291 $this->search_string 295 $this->search_string = apply_filters( 'bp_' . $this->id . '_search_string', $r['search_string'] ); 292 296 293 297 /** 294 298 * Filters the callable function that formats the component's notifications. … … 299 303 */ 300 304 $this->notification_callback = apply_filters( 'bp_' . $this->id . '_notification_callback', $r['notification_callback'] ); 301 305 306 /** 307 * Filters the callable function that registers the component's notification actions. 308 * 309 * @since 2.6.0 310 * 311 * @param string $value Function callback. 312 */ 313 $this->notification_action_callback = apply_filters( 'bp_' . $this->id . '_notification_action_callback', $r['notification_action_callback'] ); 314 302 315 // Set the global table names, if applicable. 303 316 if ( ! empty( $r['global_tables'] ) ) { 304 317 $this->register_global_tables( $r['global_tables'] ); -
src/bp-forums/bp-forums-loader.php
70 70 'slug' => BP_FORUMS_SLUG, 71 71 'root_slug' => isset( $bp->pages->forums->slug ) ? $bp->pages->forums->slug : BP_FORUMS_SLUG, 72 72 'has_directory' => true, 73 'notification_callback' => 'messages_format_notifications',74 73 'search_string' => __( 'Search Forums...', 'buddypress' ), 75 74 ); 76 75 -
src/bp-friends/bp-friends-functions.php
795 795 ) ); 796 796 } 797 797 add_action( 'bp_activity_mentions_prime_results', 'bp_friends_prime_mentions_results' ); 798 799 /** Emails ********************************************************************/ 800 801 /** 802 * Send an email after a friendship request is requested. 803 * 804 * When a friendship is requested, an email is sent to the user of whom 805 * friendship has been requested ($friend_id). 806 * 807 * @since 1.0 808 * 809 * @param int $friendship_id ID of the friendship object. 810 * @param int $initiator_id ID of the user who initiated the request. 811 * @param int $friend_id ID of the request recipient. 812 */ 813 function friends_notification_new_request( $friendship_id, $initiator_id, $friend_id ) { 814 if ( 'no' == bp_get_user_meta( (int) $friend_id, 'notification_friends_friendship_request', true ) ) { 815 return; 816 } 817 818 $args = array( 819 'tokens' => array( 820 'friend-requests.url' => esc_url( bp_core_get_user_domain( $friend_id ) . bp_get_friends_slug() . '/requests/' ), 821 'friend.id' => $friend_id, 822 'friendship.id' => $friendship_id, 823 'initiator.id' => $initiator_id, 824 'initiator.url' => esc_url( bp_core_get_user_domain( $initiator_id ) ), 825 'initiator.name' => bp_core_get_user_displayname( $initiator_id ), 826 ), 827 ); 828 bp_send_email( 'friends-request', $friend_id, $args ); 829 } 830 add_action( 'friends_friendship_requested', 'friends_notification_new_request', 10, 3 ); 831 832 /** 833 * Send an email after a friendship request is accepted. 834 * 835 * When a friendship request is accepted, an email is sent to the user who 836 * requested the friendship ($initiator_id). 837 * 838 * @since 1.0 839 * 840 * @param int $friendship_id ID of the friendship object. 841 * @param int $initiator_id ID of the user who initiated the request. 842 * @param int $friend_id ID of the request recipient. 843 */ 844 function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) { 845 if ( 'no' == bp_get_user_meta( (int) $initiator_id, 'notification_friends_friendship_accepted', true ) ) { 846 return; 847 } 848 849 $args = array( 850 'tokens' => array( 851 'friend.id' => $friend_id, 852 'friendship.url' => esc_url( bp_core_get_user_domain( $friend_id ) ), 853 'friend.name' => bp_core_get_user_displayname( $friend_id ), 854 'friendship.id' => $friendship_id, 855 'initiator.id' => $initiator_id, 856 ), 857 ); 858 bp_send_email( 'friends-request-accepted', $initiator_id, $args ); 859 } 860 add_action( 'friends_friendship_accepted', 'friends_notification_accepted_request', 10, 3 ); -
src/bp-friends/bp-friends-notifications.php
13 13 // Exit if accessed directly. 14 14 defined( 'ABSPATH' ) || exit; 15 15 16 /** Emails ********************************************************************/17 18 16 /** 19 * Send notifications related to a new friendship request. 20 * 21 * When a friendship is requested, an email and a BP notification are sent to 22 * the user of whom friendship has been requested ($friend_id). 17 * Register screen notification actions with the Notifications component. 23 18 * 24 * @since 1.0.0 25 * 26 * @param int $friendship_id ID of the friendship object. 27 * @param int $initiator_id ID of the user who initiated the request. 28 * @param int $friend_id ID of the request recipient. 19 * @since 2.6.0 29 20 */ 30 function friends_notification_new_request( $friendship_id, $initiator_id, $friend_id ) { 31 if ( 'no' == bp_get_user_meta( (int) $friend_id, 'notification_friends_friendship_request', true ) ) { 32 return; 33 } 34 35 $args = array( 36 'tokens' => array( 37 'friend-requests.url' => esc_url( bp_core_get_user_domain( $friend_id ) . bp_get_friends_slug() . '/requests/' ), 38 'friend.id' => $friend_id, 39 'friendship.id' => $friendship_id, 40 'initiator.id' => $initiator_id, 41 'initiator.url' => esc_url( bp_core_get_user_domain( $initiator_id ) ), 42 'initiator.name' => bp_core_get_user_displayname( $initiator_id ), 43 ), 21 function bp_friends_register_notification_actions() { 22 // Set labels 23 bp_notifications_set_prop( 24 'settings_component_label', 25 _x( 'Friends', 'Settings > Notifications component label', 'buddypress' ), 26 'labels', 27 'friends' 44 28 ); 45 bp_send_email( 'friends-request', $friend_id, $args );46 }47 add_action( 'friends_friendship_requested', 'friends_notification_new_request', 10, 3 );48 29 49 /** 50 * Send notifications related to the acceptance of a friendship request. 51 * 52 * When a friendship request is accepted, an email and a BP notification are 53 * sent to the user who requested the friendship ($initiator_id). 54 * 55 * @since 1.0.0 56 * 57 * @param int $friendship_id ID of the friendship object. 58 * @param int $initiator_id ID of the user who initiated the request. 59 * @param int $friend_id ID of the request recipient. 60 */ 61 function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) { 62 if ( 'no' == bp_get_user_meta( (int) $initiator_id, 'notification_friends_friendship_accepted', true ) ) { 63 return; 64 } 30 // Register actions. 31 bp_notifications_set_action( 'friends', array( 32 'action' => 'friendship_requested', 33 'settings_label' => __( 'A member sends you a friendship request', 'buddypress' ) 34 ) ); 65 35 66 $args = array( 67 'tokens' => array( 68 'friend.id' => $friend_id, 69 'friendship.url' => esc_url( bp_core_get_user_domain( $friend_id ) ), 70 'friend.name' => bp_core_get_user_displayname( $friend_id ), 71 'friendship.id' => $friendship_id, 72 'initiator.id' => $initiator_id, 73 ), 74 ); 75 bp_send_email( 'friends-request-accepted', $initiator_id, $args ); 76 } 77 add_action( 'friends_friendship_accepted', 'friends_notification_accepted_request', 10, 3 ); 36 bp_notifications_set_action( 'friends', array( 37 'action' => 'friendship_accepted', 38 'settings_label' => __( 'A member accepts your friendship request', 'buddypress' ) 39 ) ); 78 40 79 /** Notifications *************************************************************/ 41 /** 42 * Fires after default friend notification actions are registered. 43 * 44 * @since 2.6.0 45 */ 46 do_action( 'bp_friends_register_notification_actions' ); 47 } 80 48 81 49 /** 82 50 * Notification formatting callback for bp-friends notifications. … … 182 150 * @since 1.2.0 183 151 */ 184 152 function friends_clear_friend_notifications() { 185 if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' )) {153 if ( isset( $_GET['new'] ) ) { 186 154 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' ); 187 155 } 188 156 } … … 194 162 * @since 1.9.0 195 163 */ 196 164 function bp_friends_mark_friendship_request_notifications_by_type() { 197 if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' )) {165 if ( isset( $_GET['new'] ) ) { 198 166 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' ); 199 167 } 200 168 } … … 206 174 * @since 1.9.0 207 175 */ 208 176 function bp_friends_mark_friendship_accepted_notifications_by_type() { 209 if ( bp_is_active( 'notifications' ) ) { 210 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' ); 211 } 177 bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' ); 212 178 } 213 179 add_action( 'friends_screen_my_friends', 'bp_friends_mark_friendship_accepted_notifications_by_type' ); 214 180 … … 222 188 * @param int $friend_user_id The friendship request receiver user ID. 223 189 */ 224 190 function bp_friends_friendship_requested_notification( $friendship_id, $initiator_user_id, $friend_user_id ) { 225 if ( bp_is_active( 'notifications' ) ) { 226 bp_notifications_add_notification( array( 227 'user_id' => $friend_user_id, 228 'item_id' => $initiator_user_id, 229 'secondary_item_id' => $friendship_id, 230 'component_name' => buddypress()->friends->id, 231 'component_action' => 'friendship_request', 232 'date_notified' => bp_core_current_time(), 233 'is_new' => 1, 234 ) ); 235 } 191 bp_notifications_add_notification( array( 192 'user_id' => $friend_user_id, 193 'item_id' => $initiator_user_id, 194 'secondary_item_id' => $friendship_id, 195 'component_name' => buddypress()->friends->id, 196 'component_action' => 'friendship_request', 197 'date_notified' => bp_core_current_time(), 198 'is_new' => 1, 199 ) ); 236 200 } 237 201 add_action( 'friends_friendship_requested', 'bp_friends_friendship_requested_notification', 10, 3 ); 238 202 … … 245 209 * @param object $friendship Friendship object. 246 210 */ 247 211 function bp_friends_mark_friendship_rejected_notifications_by_item_id( $friendship_id, $friendship ) { 248 if ( bp_is_active( 'notifications' ) ) { 249 bp_notifications_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 250 } 212 bp_notifications_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 251 213 } 252 214 add_action( 'friends_friendship_rejected', 'bp_friends_mark_friendship_rejected_notifications_by_item_id', 10, 2 ); 253 215 … … 261 223 * @param int $friend_user_id The friendship request receiver user ID. 262 224 */ 263 225 function bp_friends_add_friendship_accepted_notification( $friendship_id, $initiator_user_id, $friend_user_id ) { 264 265 // Bail if notifications is not active.266 if ( ! bp_is_active( 'notifications' ) ) {267 return;268 }269 270 226 // Remove the friend request notice. 271 227 bp_notifications_mark_notifications_by_item_id( $friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 272 228 … … 292 248 * @param object $friendship Friendship Object. 293 249 */ 294 250 function bp_friends_mark_friendship_withdrawn_notifications_by_item_id( $friendship_id, $friendship ) { 295 if ( bp_is_active( 'notifications' ) ) { 296 bp_notifications_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 297 } 251 bp_notifications_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' ); 298 252 } 299 253 add_action( 'friends_friendship_withdrawn', 'bp_friends_mark_friendship_withdrawn_notifications_by_item_id', 10, 2 ); 300 254 … … 306 260 * @param int $user_id ID of the user whose notifications are removed. 307 261 */ 308 262 function bp_friends_remove_notifications_data( $user_id = 0 ) { 309 if ( bp_is_active( 'notifications' ) ) { 310 bp_notifications_delete_notifications_from_user( $user_id, buddypress()->friends->id, 'friendship_request' ); 311 } 263 bp_notifications_delete_notifications_from_user( $user_id, buddypress()->friends->id, 'friendship_request' ); 312 264 } 313 265 add_action( 'friends_remove_data', 'bp_friends_remove_notifications_data', 10, 1 ); -
src/bp-friends/classes/class-bp-friends-component.php
53 53 'activity', 54 54 'template', 55 55 'functions', 56 'notifications',57 56 'widgets', 58 57 ); 59 58 59 // Conditional includes. 60 if ( bp_is_active( 'notifications' ) ) { 61 $includes[] = 'notifications'; 62 } 63 60 64 if ( ! buddypress()->do_autoload ) { 61 65 $includes[] = 'classes'; 62 66 } … … 103 107 'has_directory' => false, 104 108 'search_string' => __( 'Search Friends...', 'buddypress' ), 105 109 'notification_callback' => 'friends_format_notifications', 106 'global_tables' => $global_tables 110 'notification_action_callback' => 'bp_friends_register_notification_actions', 111 'global_tables' => $global_tables 107 112 ); 108 113 109 114 parent::setup_globals( $args ); -
src/bp-groups/bp-groups-notifications.php
294 294 /** Notifications *************************************************************/ 295 295 296 296 /** 297 * Register screen notification actions with the Notifications component. 298 * 299 * @since 2.6.0 300 */ 301 function bp_groups_register_notification_actions() { 302 // Set labels 303 bp_notifications_set_prop( 304 'settings_component_label', 305 _x( 'Groups', 'Settings > Notifications component label', 'buddypress' ), 306 'labels', 307 'groups' 308 ); 309 310 // Register actions. 311 bp_notifications_set_action( 'groups', array( 312 'action' => 'group_invite', 313 'settings_label' => __( 'A member invites you to join a group', 'buddypress' ) 314 ) ); 315 316 bp_notifications_set_action( 'groups', array( 317 'action' => 'member_promoted_to_admin', 318 'settings_label' => __( 'You are promoted to a group administrator', 'buddypress' ) 319 ) ); 320 321 bp_notifications_set_action( 'groups', array( 322 'action' => 'member_promoted_to_mod', 323 'settings_label' => __( 'You are promoted to a group moderator', 'buddypress' ) 324 ) ); 325 326 bp_notifications_set_action( 'groups', array( 327 'action' => 'new_membership_request', 328 'settings_label' => __( 'A member requests to join a private group for which you are an admin', 'buddypress' ) 329 ) ); 330 331 bp_notifications_set_action( 'groups', array( 332 'action' => 'membership_request_accepted', 333 'settings_label' => __( 'Your group membership request is accepted', 'buddypress' ) 334 ) ); 335 336 bp_notifications_set_action( 'groups', array( 337 'action' => 'membership_request_rejected', 338 'settings_label' => __( 'Your group membership request is declined', 'buddypress' ) 339 ) ); 340 341 /** 342 * Fires after default friend notification actions are registered. 343 * 344 * @since 2.6.0 345 */ 346 do_action( 'bp_groups_register_notification_actions' ); 347 } 348 349 /** 297 350 * Format notifications for the Groups component. 298 351 * 299 352 * @since 1.0.0 -
src/bp-groups/classes/class-bp-groups-component.php
166 166 'has_directory' => true, 167 167 'directory_title' => _x( 'Groups', 'component directory title', 'buddypress' ), 168 168 'notification_callback' => 'groups_format_notifications', 169 'search_string' => _x( 'Search Groups...', 'Component directory search', 'buddypress' ), 170 'global_tables' => $global_tables, 171 'meta_tables' => $meta_tables, 169 'notification_action_callback' => 'bp_groups_register_notification_actions', 170 'search_string' => _x( 'Search Groups...', 'Component directory search', 'buddypress' ), 171 'global_tables' => $global_tables, 172 'meta_tables' => $meta_tables, 172 173 ); 173 174 174 175 parent::setup_globals( $args ); -
src/bp-messages/bp-messages-functions.php
524 524 525 525 return $retval; 526 526 } 527 528 /** Email *********************************************************************/ 529 530 /** 531 * Email message recipients to alert them of a new unread private message. 532 * 533 * @since 1.0.0 534 * 535 * @param array|BP_Messages_Message $raw_args { 536 * Array of arguments. Also accepts a BP_Messages_Message object. 537 * @type array $recipients User IDs of recipients. 538 * @type string $email_subject Subject line of message. 539 * @type string $email_content Content of message. 540 * @type int $sender_id User ID of sender. 541 * } 542 */ 543 function messages_notification_new_message( $raw_args = array() ) { 544 if ( is_object( $raw_args ) ) { 545 $args = (array) $raw_args; 546 } else { 547 $args = $raw_args; 548 } 549 550 // These should be extracted below. 551 $recipients = array(); 552 $email_subject = $email_content = ''; 553 $sender_id = 0; 554 555 // Barf. 556 extract( $args ); 557 558 if ( empty( $recipients ) ) { 559 return; 560 } 561 562 $sender_name = bp_core_get_user_displayname( $sender_id ); 563 564 // Send an email to each recipient. 565 foreach ( $recipients as $recipient ) { 566 if ( $sender_id == $recipient->user_id || 'no' == bp_get_user_meta( $recipient->user_id, 'notification_messages_new_message', true ) ) { 567 continue; 568 } 569 570 // User data and links. 571 $ud = get_userdata( $recipient->user_id ); 572 if ( empty( $ud ) ) { 573 continue; 574 } 575 576 $args = array( 577 'tokens' => array( 578 'usermessage' => wp_strip_all_tags( $message ), 579 'message.url' => esc_url( bp_core_get_user_domain( $recipient->user_id ) . bp_get_messages_slug() . '/' ), 580 'sender.name' => $sender_name, 581 'usersubject' => sanitize_text_field( $subject ), 582 ), 583 ); 584 bp_send_email( 'messages-unread', $ud, $args ); 585 } 586 587 /** 588 * Fires after the sending of a new message email notification. 589 * 590 * @since 1.5.0 591 * @deprecated 2.5.0 Use the filters in BP_Email. 592 * $email_subject and $email_content arguments unset and deprecated. 593 * 594 * @param array $recipients User IDs of recipients. 595 * @param string $email_subject Deprecated in 2.5; now an empty string. 596 * @param string $email_content Deprecated in 2.5; now an empty string. 597 * @param array $args Array of originally provided arguments. 598 */ 599 do_action( 'bp_messages_sent_notification_email', $recipients, '', '', $args ); 600 } 601 add_action( 'messages_message_sent', 'messages_notification_new_message', 10 ); -
src/bp-messages/bp-messages-notifications.php
10 10 // Exit if accessed directly. 11 11 defined( 'ABSPATH' ) || exit; 12 12 13 /** Email *********************************************************************/14 15 13 /** 16 * Email message recipients to alert them of a new unread private message. 17 * 18 * @since 1.0.0 14 * Register screen notification actions with the Notifications component. 19 15 * 20 * @param array|BP_Messages_Message $raw_args { 21 * Array of arguments. Also accepts a BP_Messages_Message object. 22 * @type array $recipients User IDs of recipients. 23 * @type string $email_subject Subject line of message. 24 * @type string $email_content Content of message. 25 * @type int $sender_id User ID of sender. 26 * } 16 * @since 2.6.0 27 17 */ 28 function messages_notification_new_message( $raw_args = array() ) { 29 if ( is_object( $raw_args ) ) { 30 $args = (array) $raw_args; 31 } else { 32 $args = $raw_args; 33 } 34 35 // These should be extracted below. 36 $recipients = array(); 37 $email_subject = $email_content = ''; 38 $sender_id = 0; 39 40 // Barf. 41 extract( $args ); 42 43 if ( empty( $recipients ) ) { 44 return; 45 } 46 47 $sender_name = bp_core_get_user_displayname( $sender_id ); 48 49 // Send an email to each recipient. 50 foreach ( $recipients as $recipient ) { 51 if ( $sender_id == $recipient->user_id || 'no' == bp_get_user_meta( $recipient->user_id, 'notification_messages_new_message', true ) ) { 52 continue; 53 } 54 55 // User data and links. 56 $ud = get_userdata( $recipient->user_id ); 57 if ( empty( $ud ) ) { 58 continue; 59 } 60 61 $args = array( 62 'tokens' => array( 63 'usermessage' => wp_strip_all_tags( stripslashes( $message ) ), 64 'message.url' => esc_url( bp_core_get_user_domain( $recipient->user_id ) . bp_get_messages_slug() . '/view/' . $thread_id . '/' ), 65 'sender.name' => $sender_name, 66 'usersubject' => sanitize_text_field( stripslashes( $subject ) ), 67 ), 68 ); 69 bp_send_email( 'messages-unread', $ud, $args ); 70 } 18 function bp_messages_register_notification_actions() { 19 // Set labels 20 bp_notifications_set_prop( 21 'settings_component_label', 22 _x( 'Messages', 'Settings > Notifications component label', 'buddypress' ), 23 'labels', 24 'messages' 25 ); 26 27 // Register actions. 28 bp_notifications_set_action( 'messages', array( 29 'action' => 'new_message', 30 'settings_label' => __( 'A member sends you a new message', 'buddypress' ) 31 ) ); 71 32 72 33 /** 73 * Fires after the sending of a new message email notification. 74 * 75 * @since 1.5.0 76 * @deprecated 2.5.0 Use the filters in BP_Email. 77 * $email_subject and $email_content arguments unset and deprecated. 34 * Fires after default message notification actions are registered. 78 35 * 79 * @param array $recipients User IDs of recipients. 80 * @param string $email_subject Deprecated in 2.5; now an empty string. 81 * @param string $email_content Deprecated in 2.5; now an empty string. 82 * @param array $args Array of originally provided arguments. 36 * @since 2.6.0 83 37 */ 84 do_action( 'bp_messages_ sent_notification_email', $recipients, '', '', $args);38 do_action( 'bp_messages_register_notification_actions' ); 85 39 } 86 add_action( 'messages_message_sent', 'messages_notification_new_message', 10 );87 88 /** Notifications *************************************************************/89 40 90 41 /** 91 42 * Format notifications for the Messages component. … … 181 132 * @param BP_Messages_Message $message Message object. 182 133 */ 183 134 function bp_messages_message_sent_add_notification( $message ) { 184 if ( bp_is_active( 'notifications' ) &&! empty( $message->recipients ) ) {135 if ( ! empty( $message->recipients ) ) { 185 136 foreach ( (array) $message->recipients as $recipient ) { 186 137 bp_notifications_add_notification( array( 187 138 'user_id' => $recipient->user_id, … … 203 154 * @since 1.9.0 204 155 */ 205 156 function bp_messages_screen_conversation_mark_notifications() { 206 if ( bp_is_active( 'notifications' ) ) { 207 global $thread_template; 208 209 // Get unread PM notifications for the user. 210 $new_pm_notifications = BP_Notifications_Notification::get( array( 211 'user_id' => bp_loggedin_user_id(), 212 'component_name' => buddypress()->messages->id, 213 'component_action' => 'new_message', 214 'is_new' => 1, 215 ) ); 216 $unread_message_ids = wp_list_pluck( $new_pm_notifications, 'item_id' ); 217 218 // No unread PMs, so stop! 219 if ( empty( $unread_message_ids ) ) { 220 return; 221 } 157 global $thread_template; 158 159 // Get unread PM notifications for the user. 160 $new_pm_notifications = BP_Notifications_Notification::get( array( 161 'user_id' => bp_loggedin_user_id(), 162 'component_name' => buddypress()->messages->id, 163 'component_action' => 'new_message', 164 'is_new' => 1, 165 ) ); 166 $unread_message_ids = wp_list_pluck( $new_pm_notifications, 'item_id' ); 167 168 // No unread PMs, so stop! 169 if ( empty( $unread_message_ids ) ) { 170 return; 171 } 222 172 223 224 173 // Get the unread message ids for this thread only. 174 $message_ids = array_intersect( $unread_message_ids, wp_list_pluck( $thread_template->thread->messages, 'id' ) ); 225 175 226 // Mark each notification for each PM message as read. 227 foreach ( $message_ids as $message_id ) { 228 bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), (int) $message_id, buddypress()->messages->id, 'new_message' ); 229 } 176 // Mark each notification for each PM message as read. 177 foreach ( $message_ids as $message_id ) { 178 bp_notifications_mark_notifications_by_item_id( bp_loggedin_user_id(), (int) $message_id, buddypress()->messages->id, 'new_message' ); 230 179 } 231 180 } 232 181 add_action( 'thread_loop_start', 'bp_messages_screen_conversation_mark_notifications', 10 ); … … 240 189 * @param array $message_ids IDs of the messages. 241 190 */ 242 191 function bp_messages_message_delete_notifications( $thread_id, $message_ids ) { 243 if ( ! bp_is_active( 'notifications' ) ) {244 return;245 }246 247 192 // For each recipient, delete notifications corresponding to each message. 248 193 $thread = new BP_Messages_Thread( $thread_id ); 249 194 foreach ( $thread->get_recipients() as $recipient ) { -
src/bp-messages/classes/class-bp-messages-component.php
63 63 'filters', 64 64 'template', 65 65 'functions', 66 'notifications',67 66 'widgets', 68 67 ); 69 68 … … 72 71 } 73 72 74 73 // Conditional includes. 74 if ( bp_is_active( 'notifications' ) ) { 75 $includes[] = 'notifications'; 76 } 75 77 if ( bp_is_active( $this->id, 'star' ) ) { 76 78 $includes[] = 'star'; 77 79 } … … 118 120 'slug' => BP_MESSAGES_SLUG, 119 121 'has_directory' => false, 120 122 'notification_callback' => 'messages_format_notifications', 121 'search_string' => __( 'Search Messages...', 'buddypress' ), 122 'global_tables' => $global_tables, 123 'meta_tables' => $meta_tables 123 'notification_action_callback' => 'bp_messages_register_notification_actions', 124 'search_string' => __( 'Search Messages...', 'buddypress' ), 125 'global_tables' => $global_tables, 126 'meta_tables' => $meta_tables 124 127 ) ); 125 128 } 126 129 -
src/bp-notifications/bp-notifications-functions.php
63 63 } 64 64 } 65 65 66 // See if the user has disabled notifications for this component or action. 67 if ( bp_is_active( 'settings' ) ) { 68 // Eek. 69 // @see https://buddypress.trac.wordpress.org/ticket/6663#comment:4 70 if ( 'profile' === $r['component_name'] && bp_is_active( 'xprofile' ) ) { 71 $r['component_name'] = 'xprofile'; 72 } 73 74 $did_user_disable_component = bp_get_user_meta( $r['user_id'], "notifications_{$r['component_name']}_enabled", true ); 75 if ( '' !== $did_user_disable_component && 0 == $did_user_disable_component ) { 76 return false; 77 } 78 79 $did_user_disable_action = bp_get_user_meta( $r['user_id'], "notifications_{$r['component_name']}_{$r['component_action']}_enabled", true ); 80 if ( '' !== $did_user_disable_action && 0 == $did_user_disable_action ) { 81 return false; 82 } 83 } 84 66 85 // Setup the new notification. 67 86 $notification = new BP_Notifications_Notification; 68 87 $notification->user_id = $r['user_id']; … … 622 641 623 642 // Loop through components, look for callbacks, add to return value. 624 643 foreach ( $active_components as $component ) { 625 if ( !empty( $bp->$component->notification_callback ) ) {644 if ( !empty( $bp->$component->notification_callback ) && is_callable( $bp->$component->notification_callback ) ) { 626 645 $component_names[] = $component; 627 646 } 628 647 // The extended profile component is identified in the active_components array as 'xprofile'. … … 643 662 return apply_filters( 'bp_notifications_get_registered_components', $component_names, $active_components ); 644 663 } 645 664 665 /** 666 * Initialize registered notification actions. 667 * 668 * This loops through each component to fetch registered notification actions. 669 * This function is designed to be run when you need to fetch these actions in 670 * your code. 671 * 672 * @since 2.6.0 673 */ 674 function bp_notifications_init_registered_actions() { 675 // Load BuddyPress. 676 $bp = buddypress(); 677 678 // We've already done this! 679 if ( ! empty( $bp->notifications->actions ) ) { 680 return; 681 } 682 683 // Setup return value. 684 $component_names = array(); 685 686 // Get the active components. 687 $active_components = array_keys( $bp->active_components ); 688 689 // Loop through components, look for callbacks and run them. 690 foreach ( $active_components as $component ) { 691 // The extended profile component is identified in the active_components array as 'xprofile'. 692 // However, the extended profile child object has the key 'profile' in the $bp global. 693 if ( 'xprofile' == $component ) { 694 $component = 'profile'; 695 } 696 697 if ( ! empty( $bp->$component->notification_action_callback ) && is_callable( $bp->$component->notification_action_callback ) ) { 698 call_user_func( $bp->$component->notification_action_callback ); 699 } 700 } 701 } 702 703 /** 704 * Register a notification action. 705 * 706 * Used primarily to output a user's "Settings > Notifications" page, but 707 * could be used for other things. 708 * 709 * You should run this function after 'bp_setup_globals'. 710 * 711 * @since 2.6.0 712 * 713 * @param array $args { 714 * Array of arguments to register for the notification action. 715 * @type string $action The action name. 716 * @type string $settings_label The label for the action. Used on a user's Settings page. 717 * } 718 * @param string $component The component that the action belongs to. 719 * @return bool 720 */ 721 function bp_notifications_set_action( $component = '', $args = array() ) { 722 if ( ! did_action( 'bp_setup_globals' ) ) { 723 _doing_it_wrong( __FUNCTION__, "Function must be called after the 'bp_setup_globals' hook." ); 724 return false; 725 } 726 727 if ( empty( $component ) || empty( $args ) ) { 728 return false; 729 } 730 731 if ( ! isset( buddypress()->$component->notification_callback ) ) { 732 return false; 733 } 734 735 $action = $args['action']; 736 unset( $args['action'] ); 737 738 if ( isset( buddypress()->notifications->actions[$component][$action] ) ) { 739 return false; 740 } 741 742 buddypress()->notifications->actions[$component][$action] = $args; 743 744 return true; 745 } 746 747 /** 748 * Set an arbitrary value in the buddypress()->notifications object. 749 * 750 * Useful for devs to stash various items. 751 * 752 * @since 2.6.0 753 * 754 * @param string $prop The property name. 755 * @param mixed $value The value to set for the property. 756 * @param string $object The object this property should be assigned to. Optional. 757 * @param string $component The component attached with this property. Optional. 758 * If filled in, this will prefix the $prop name. 759 * @return bool 760 */ 761 function bp_notifications_set_prop( $prop = '', $value = '', $object = '', $component = '' ) { 762 if ( ! did_action( 'bp_setup_globals' ) ) { 763 _doing_it_wrong( __FUNCTION__, "Function must be called after the 'bp_setup_globals' hook." ); 764 return false; 765 } 766 767 if ( empty( $prop ) || empty( $value ) ) { 768 return false; 769 } 770 771 if ( ! empty( $component ) ) { 772 $prop = "{$component}_{$prop}"; 773 } 774 775 $prop = sanitize_key( $prop ); 776 $object = sanitize_key( $object ); 777 778 if ( ! empty( $object ) ) { 779 if ( empty( buddypress()->notifications->$object ) ) { 780 buddypress()->notifications->$object = new stdClass; 781 } 782 783 buddypress()->notifications->$object->$prop = $value; 784 } else { 785 buddypress()->notifications->$prop = $value; 786 } 787 788 return true; 789 } 790 791 646 792 /** Meta **********************************************************************/ 647 793 648 794 /** -
src/bp-notifications/bp-notifications-screens.php
68 68 * @since 1.9.0 69 69 */ 70 70 function bp_notifications_screen_settings() { 71 // Add hook to display notification content. 72 add_action( 'bp_template_content', 'bp_notifications_screen_content' ); 71 73 74 /** 75 * Fires right before the loading of the settings screen notifications screen template file. 76 * 77 * @since 2.6.0 78 */ 79 do_action( 'bp_notifications_screen_settings' ); 80 81 /** 82 * Filters the template to load for the Notifications settings screen. 83 * 84 * @since 2.6.0 85 * 86 * @param string $template Path to the XProfile change avatar template to load. 87 */ 88 bp_core_load_template( apply_filters( 'bp_settings_screen_notifications', '/members/single/home' ) ); 89 } 90 91 /** 92 * Output the screen notification content via a template part. 93 * 94 * @since 2.6.0 95 */ 96 function bp_notifications_screen_content() { 97 bp_get_template_part( 'members/single/settings/screen-notifications' ); 72 98 } 99 No newline at end of file -
new file src/bp-notifications/bp-notifications-settings.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Notifications Settings Functions. 4 * 5 * @package BuddyPress 6 * @subpackage NotificationsSettings 7 * @since 2.6.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Output the notification component settings title. 15 * 16 * @since 2.6.0 17 * 18 * @param string $component The component to retrieve the settings title for. 19 * @param string $element The element to wrap the title around. Default: h3. 20 */ 21 function bp_notifications_component_settings_title( $component = '', $element = 'h3' ) { 22 echo bp_notifications_get_component_settings_title( $component, $element ); 23 } 24 25 /** 26 * Return the notification component settings title. 27 * 28 * @since 2.6.0 29 * 30 * @param string $component The component to retrieve the settings title for. 31 * @param string $element The element to wrap the title around. Default: h3. 32 * @return string 33 */ 34 function bp_notifications_get_component_settings_title( $component = '', $element = 'h3' ) { 35 // Load registered notification actions if we haven't already done so. 36 if ( empty( buddypress()->notifications->actions ) ) { 37 bp_notifications_init_registered_actions(); 38 } 39 40 /** 41 * Filter the element used for the notification component settings title. 42 * 43 * @since 2.6.0 44 * 45 * @var string $element The element to use. Default: h3. 46 */ 47 $element = apply_filters( 'bp_notifications_component_settings_title_element', $element ); 48 $element = sanitize_key( $element ); 49 50 // Fallback title. 51 $title = ucfirst( sanitize_key( $component ) ); 52 53 // Get registered component label if available. 54 $key = "{$component}_settings_component_label"; 55 if ( isset( buddypress()->notifications->labels->$key ) ) { 56 $title = esc_html( buddypress()->notifications->labels->$key ); 57 } 58 59 /** 60 * Filter the notification component settings title. 61 * 62 * @since 2.6.0 63 * 64 * @var string $title The component settings title. 65 * @var string $component The component name. 66 */ 67 $title = apply_filters( 'bp_notifications_component_settings_title', $title, $component ); 68 69 return "<{$element}>{$title}</{$element}>"; 70 } 71 72 /** 73 * Handles the saving of user screen notification settings. 74 * 75 * @since 2.6.0 76 */ 77 function bp_notifications_settings_action_screen_notifications() { 78 // Bail if not a POST action 79 if ( false === bp_is_post_request() ) { 80 return; 81 } 82 83 // Bail if not in settings 84 if ( ! bp_is_user_settings() || ! bp_is_current_action( 'screen-notifications' ) ) { 85 return; 86 } 87 88 check_admin_referer( 'bp_settings_screen_notifications' ); 89 90 // Load our registered notifications actions. 91 bp_notifications_init_registered_actions(); 92 93 // Save settings. 94 foreach ( (array) bp_notifications_get_registered_components() as $component ) { 95 if ( empty( $_POST[ $component ] ) ) { 96 continue; 97 } 98 99 // Fudge xprofile component. 100 if ( 'xprofile' === $component ) { 101 $_POST[ 'xprofile' ] = $_POST[ 'profile' ]; 102 } 103 104 // Disable notifications for this component. 105 if ( ! isset( $_POST[ $component ]['enabled'] ) ) { 106 bp_update_user_meta( bp_displayed_user_id(), "notifications_{$component}_enabled", 0 ); 107 continue; 108 109 // Re-enable them. 110 } else { 111 bp_delete_user_meta( bp_displayed_user_id(), "notifications_{$component}_enabled" ); 112 } 113 114 // Per-action handling. 115 foreach( $_POST[ $component ] as $action => $val ) { 116 if ( 'enabled' === $action ) { 117 continue; 118 } 119 120 if ( isset( buddypress()->notifications->actions[$component][$action] ) ) { 121 // Disable notifications for this action. 122 if ( 0 === (int) $val) { 123 bp_update_user_meta( bp_displayed_user_id(), "notifications_{$component}_{$action}_enabled", 0 ); 124 continue; 125 } else { 126 bp_delete_user_meta( bp_displayed_user_id(), "notifications_{$component}_{$action}_enabled" ); 127 } 128 } 129 } 130 } 131 132 // Switch feedback for super admins 133 if ( bp_is_my_profile() ) { 134 bp_core_add_message( __( 'Your screen notification settings have been saved.', 'buddypress' ), 'success' ); 135 } else { 136 bp_core_add_message( __( "This user's screen notification settings have been saved.", 'buddypress' ), 'success' ); 137 } 138 139 /** 140 * Fires after screen notification settings are saved, and before redirect. 141 * 142 * @since 2.6.0 143 */ 144 do_action( 'bp_notifications_settings_action_after_save' ); 145 146 bp_core_redirect( bp_displayed_user_domain() . bp_get_settings_slug() . '/screen-notifications/' ); 147 die(); 148 } 149 add_action( 'bp_actions', 'bp_notifications_settings_action_screen_notifications' ); 150 No newline at end of file -
src/bp-notifications/classes/class-bp-notifications-component.php
17 17 */ 18 18 class BP_Notifications_Component extends BP_Component { 19 19 20 /* 21 * Notification actions holder. 22 * 23 * @since 2.6.0 24 * 25 * @var array 26 */ 27 public $actions = array(); 28 29 /** 30 * Notification labels holder. 31 * 32 * @since 2.6.0 33 * 34 * @var object 35 */ 36 public $labels; 37 20 38 /** 21 39 * Start the notifications component creation process. 22 40 * … … 31 49 'adminbar_myaccount_order' => 30 32 50 ) 33 51 ); 52 53 $this->setup_hooks(); 34 54 } 35 55 36 56 /** … … 52 72 'cache', 53 73 ); 54 74 75 // @todo if ( bp_is_active( 'settings' ) && bp_is_user_settings() ) ? 76 if ( bp_is_active( 'settings' ) ) { 77 $includes[] = 'settings'; 78 } 79 55 80 if ( ! buddypress()->do_autoload ) { 56 81 $includes[] = 'classes'; 57 82 } … … 91 116 'global_tables' => $global_tables, 92 117 ); 93 118 119 $this->labels = new stdClass; 120 94 121 parent::setup_globals( $args ); 95 122 } 96 123 97 124 /** 125 * Add custom hooks. 126 * 127 * @since 2.6.0 128 */ 129 public function setup_hooks() { 130 add_filter( 'bp_settings_admin_nav', array( $this, 'setup_settings_admin_nav' ), 1 ); 131 } 132 133 /** 98 134 * Set up component navigation. 99 135 * 100 136 * @since 1.9.0 … … 163 199 'user_has_access' => $access, 164 200 ); 165 201 202 /** 203 * The Settings > Notifications nav item can only be set up after the Settings 204 * component has run its own nav routine. 205 */ 206 add_action( 'bp_settings_setup_nav', array( $this, 'setup_settings_nav' ) ); 207 166 208 parent::setup_nav( $main_nav, $sub_nav ); 167 209 } 168 210 169 211 /** 212 * Set up the Settings > Notifications nav item. 213 * 214 * Loaded in a separate method because the Settings component may not be 215 * loaded in time during the BP_Notifications_Component::setup_nav() method. 216 * 217 * @since 2.6.0 218 */ 219 public function setup_settings_nav() { 220 if ( ! bp_is_active( 'settings' ) ) { 221 return; 222 } 223 224 // Determine user to use. 225 if ( bp_displayed_user_domain() ) { 226 $user_domain = bp_displayed_user_domain(); 227 } elseif ( bp_loggedin_user_domain() ) { 228 $user_domain = bp_loggedin_user_domain(); 229 } else { 230 return; 231 } 232 233 // Get the settings slug. 234 $settings_slug = bp_get_settings_slug(); 235 236 bp_core_new_subnav_item( array( 237 'name' => _x( 'Notifications', 'Notification settings sub nav', 'buddypress' ), 238 'slug' => 'screen-notifications', 239 'parent_url' => trailingslashit( $user_domain . $settings_slug ), 240 'parent_slug' => $settings_slug, 241 'screen_function' => 'bp_notifications_screen_settings', 242 'position' => 25, 243 'user_has_access' => bp_core_can_edit_settings() 244 ) ); 245 } 246 247 /** 170 248 * Set up the component entries in the WordPress Admin Bar. 171 249 * 172 250 * @since 1.9.0 … … 226 304 } 227 305 228 306 /** 307 * Adds "Settings > Notifications" subnav item under the "Settings" adminbar menu. 308 * 309 * @since 2.6.0 310 * 311 * @param array $wp_admin_nav The settings adminbar nav array. 312 * @return array 313 */ 314 public function setup_settings_admin_nav( $wp_admin_nav ) { 315 316 // Setup the logged in user variables. 317 $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() ); 318 319 // Add the "Notifications" subnav item. 320 $wp_admin_nav[] = array( 321 'parent' => 'my-account-' . buddypress()->settings->id, 322 'id' => 'my-account-' . buddypress()->settings->id . '-screennotifications', 323 'title' => _x( 'Notifications', 'My Account Settings sub nav', 'buddypress' ), 324 'href' => trailingslashit( $settings_link . 'screen-notifications' ) 325 ); 326 327 return $wp_admin_nav; 328 } 329 330 /** 229 331 * Set up the title for pages and <title>. 230 332 * 231 333 * @since 1.9.0 -
new file src/bp-templates/bp-legacy/buddypress/members/single/settings/screen-notifications.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress - Members Settings Screen Notifications 4 * 5 * @since 2.6.0 6 * 7 * @package BuddyPress 8 * @subpackage bp-legacy 9 */ 10 11 /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/settings/profile.php */ 12 do_action( 'bp_before_member_settings_template' ); ?> 13 14 <form action="<?php echo bp_displayed_user_domain() . bp_get_settings_slug() . '/screen-notifications'; ?>" method="post" class="standard-form" id="settings-form"> 15 16 <?php 17 $components = bp_notifications_get_registered_components(); 18 19 // Fudge xprofile component. 20 $profile = array_search( 'xprofile', $components ); 21 if ( false !== $profile ) { 22 $components[] = 'profile'; 23 unset( $components[ $profile ] ); 24 } 25 26 sort( $components, SORT_STRING ); 27 28 // Initialize registered notification actions. 29 bp_notifications_init_registered_actions(); 30 31 foreach ( $components as $component ) : 32 $enabled = bp_get_user_meta( bp_loggedin_user_id(), "notifications_{$component}_enabled", true ); 33 if ( '' === $enabled ) { 34 $enabled = 1; 35 } 36 37 $action_count = ! empty( buddypress()->notifications->actions[$component] ) ? count( buddypress()->notifications->actions[$component] ) : 0; 38 ?> 39 <?php bp_notifications_component_settings_title( $component, 'h2' ); ?> 40 41 <label for="<?php esc_attr_e( "{$component}-notification-enable" ); ?>"> 42 <input type="checkbox" name="<?php esc_attr_e( "{$component}[enabled]" ); ?>" data-component="<?php esc_attr_e( $component ); ?>" id="<?php esc_attr_e( "{$component}-notification-enable" ); ?>" value="1" <?php checked( $enabled, 1, true ) ?>/> 43 44 <?php esc_html_e( 'Enable screen notifications for this component', 'buddypress' ); ?> 45 </label> 46 47 <?php if ( ! empty( buddypress()->notifications->actions[$component] ) ) : ?> 48 49 <table class="notification-settings" id="<?php esc_attr_e( "{$component}-screen-notification-settings" ); ?>"> 50 <thead> 51 <tr> 52 <th class="icon"> </th> 53 <th> </th> 54 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 55 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 56 </tr> 57 </thead> 58 59 <tbody> 60 <?php 61 foreach ( buddypress()->notifications->actions[$component] as $action => $val ) : 62 $action = sanitize_key( $action ); 63 64 $enabled = bp_get_user_meta( bp_loggedin_user_id(), "notifications_{$component}_{$action}_enabled", true ); 65 if ( '' === $enabled ) { 66 $enabled = 1; 67 } 68 ?> 69 70 <tr id="<?php esc_html_e( "{$component}-{$action}" ); ?>" class="<?php esc_attr_e( "{$component}-screen-notification-singular" ); ?>"> 71 <td> </td> 72 <td><?php esc_html_e( $val['settings_label' ] ); ?></td> 73 <td class="yes"><input type="radio" name="<?php esc_attr_e( "{$component}[{$action}]" ); ?>" id="<?php esc_attr_e( "{$component}-notification-{$action}-yes" ); ?>" value="1" <?php checked( $enabled, 1, true ) ?>/><label for="<?php esc_attr_e( "{$component}-notification-{$action}-yes" ); ?>" class="bp-screen-reader-text"><?php _e( 'Yes', 'buddypress' ); ?></label></td> 74 <td class="no"><input type="radio" name="<?php esc_attr_e( "{$component}[{$action}]" ); ?>" id="<?php esc_attr_e( "{$component}-notification-{$action}-no" ); ?>" value="0" <?php checked( $enabled, 0, true ) ?>/><label for="<?php esc_attr_e( "{$component}-notification-{$action}-no" ); ?>" class="bp-screen-reader-text"><?php _e( 'No', 'buddypress' ); ?></label></td> 75 </tr> 76 77 <?php 78 endforeach; 79 ?> 80 </tbody> 81 </table> 82 83 <?php endif; ?> 84 85 <?php endforeach; ?> 86 87 <script type="text/javascript"> 88 // This will be moved to bp-legacy's buddypress.js file. Or maybe not? 89 jQuery(function($){ 90 $('#settings-form input[type=checkbox]').each(function( index, elem ) { 91 toggleSettingsComponentFields( $(this) ); 92 }); 93 94 $('#settings-form').on('click', 'input[type=checkbox]', function(e) { 95 toggleSettingsComponentFields( $(this) ); 96 }); 97 98 function toggleSettingsComponentFields( elem ) { 99 var component = $( elem ).data( 'component' ); 100 101 if ( elem.is(':checked') ) { 102 $('#' + component + '-screen-notification-settings').fadeIn('fast'); 103 } else { 104 $('#' + component + '-screen-notification-settings').fadeOut('fast'); 105 } 106 } 107 }); 108 </script> 109 110 <?php 111 112 /** 113 * Fires before the display of the submit button for user notification saving. 114 * 115 * @since 2.6.0 116 */ 117 do_action( 'bp_members_screen_notification_settings_before_submit' ); ?> 118 119 <div class="submit"> 120 <input type="submit" name="screen-notifications-submit" value="<?php esc_attr_e( 'Save Changes', 'buddypress' ); ?>" id="submit" class="auto" /> 121 </div> 122 123 <?php 124 125 /** 126 * Fires after the display of the submit button for user notification saving. 127 * 128 * @since 2.6.0 129 */ 130 do_action( 'bp_members_screen_notification_settings_after_submit' ); ?> 131 132 <?php wp_nonce_field( 'bp_settings_screen_notifications' ); ?> 133 134 </form> 135 136 <?php 137 138 /** This action is documented in bp-templates/bp-legacy/buddypress/members/single/settings/profile.php */ 139 do_action( 'bp_after_member_settings_template' ); 140 No newline at end of file -
src/bp-xprofile/bp-xprofile-notifications.php
10 10 /** Notifications *************************************************************/ 11 11 12 12 /** 13 * Register screen notification actions with the Notifications component. 14 * 15 * @since 2.6.0 16 */ 17 function bp_xprofile_register_notification_actions() { 18 // Set labels 19 bp_notifications_set_prop( 20 'settings_component_label', 21 _x( 'Profile', 'Settings > Notifications component label', 'buddypress' ), 22 'labels', 23 'xprofile' 24 ); 25 26 /** 27 * Fires after default extended profile notification actions are registered. 28 * 29 * @since 2.6.0 30 */ 31 do_action( 'bp_xprofile_register_notification_actions' ); 32 } 33 34 /** 13 35 * Format notifications for the extended profile (Xprofile) component. 14 36 * 15 37 * @since 2.4.0 -
tests/phpunit/testcases/notifications/functions.php
294 294 $found2 = $wpdb->get_col( $query ); 295 295 $this->assertEmpty( $found2 ); 296 296 } 297 298 /** 299 * @group notification_settings 300 */ 301 public function test_notifications_disabled_by_component_action_by_user() { 302 $u = $this->factory->user->create(); 303 304 // Disable notifications for the 'new_at_mention' action. 305 bp_update_user_meta( $u, 'notifications_activity_new_at_mention_enabled', 0 ); 306 307 $n1 = $this->factory->notification->create( array( 308 'component_name' => 'activity', 309 'component_action' => 'new_at_mention', 310 'item_id' => 99, 311 'user_id' => $u, 312 ) ); 313 314 // This should pass through. 315 $n2 = $this->factory->notification->create( array( 316 'component_name' => 'activity', 317 'component_action' => 'kwyjibo', 318 'item_id' => 99, 319 'user_id' => $u, 320 ) ); 321 322 $this->assertFalse( $n1 ); 323 $this->assertNotFalse( $n2 ); 324 } 325 326 /** 327 * @group notification_settings 328 */ 329 public function test_notifications_disabled_by_component_name_by_user() { 330 $u = $this->factory->user->create(); 331 332 // Disable notifications for the 'activity' component. 333 bp_update_user_meta( $u, 'notifications_activity_enabled', 0 ); 334 335 $n1 = $this->factory->notification->create( array( 336 'component_name' => 'activity', 337 'component_action' => 'kwyjibo', 338 'item_id' => 99, 339 'user_id' => $u, 340 ) ); 341 342 $n2 = $this->factory->notification->create( array( 343 'component_name' => 'activity', 344 'component_action' => 'new_at_mention', 345 'item_id' => 99, 346 'user_id' => $u, 347 ) ); 348 349 // This should pass through. 350 $n3 = $this->factory->notification->create( array( 351 'component_name' => 'messages', 352 'component_action' => 'new_message', 353 'item_id' => 99, 354 'user_id' => $u, 355 ) ); 356 357 $this->assertFalse( $n1 ); 358 $this->assertFalse( $n2 ); 359 $this->assertNotFalse( $n3 ); 360 } 297 361 }