Changeset 11022 for trunk/src/bp-activity/bp-activity-functions.php
- Timestamp:
- 08/22/2016 08:46:36 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-functions.php
r10894 r11022 3418 3418 } 3419 3419 3420 /* Emails *********************************************************************/ 3421 3422 /** 3423 * Send email and BP notifications when a user is mentioned in an update. 3424 * 3425 * @since 1.2.0 3426 * 3427 * @param int $activity_id The ID of the activity update. 3428 * @param int $receiver_user_id The ID of the user who is receiving the update. 3429 */ 3430 function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) { 3431 $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' ); 3432 3433 // Don't leave multiple notifications for the same activity item. 3434 foreach( $notifications as $notification ) { 3435 if ( $activity_id == $notification->item_id ) { 3436 return; 3437 } 3438 } 3439 3440 $activity = new BP_Activity_Activity( $activity_id ); 3441 $email_type = 'activity-at-message'; 3442 $group_name = ''; 3443 $message_link = bp_activity_get_permalink( $activity_id ); 3444 $poster_name = bp_core_get_user_displayname( $activity->user_id ); 3445 3446 remove_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 3447 remove_filter( 'bp_get_activity_content_body', 'wpautop' ); 3448 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 3449 3450 /** This filter is documented in bp-activity/bp-activity-template.php */ 3451 $content = apply_filters( 'bp_get_activity_content_body', $activity->content ); 3452 3453 add_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 3454 add_filter( 'bp_get_activity_content_body', 'wpautop' ); 3455 add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 3456 3457 // Now email the user with the contents of the message (if they have enabled email notifications). 3458 if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) { 3459 if ( bp_is_active( 'groups' ) && bp_is_group() ) { 3460 $email_type = 'groups-at-message'; 3461 $group_name = bp_get_current_group_name(); 3462 } 3463 3464 $unsubscribe_args = array( 3465 'user_id' => $receiver_user_id, 3466 'notification_type' => $email_type, 3467 ); 3468 3469 $args = array( 3470 'tokens' => array( 3471 'activity' => $activity, 3472 'usermessage' => wp_strip_all_tags( $content ), 3473 'group.name' => $group_name, 3474 'mentioned.url' => $message_link, 3475 'poster.name' => $poster_name, 3476 'receiver-user.id' => $receiver_user_id, 3477 'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ), 3478 ), 3479 ); 3480 3481 bp_send_email( $email_type, $receiver_user_id, $args ); 3482 } 3483 3484 /** 3485 * Fires after the sending of an @mention email notification. 3486 * 3487 * @since 1.5.0 3488 * @since 2.5.0 $subject, $message, $content arguments unset and deprecated. 3489 * 3490 * @param BP_Activity_Activity $activity Activity Item object. 3491 * @param string $deprecated Removed in 2.5; now an empty string. 3492 * @param string $deprecated Removed in 2.5; now an empty string. 3493 * @param string $deprecated Removed in 2.5; now an empty string. 3494 * @param int $receiver_user_id The ID of the user who is receiving the update. 3495 */ 3496 do_action( 'bp_activity_sent_mention_email', $activity, '', '', '', $receiver_user_id ); 3497 } 3498 3499 /** 3500 * Send email and BP notifications when an activity item receives a comment. 3501 * 3502 * @since 1.2.0 3503 * @since 2.5.0 Updated to use new email APIs. 3504 * 3505 * @param int $comment_id The comment id. 3506 * @param int $commenter_id The ID of the user who posted the comment. 3507 * @param array $params {@link bp_activity_new_comment()}. 3508 */ 3509 function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) { 3510 $original_activity = new BP_Activity_Activity( $params['activity_id'] ); 3511 $poster_name = bp_core_get_user_displayname( $commenter_id ); 3512 $thread_link = bp_activity_get_permalink( $params['activity_id'] ); 3513 3514 remove_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 3515 remove_filter( 'bp_get_activity_content_body', 'wpautop' ); 3516 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 3517 3518 /** This filter is documented in bp-activity/bp-activity-template.php */ 3519 $content = apply_filters( 'bp_get_activity_content_body', $params['content'] ); 3520 3521 add_filter( 'bp_get_activity_content_body', 'convert_smilies' ); 3522 add_filter( 'bp_get_activity_content_body', 'wpautop' ); 3523 add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 3524 3525 if ( $original_activity->user_id != $commenter_id ) { 3526 3527 // Send an email if the user hasn't opted-out. 3528 if ( 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) { 3529 3530 $unsubscribe_args = array( 3531 'user_id' => $original_activity->user_id, 3532 'notification_type' => 'activity-comment', 3533 ); 3534 3535 $args = array( 3536 'tokens' => array( 3537 'comment.id' => $comment_id, 3538 'commenter.id' => $commenter_id, 3539 'usermessage' => wp_strip_all_tags( $content ), 3540 'original_activity.user_id' => $original_activity->user_id, 3541 'poster.name' => $poster_name, 3542 'thread.url' => esc_url( $thread_link ), 3543 'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ), 3544 ), 3545 ); 3546 3547 bp_send_email( 'activity-comment', $original_activity->user_id, $args ); 3548 } 3549 3550 /** 3551 * Fires at the point that notifications should be sent for activity comments. 3552 * 3553 * @since 2.6.0 3554 * 3555 * @param BP_Activity_Activity $original_activity The original activity. 3556 * @param int $comment_id ID for the newly received comment. 3557 * @param int $commenter_id ID of the user who made the comment. 3558 * @param array $params Arguments used with the original activity comment. 3559 */ 3560 do_action( 'bp_activity_sent_reply_to_update_notification', $original_activity, $comment_id, $commenter_id, $params ); 3561 } 3562 3563 3564 /* 3565 * If this is a reply to another comment, send an email notification to the 3566 * author of the immediate parent comment. 3567 */ 3568 if ( empty( $params['parent_id'] ) || ( $params['activity_id'] == $params['parent_id'] ) ) { 3569 return; 3570 } 3571 3572 $parent_comment = new BP_Activity_Activity( $params['parent_id'] ); 3573 3574 if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id ) { 3575 3576 // Send an email if the user hasn't opted-out. 3577 if ( 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) { 3578 3579 $unsubscribe_args = array( 3580 'user_id' => $parent_comment->user_id, 3581 'notification_type' => 'activity-comment-author', 3582 ); 3583 3584 $args = array( 3585 'tokens' => array( 3586 'comment.id' => $comment_id, 3587 'commenter.id' => $commenter_id, 3588 'usermessage' => wp_strip_all_tags( $content ), 3589 'parent-comment-user.id' => $parent_comment->user_id, 3590 'poster.name' => $poster_name, 3591 'thread.url' => esc_url( $thread_link ), 3592 'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ), 3593 ), 3594 ); 3595 3596 bp_send_email( 'activity-comment-author', $parent_comment->user_id, $args ); 3597 } 3598 3599 /** 3600 * Fires at the point that notifications should be sent for comments on activity replies. 3601 * 3602 * @since 2.6.0 3603 * 3604 * @param BP_Activity_Activity $parent_comment The parent activity. 3605 * @param int $comment_id ID for the newly received comment. 3606 * @param int $commenter_id ID of the user who made the comment. 3607 * @param array $params Arguments used with the original activity comment. 3608 */ 3609 do_action( 'bp_activity_sent_reply_to_reply_notification', $parent_comment, $comment_id, $commenter_id, $params ); 3610 } 3611 } 3612 3613 /** 3614 * Helper method to map action arguments to function parameters. 3615 * 3616 * @since 1.9.0 3617 * 3618 * @param int $comment_id ID of the comment being notified about. 3619 * @param array $params Parameters to use with notification. 3620 */ 3621 function bp_activity_new_comment_notification_helper( $comment_id, $params ) { 3622 bp_activity_new_comment_notification( $comment_id, $params['user_id'], $params ); 3623 } 3624 add_action( 'bp_activity_comment_posted', 'bp_activity_new_comment_notification_helper', 10, 2 ); 3420 3625 3421 3626 /** Embeds *******************************************************************/
Note: See TracChangeset
for help on using the changeset viewer.