Skip to:
Content

BuddyPress.org

Ticket #5938: bp-activity-notifications-5938.diff

File bp-activity-notifications-5938.diff, 11.0 KB (added by tw2113, 10 years ago)
  • src/bp-activity/bp-activity-notifications.php

     
    1515/**
    1616 * Send email and BP notifications when a user is mentioned in an update.
    1717 *
    18  * @since BuddyPress (1.2)
     18 * @since BuddyPress (1.2.0)
    1919 *
    2020 * @uses bp_notifications_add_notification()
    2121 * @uses bp_get_user_meta()
     
    9999                        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    100100                }
    101101
    102                 // Send the message
     102                /**
     103                 * Filters the user email that the @mention notification will be sent to.
     104                 *
     105                 * @since BuddyPress (1.2.0)
     106                 *
     107                 * @param string $to User email the notification is being sent to.
     108                 */
    103109                $to      = apply_filters( 'bp_activity_at_message_notification_to', $to );
     110
     111                /**
     112                 * Filters the @mention notification subject that will be sent to user.
     113                 *
     114                 * @since BuddyPress (1.2.0)
     115                 *
     116                 * @param string $subject Email notification subject text.
     117                 * @param string $poster_name Name of the person who made the @mention.
     118                 */
    104119                $subject = apply_filters( 'bp_activity_at_message_notification_subject', $subject, $poster_name );
     120
     121                /**
     122                 * Filters the @mention notification message that will be sent to user.
     123                 *
     124                 * @since BuddyPress (1.2.0)
     125                 *
     126                 * @param string $message Email notification message text.
     127                 * @param string $poster_name Name of the person who made the @mention.
     128                 * @param string $content Content of the @mention.
     129                 * @param string $message_link URL permalink for the activity message.
     130                 * @param string $settings_link URL permalink for the user's notification settings area.
     131                 */
    105132                $message = apply_filters( 'bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link );
    106133
    107134                wp_mail( $to, $subject, $message );
    108135        }
    109136
     137        /**
     138         * Fires after the sending of an @mention email notification.
     139         *
     140         * @since BuddyPress (1.5.0)
     141         *
     142         * @param BP_Activity_Activity $activity Activity Item object.
     143         * @param string               $subject Email notification subject text.
     144         * @param string               $message Email notification message text.
     145         * @param string               $content Content of the @mention.
     146         * @param int                  $receiver_user_id The ID of the user who is receiving the update.
     147         */
    110148        do_action( 'bp_activity_sent_mention_email', $activity, $subject, $message, $content, $receiver_user_id );
    111149}
    112150
     
    113151/**
    114152 * Send email and BP notifications when an activity item receives a comment.
    115153 *
    116  * @since BuddyPress (1.2)
     154 * @since BuddyPress (1.2.0)
    117155 *
    118156 * @uses bp_get_user_meta()
    119157 * @uses bp_core_get_user_displayname()
     
    177215                        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    178216                }
    179217
    180                 /* Send the message */
     218                /**
     219                 * Filters the user email that the new comment notification will be sent to.
     220                 *
     221                 * @since BuddyPress (1.2.0)
     222                 *
     223                 * @param string $to User email the notification is being sent to.
     224                 */
    181225                $to = apply_filters( 'bp_activity_new_comment_notification_to', $to );
     226
     227                /**
     228                 * Filters the new comment notification subject that will be sent to user.
     229                 *
     230                 * @since BuddyPress (1.2.0)
     231                 *
     232                 * @param string $subject Email notification subject text.
     233                 * @param string $poster_name Name of the person who made the comment.
     234                 */
    182235                $subject = apply_filters( 'bp_activity_new_comment_notification_subject', $subject, $poster_name );
     236
     237                /**
     238                 * Filters the new comment notification message that will be sent to user.
     239                 *
     240                 * @since BuddyPress (1.2.0)
     241                 *
     242                 * @param string $message Email notification message text.
     243                 * @param string $poster_name Name of the person who made the comment.
     244                 * @param string $content Content of the comment.
     245                 * @param string $thread_link URL permalink for the activity thread.
     246                 * @param string $settings_link URL permalink for the user's notification settings area.
     247                 */
    183248                $message = apply_filters( 'bp_activity_new_comment_notification_message', $message, $poster_name, $content, $thread_link, $settings_link );
    184249
    185250                wp_mail( $to, $subject, $message );
    186251
     252                /**
     253                 * Fires after the sending of a reply to an update email notification.
     254                 *
     255                 * @since BuddyPress (1.5.0)
     256                 *
     257                 * @param int    $user_id ID of the original activity item author.
     258                 * @param string $subject Email notification subject text.
     259                 * @param string $message Email notification message text.
     260                 * @param int    $comment_id ID for the newly received comment.
     261                 * @param int    $commenter_id ID of the user who made the comment.
     262                 * @param array  $params Arguments used with the original activity comment.
     263                 */
    187264                do_action( 'bp_activity_sent_reply_to_update_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
    188265        }
    189266
     
    226303                        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
    227304                }
    228305
    229                 /* Send the message */
     306                /**
     307                 * Filters the user email that the new comment reply notification will be sent to.
     308                 *
     309                 * @since BuddyPress (1.2.0)
     310                 *
     311                 * @param string $to User email the notification is being sent to.
     312                 */
    230313                $to = apply_filters( 'bp_activity_new_comment_notification_comment_author_to', $to );
     314
     315                /**
     316                 * Filters the new comment reply notification subject that will be sent to user.
     317                 *
     318                 * @since BuddyPress (1.2.0)
     319                 *
     320                 * @param string $subject Email notification subject text.
     321                 * @param string $poster_name Name of the person who made the comment reply.
     322                 */
    231323                $subject = apply_filters( 'bp_activity_new_comment_notification_comment_author_subject', $subject, $poster_name );
     324
     325                /**
     326                 * Filters the new comment reply notification message that will be sent to user.
     327                 *
     328                 * @since BuddyPress (1.2.0)
     329                 *
     330                 * @param string $message Email notification message text.
     331                 * @param string $poster_name Name of the person who made the comment reply.
     332                 * @param string $content Content of the comment reply.
     333                 * @param string $settings_link URL permalink for the user's notification settings area.
     334                 * @param string $thread_link URL permalink for the activity thread.
     335                 */
    232336                $message = apply_filters( 'bp_activity_new_comment_notification_comment_author_message', $message, $poster_name, $content, $settings_link, $thread_link );
    233337
    234338                wp_mail( $to, $subject, $message );
    235339
     340                /**
     341                 * Fires after the sending of a reply to a reply email notification.
     342                 *
     343                 * @since BuddyPress (1.5.0)
     344                 *
     345                 * @param int    $user_id ID of the original activity item author.
     346                 * @param string $subject Email notification subject text.
     347                 * @param string $message Email notification message text.
     348                 * @param int    $comment_id ID for the newly received comment.
     349                 * @param int    $commenter_id ID of the user who made the comment.
     350                 * @param array  $params Arguments used with the original activity comment.
     351                 */
    236352                do_action( 'bp_activity_sent_reply_to_reply_email', $original_activity->user_id, $subject, $message, $comment_id, $commenter_id, $params );
    237353        }
    238354}
     
    254370/**
    255371 * Format notifications related to activity.
    256372 *
    257  * @since BuddyPress (1.5)
     373 * @since BuddyPress (1.5.0)
    258374 *
    259375 * @uses bp_loggedin_user_domain()
    260376 * @uses bp_get_activity_slug()
     
    278394                        $poster_user_id   = $secondary_item_id;
    279395                        $at_mention_link  = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/';
    280396                        $at_mention_title = sprintf( __( '@%s Mentions', 'buddypress' ), bp_get_loggedin_user_username() );
     397                        $amount = 'single';
    281398
    282399                        if ( (int) $total_items > 1 ) {
    283400                                $text = sprintf( __( 'You have %1$d new mentions', 'buddypress' ), (int) $total_items );
    284                                 $filter = 'bp_activity_multiple_at_mentions_notification';
     401                                $amount = 'multiple';
    285402                        } else {
    286403                                $user_fullname = bp_core_get_user_displayname( $poster_user_id );
    287404                                $text =  sprintf( __( '%1$s mentioned you', 'buddypress' ), $user_fullname );
    288                                 $filter = 'bp_activity_single_at_mentions_notification';
    289405                        }
    290406                break;
    291407        }
    292408
    293409        if ( 'string' == $format ) {
    294                 $return = apply_filters( $filter, '<a href="' . esc_url( $at_mention_link ) . '" title="' . esc_attr( $at_mention_title ) . '">' . esc_html( $text ) . '</a>', $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
     410
     411                /**
     412                 * Filters the @mention notification for the string format.
     413                 *
     414                 * This is a variable filter that is dependent on how many items need notified about. The two possible hooks are bp_activity_single_at_mentions_notification or bp_activity_multiple_at_mentions_notification.
     415                 *
     416                 * @since BuddyPress (1.5.0)
     417                 *
     418                 * @param string $string HTML anchor tag for the mention.
     419                 * @param string $at_mention_link The permalink for the mention.
     420                 * @param int    $total_items How many items being notified about.
     421                 * @param int    $activity_id ID of the activity item being formatted.
     422                 * @param int    $poster_user_id ID of the user posting the mention.
     423                 */
     424                $return = apply_filters( 'bp_activity_' . $amount . '_at_mentions_notification', '<a href="' . esc_url( $at_mention_link ) . '" title="' . esc_attr( $at_mention_title ) . '">' . esc_html( $text ) . '</a>', $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
    295425        } else {
    296                 $return = apply_filters( $filter, array(
     426
     427                /**
     428                 * Filters the @mention notification for any non-string format.
     429                 *
     430                 * This is a variable filter that is dependent on how many items need notified about. The two possible hooks are bp_activity_single_at_mentions_notification or bp_activity_multiple_at_mentions_notification.
     431                 *
     432                 * @since BuddyPress (1.5.0)
     433                 *
     434                 * @param array  $array Array holding the content and permalink for the mention notification.
     435                 * @param string $at_mention_link The permalink for the mention.
     436                 * @param int    $total_items How many items being notified about.
     437                 * @param int    $activity_id ID of the activity item being formatted.
     438                 * @param int    $poster_user_id ID of the user posting the mention.
     439                 */
     440                $return = apply_filters( 'bp_activity_' . $amount . '_at_mentions_notification', array(
    297441                        'text' => $text,
    298442                        'link' => $at_mention_link
    299443                ), $at_mention_link, (int) $total_items, $activity_id, $poster_user_id );
    300444        }
    301445
     446        /**
     447         * Fires right before returning the formatted activity notifications.
     448         *
     449         * @since BuddyPress (1.2.0)
     450         *
     451         * @param string $action The type of activity item.
     452         * @param int    $item_id The activity ID.
     453         * @param int    $secondary_item_id @mention mentioner ID.
     454         * @param int    $total_items Total amount of items to format.
     455         */
    302456        do_action( 'activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items );
    303457
    304458        return $return;
     
    338492/**
    339493 * Mark at-mention notifications as read when users visit their Mentions page.
    340494 *
    341  * @since BuddyPress (1.5)
     495 * @since BuddyPress (1.5.0)
    342496 *
    343497 * @uses bp_notifications_mark_all_notifications_by_type()
    344498 */