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-notifications.php

    r10941 r11022  
    1313// Exit if accessed directly.
    1414defined( 'ABSPATH' ) || exit;
    15 
    16 /** Emails ********************************************************************/
    17 
    18 /**
    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).
    23  *
    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.
    29  */
    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     $unsubscribe_args = array(
    36         'user_id'           => $friend_id,
    37         'notification_type' => 'friends-request',
    38     );
    39 
    40     $args = array(
    41         'tokens' => array(
    42             'friend-requests.url' => esc_url( bp_core_get_user_domain( $friend_id ) . bp_get_friends_slug() . '/requests/' ),
    43             'friend.id'           => $friend_id,
    44             'friendship.id'       => $friendship_id,
    45             'initiator.id'        => $initiator_id,
    46             'initiator.url'       => esc_url( bp_core_get_user_domain( $initiator_id ) ),
    47             'initiator.name'      => bp_core_get_user_displayname( $initiator_id ),
    48             'unsubscribe'         => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    49         ),
    50     );
    51     bp_send_email( 'friends-request', $friend_id, $args );
    52 }
    53 add_action( 'friends_friendship_requested', 'friends_notification_new_request', 10, 3 );
    54 
    55 /**
    56  * Send notifications related to the acceptance of a friendship request.
    57  *
    58  * When a friendship request is accepted, an email and a BP notification are
    59  * sent to the user who requested the friendship ($initiator_id).
    60  *
    61  * @since 1.0.0
    62  *
    63  * @param int $friendship_id ID of the friendship object.
    64  * @param int $initiator_id  ID of the user who initiated the request.
    65  * @param int $friend_id     ID of the request recipient.
    66  */
    67 function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) {
    68     if ( 'no' == bp_get_user_meta( (int) $initiator_id, 'notification_friends_friendship_accepted', true ) ) {
    69         return;
    70     }
    71 
    72     $unsubscribe_args = array(
    73         'user_id'           => $initiator_id,
    74         'notification_type' => 'friends-request-accepted',
    75     );
    76 
    77     $args = array(
    78         'tokens' => array(
    79             'friend.id'      => $friend_id,
    80             'friendship.url' => esc_url( bp_core_get_user_domain( $friend_id ) ),
    81             'friend.name'    => bp_core_get_user_displayname( $friend_id ),
    82             'friendship.id'  => $friendship_id,
    83             'initiator.id'   => $initiator_id,
    84             'unsubscribe'      => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    85         ),
    86     );
    87     bp_send_email( 'friends-request-accepted', $initiator_id, $args );
    88 }
    89 add_action( 'friends_friendship_accepted', 'friends_notification_accepted_request', 10, 3 );
    90 
    91 /** Notifications *************************************************************/
    9215
    9316/**
     
    195118 */
    196119function friends_clear_friend_notifications() {
    197     if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' ) ) {
     120    if ( isset( $_GET['new'] ) ) {
    198121        bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
    199122    }
     
    207130 */
    208131function bp_friends_mark_friendship_request_notifications_by_type() {
    209     if ( isset( $_GET['new'] ) && bp_is_active( 'notifications' ) ) {
     132    if ( isset( $_GET['new'] ) ) {
    210133        bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_request' );
    211134    }
     
    219142 */
    220143function bp_friends_mark_friendship_accepted_notifications_by_type() {
    221     if ( bp_is_active( 'notifications' ) ) {
    222         bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
    223     }
     144    bp_notifications_mark_notifications_by_type( bp_loggedin_user_id(), buddypress()->friends->id, 'friendship_accepted' );
    224145}
    225146add_action( 'friends_screen_my_friends', 'bp_friends_mark_friendship_accepted_notifications_by_type' );
     
    235156 */
    236157function bp_friends_friendship_requested_notification( $friendship_id, $initiator_user_id, $friend_user_id ) {
    237     if ( bp_is_active( 'notifications' ) ) {
    238         bp_notifications_add_notification( array(
    239             'user_id'           => $friend_user_id,
    240             'item_id'           => $initiator_user_id,
    241             'secondary_item_id' => $friendship_id,
    242             'component_name'    => buddypress()->friends->id,
    243             'component_action'  => 'friendship_request',
    244             'date_notified'     => bp_core_current_time(),
    245             'is_new'            => 1,
    246         ) );
    247     }
     158    bp_notifications_add_notification( array(
     159        'user_id'           => $friend_user_id,
     160        'item_id'           => $initiator_user_id,
     161        'secondary_item_id' => $friendship_id,
     162        'component_name'    => buddypress()->friends->id,
     163        'component_action'  => 'friendship_request',
     164        'date_notified'     => bp_core_current_time(),
     165        'is_new'            => 1,
     166    ) );
    248167}
    249168add_action( 'friends_friendship_requested', 'bp_friends_friendship_requested_notification', 10, 3 );
     
    258177 */
    259178function bp_friends_mark_friendship_rejected_notifications_by_item_id( $friendship_id, $friendship ) {
    260     if ( bp_is_active( 'notifications' ) ) {
    261         bp_notifications_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' );
    262     }
     179    bp_notifications_mark_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' );
    263180}
    264181add_action( 'friends_friendship_rejected', 'bp_friends_mark_friendship_rejected_notifications_by_item_id', 10, 2 );
     
    274191 */
    275192function bp_friends_add_friendship_accepted_notification( $friendship_id, $initiator_user_id, $friend_user_id ) {
    276 
    277     // Bail if notifications is not active.
    278     if ( ! bp_is_active( 'notifications' ) ) {
    279         return;
    280     }
    281 
    282193    // Remove the friend request notice.
    283194    bp_notifications_mark_notifications_by_item_id( $friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request' );
     
    305216 */
    306217function bp_friends_mark_friendship_withdrawn_notifications_by_item_id( $friendship_id, $friendship ) {
    307     if ( bp_is_active( 'notifications' ) ) {
    308         bp_notifications_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' );
    309     }
     218    bp_notifications_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, buddypress()->friends->id, 'friendship_request' );
    310219}
    311220add_action( 'friends_friendship_withdrawn', 'bp_friends_mark_friendship_withdrawn_notifications_by_item_id', 10, 2 );
     
    319228 */
    320229function bp_friends_remove_notifications_data( $user_id = 0 ) {
    321     if ( bp_is_active( 'notifications' ) ) {
    322         bp_notifications_delete_notifications_from_user( $user_id, buddypress()->friends->id, 'friendship_request' );
    323     }
     230    bp_notifications_delete_notifications_from_user( $user_id, buddypress()->friends->id, 'friendship_request' );
    324231}
    325232add_action( 'friends_remove_data', 'bp_friends_remove_notifications_data', 10, 1 );
Note: See TracChangeset for help on using the changeset viewer.