Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/22/2016 08:46:36 PM (5 years ago)
Author:
r-a-y
Message:

Load all notification-related code conditionally for each component.

If the notifications component isn't active, there is no need to load all
notification code.

See #6712.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/bp-friends-functions.php

    r10587 r11022  
    796796}
    797797add_action( 'bp_activity_mentions_prime_results', 'bp_friends_prime_mentions_results' );
     798
     799/** Emails ********************************************************************/
     800
     801/**
     802 * Send notifications related to a new friendship request.
     803 *
     804 * When a friendship is requested, an email and a BP notification are sent to
     805 * the user of whom friendship has been requested ($friend_id).
     806 *
     807 * @since 1.0.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 */
     813function 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    $unsubscribe_args = array(
     819        'user_id'           => $friend_id,
     820        'notification_type' => 'friends-request',
     821    );
     822
     823    $args = array(
     824        'tokens' => array(
     825            'friend-requests.url' => esc_url( bp_core_get_user_domain( $friend_id ) . bp_get_friends_slug() . '/requests/' ),
     826            'friend.id'           => $friend_id,
     827            'friendship.id'       => $friendship_id,
     828            'initiator.id'        => $initiator_id,
     829            'initiator.url'       => esc_url( bp_core_get_user_domain( $initiator_id ) ),
     830            'initiator.name'      => bp_core_get_user_displayname( $initiator_id ),
     831            'unsubscribe'         => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
     832        ),
     833    );
     834    bp_send_email( 'friends-request', $friend_id, $args );
     835}
     836add_action( 'friends_friendship_requested', 'friends_notification_new_request', 10, 3 );
     837
     838/**
     839 * Send notifications related to the acceptance of a friendship request.
     840 *
     841 * When a friendship request is accepted, an email and a BP notification are
     842 * sent to the user who requested the friendship ($initiator_id).
     843 *
     844 * @since 1.0.0
     845 *
     846 * @param int $friendship_id ID of the friendship object.
     847 * @param int $initiator_id  ID of the user who initiated the request.
     848 * @param int $friend_id     ID of the request recipient.
     849 */
     850function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) {
     851    if ( 'no' == bp_get_user_meta( (int) $initiator_id, 'notification_friends_friendship_accepted', true ) ) {
     852        return;
     853    }
     854
     855    $unsubscribe_args = array(
     856        'user_id'           => $initiator_id,
     857        'notification_type' => 'friends-request-accepted',
     858    );
     859
     860    $args = array(
     861        'tokens' => array(
     862            'friend.id'      => $friend_id,
     863            'friendship.url' => esc_url( bp_core_get_user_domain( $friend_id ) ),
     864            'friend.name'    => bp_core_get_user_displayname( $friend_id ),
     865            'friendship.id'  => $friendship_id,
     866            'initiator.id'   => $initiator_id,
     867            'unsubscribe'      => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
     868        ),
     869    );
     870    bp_send_email( 'friends-request-accepted', $initiator_id, $args );
     871}
     872add_action( 'friends_friendship_accepted', 'friends_notification_accepted_request', 10, 3 );
Note: See TracChangeset for help on using the changeset viewer.