Skip to:
Content

BuddyPress.org

Ticket #6932: 6932.6932.7.diff

File 6932.6932.7.diff, 30.2 KB (added by DJPaul, 4 years ago)
  • src/bp-activity/bp-activity-notifications.php

    diff --git a/src/bp-activity/bp-activity-notifications.php b/src/bp-activity/bp-activity-notifications.php
    index bafeb03..13e9615 100644
    a b function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) 
    5454                        $group_name = bp_get_current_group_name();
    5555                }
    5656
     57                $unsubscribe_args = array(
     58                        'user_id'           => $receiver_user_id,
     59                        'notification_type' => $email_type,
     60                );
     61
    5762                $args = array(
    5863                        'tokens' => array(
    5964                                'activity'         => $activity,
    function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) 
    6267                                'mentioned.url'    => $message_link,
    6368                                'poster.name'      => $poster_name,
    6469                                'receiver-user.id' => $receiver_user_id,
     70                                'unsubscribe'      => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    6571                        ),
    6672                );
    6773
    function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 
    113119
    114120                // Send an email if the user hasn't opted-out.
    115121                if ( 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
     122
     123                        $unsubscribe_args = array(
     124                                'user_id'           => $original_activity->user_id,
     125                                'notification_type' => 'activity-comment',
     126                        );
     127
    116128                        $args = array(
    117129                                'tokens' => array(
    118130                                        'comment.id'                => $comment_id,
    function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 
    121133                                        'original_activity.user_id' => $original_activity->user_id,
    122134                                        'poster.name'               => $poster_name,
    123135                                        'thread.url'                => esc_url( $thread_link ),
     136                                        'unsubscribe'               => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    124137                                ),
    125138                        );
    126139
    function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 
    155168
    156169                // Send an email if the user hasn't opted-out.
    157170                if ( 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) {
     171
     172                        $unsubscribe_args = array(
     173                                'user_id'           => $parent_comment->user_id,
     174                                'notification_type' => 'activity-comment-author',
     175                        );
     176
    158177                        $args = array(
    159178                                'tokens' => array(
    160179                                        'comment.id'             => $comment_id,
    function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 
    163182                                        'parent-comment-user.id' => $parent_comment->user_id,
    164183                                        'poster.name'            => $poster_name,
    165184                                        'thread.url'             => esc_url( $thread_link ),
     185                                        'unsubscribe'            => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    166186                                ),
    167187                        );
    168188
    function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 
    178198                 * @param int                  $comment_id     ID for the newly received comment.
    179199                 * @param int                  $commenter_id   ID of the user who made the comment.
    180200                 * @param array                $params         Arguments used with the original activity comment.
    181                  */
     201                 */
    182202                do_action( 'bp_activity_sent_reply_to_reply_notification', $parent_comment, $comment_id, $commenter_id, $params );
    183203        }
    184204}
  • src/bp-core/admin/bp-core-admin-schema.php

    diff --git a/src/bp-core/admin/bp-core-admin-schema.php b/src/bp-core/admin/bp-core-admin-schema.php
    index ba38b31..d4ad480 100644
    a b function bp_core_install_emails() { 
    517517        );
    518518
    519519        $emails       = bp_email_get_schema();
    520         $descriptions = bp_email_get_type_schema();
     520        $descriptions = bp_email_types_get_schema();
    521521
    522522        // Add these emails to the database.
    523523        foreach ( $emails as $id => $email ) {
    function bp_core_install_emails() { 
    530530                foreach ( $tt_ids as $tt_id ) {
    531531                        $term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() );
    532532                        wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array(
    533                                 'description' => $descriptions[ $id ],
     533                                'description' => $descriptions[ $id ]['description'],
    534534                        ) );
    535535                }
    536536        }
  • src/bp-core/bp-core-actions.php

    diff --git a/src/bp-core/bp-core-actions.php b/src/bp-core/bp-core-actions.php
    index e3c473e..8ed97ab 100644
    a b if ( is_admin() ) { 
    109109
    110110// Activation redirect.
    111111add_action( 'bp_activation', 'bp_add_activation_redirect' );
     112
     113// Email unsubscribe.
     114add_action( 'bp_get_request_unsubscribe', 'bp_emails_unsubscribe_handler' );
     115
  • src/bp-core/bp-core-filters.php

    diff --git a/src/bp-core/bp-core-filters.php b/src/bp-core/bp-core-filters.php
    index dd9645b..3fff5c0 100644
    a b function bp_email_set_default_tokens( $tokens, $property_name, $transform, $emai 
    10281028        $tokens['recipient.email']     = '';
    10291029        $tokens['recipient.name']      = '';
    10301030        $tokens['recipient.username']  = '';
    1031         $tokens['unsubscribe']         = site_url( 'wp-login.php' );
    10321031
    10331032
    10341033        // Who is the email going to?
    function bp_email_set_default_tokens( $tokens, $property_name, $transform, $emai 
    10451044                }
    10461045
    10471046                if ( $user_obj ) {
    1048                         // Unsubscribe link.
    1049                         $tokens['unsubscribe'] = esc_url( sprintf(
    1050                                 '%s%s/notifications/',
    1051                                 bp_core_get_user_domain( $user_obj->ID ),
    1052                                 function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings'
    1053                         ) );
    10541047                        $tokens['recipient.username'] = $user_obj->user_login;
    1055                 }
     1048                        if ( bp_is_active( 'settings' ) && empty( $tokens['unsubscribe'] ) ) {
     1049                            $tokens['unsubscribe'] = esc_url( sprintf(
     1050                                '%s%s/notifications/',
     1051                                bp_core_get_user_domain( $user_obj->ID ),
     1052                                bp_get_settings_slug()
     1053                            ) );
     1054                        }
     1055                }
    10561056        }
    10571057
     1058        // Set default unsubscribe link if not passed.
     1059    if ( empty( $tokens['unsubscribe'] ) ) {
     1060         $tokens['unsubscribe'] = site_url( 'wp-login.php' );
     1061    }
     1062
    10581063        // Email preheader.
    10591064        $post = $email->get_post_object();
    10601065        if ( $post ) {
  • src/bp-core/bp-core-functions.php

    diff --git a/src/bp-core/bp-core-functions.php b/src/bp-core/bp-core-functions.php
    index eb17831..ebece57 100644
    a b function bp_email_get_schema() { 
    33343334}
    33353335
    33363336/**
    3337  * Get a list of emails for populating email type taxonomy terms.
     3337 * Gets an array of the email types descriptions.
     3338 *
     3339 * Deprecated.
    33383340 *
    33393341 * @since 2.5.1
     3342 * @deprecated 2.6 Use bp_email_types_get_schema()
     3343 * @see bp_email_types_get_schema()
    33403344 *
    3341  * @return array
     3345 * @return array Array of the email type descriptions.
    33423346 */
    33433347function bp_email_get_type_schema() {
    3344         return array(
    3345                 'activity-comment'                   => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ),
    3346                 'activity-comment-author'            => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ),
    3347                 'activity-at-message'                => __( 'Recipient was mentioned in an activity update.', 'buddypress' ),
    3348                 'groups-at-message'                  => __( 'Recipient was mentioned in a group activity update.', 'buddypress' ),
    3349                 'core-user-registration'             => __( 'Recipient has registered for an account.', 'buddypress' ),
    3350                 'core-user-registration-with-blog'   => __( 'Recipient has registered for an account and site.', 'buddypress' ),
    3351                 'friends-request'                    => __( 'A member has sent a friend request to the recipient.', 'buddypress' ),
    3352                 'friends-request-accepted'           => __( 'Recipient has had a friend request accepted by a member.', 'buddypress' ),
    3353                 'groups-details-updated'             => __( "A group's details were updated.", 'buddypress' ),
    3354                 'groups-invitation'                  => __( 'A member has sent a group invitation to the recipient.', 'buddypress' ),
    3355                 'groups-member-promoted'             => __( "Recipient's status within a group has changed.", 'buddypress' ),
    3356                 'groups-membership-request'          => __( 'A member has requested permission to join a group.', 'buddypress' ),
    3357                 'messages-unread'                    => __( 'Recipient has received a private message.', 'buddypress' ),
    3358                 'settings-verify-email-change'       => __( 'Recipient has changed their email address.', 'buddypress' ),
    3359                 'groups-membership-request-accepted' => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ),
    3360                 'groups-membership-request-rejected' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ),
     3348        $type_schema_description = wp_list_pluck( bp_email_types_get_schema(), 'description' );
     3349        return $type_schema_description;
     3350}
     3351
     3352/**
     3353 * Get a list of emails for populating email type taxonomy terms.
     3354 *
     3355 * @since
     3356 *
     3357 * @return array Array of the email type schema.
     3358 */
     3359function bp_email_types_get_schema() {
     3360
     3361        $activity_comment = array(
     3362                'description'   => __( 'A member has replied to an activity update that the recipient posted.', 'buddypress' ),
     3363                'unsubscribe'   => array(
     3364                        'meta_key'      => 'notification_activity_new_reply',
     3365                        'message'       => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ),
     3366                        ),
     3367        );
     3368
     3369        $activity_comment_author = array(
     3370                'description'   => __( 'A member has replied to a comment on an activity update that the recipient posted.', 'buddypress' ),
     3371                'unsubscribe'   => array(
     3372                        'meta_key'      => 'notification_activity_new_reply',
     3373                        'message'       => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ),
     3374                        ),
     3375        );
     3376
     3377        $activity_at_message = array(
     3378                'description'   => __( 'Recipient was mentioned in an activity update.', 'buddypress' ),
     3379                'unsubscribe'   => array(
     3380                        'meta_key'      => 'notification_activity_new_mention',
     3381                        'message'       => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ),
     3382                ),
     3383        );
     3384
     3385        $groups_at_message = array(
     3386                'description'   => __( 'Recipient was mentioned in a group activity update.', 'buddypress' ),
     3387                'unsubscribe'   => array(
     3388                        'meta_key'      => 'notification_activity_new_mention',
     3389                        'message'       => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ),
     3390                ),
     3391        );
     3392
     3393        $core_user_registration = array(
     3394                'description'   => __( 'Recipient has registered for an account.', 'buddypress' ),
     3395                'unsubscribe'   => false,
     3396        );
     3397
     3398        $core_user_registration_with_blog = array(
     3399                'description'   => __( 'Recipient has registered for an account and site.', 'buddypress' ),
     3400                'unsubscribe'   => false,
     3401        );
     3402
     3403        $friends_request = array(
     3404                'description'   => __( 'A member has sent a friend request to the recipient.', 'buddypress' ),
     3405                'unsubscribe'   => array(
     3406                        'meta_key'      => 'notification_friends_friendship_request',
     3407                        'message'       => __( 'You will no longer receive emails when someone sends you a friend request.', 'buddypress' ),
     3408                ),
     3409        );
     3410
     3411        $friends_request_accepted = array(
     3412                'description'   => __( 'Recipient has had a friend request accepted by a member.', 'buddypress' ),
     3413                'unsubscribe'   => array(
     3414                        'meta_key'      => 'notification_friends_friendship_accepted',
     3415                        'message'       => __( 'You will no longer receive emails when someone accepts your friendship request.', 'buddypress' ),
     3416                ),
    33613417        );
     3418
     3419        $groups_details_updated = array(
     3420                'description'   => __( "A group's details were updated.", 'buddypress' ),
     3421                'unsubscribe'   => array(
     3422                        'meta_key'      => 'notification_groups_group_updated',
     3423                        'message'       => __( 'You will no longer receive emails when one of your groups is updated.', 'buddypress' ),
     3424                ),
     3425        );
     3426
     3427        $groups_details_updated = array(
     3428                'description'   => __( "A group's details were updated.", 'buddypress' ),
     3429                'unsubscribe'   => array(
     3430                        'meta_key'      => 'notification_groups_group_updated',
     3431                        'message'       => __( 'You will no longer receive emails when one of your groups is updated.', 'buddypress' ),
     3432                ),
     3433        );
     3434
     3435        $groups_invitation = array(
     3436                'description'   => __( 'A member has sent a group invitation to the recipient.', 'buddypress' ),
     3437                'unsubscribe'   => array(
     3438                        'meta_key'      => 'notification_groups_invite',
     3439                        'message'       => __( 'You will no longer receive emails when you are invited to join a group.', 'buddypress' ),
     3440                ),
     3441        );
     3442
     3443        $groups_member_promoted = array(
     3444                'description'   => __( "Recipient's status within a group has changed.", 'buddypress' ),
     3445                'unsubscribe'   => array(
     3446                        'meta_key'      => 'notification_groups_admin_promotion',
     3447                        'message'       => __( 'You will no longer receive emails when you have been promoted in a group.', 'buddypress' ),
     3448                ),
     3449        );
     3450
     3451        $groups_member_promoted = array(
     3452                'description'   => __( "Recipient's status within a group has changed.", 'buddypress' ),
     3453                'unsubscribe'   => array(
     3454                        'meta_key'      => 'notification_groups_admin_promotion',
     3455                        'message'       => __( 'You will no longer receive emails when you have been promoted in a group.', 'buddypress' ),
     3456                ),
     3457        );
     3458
     3459        $groups_membership_request = array(
     3460                'description'   => __( 'A member has requested permission to join a group.', 'buddypress' ),
     3461                'unsubscribe'   => array(
     3462                        'meta_key'      => 'notification_groups_membership_request',
     3463                        'message'       => __( 'You will no longer receive emails when someone requests to be a member of your group.', 'buddypress' ),
     3464                ),
     3465        );
     3466
     3467        $messages_unread = array(
     3468                'description'   => __( 'Recipient has received a private message.', 'buddypress' ),
     3469                'unsubscribe'   => array(
     3470                        'meta_key'      => 'notification_messages_new_message',
     3471                        'message'       => __( 'You will no longer receive emails when someone sends you a message.', 'buddypress' ),
     3472                ),
     3473        );
     3474
     3475        $settings_verify_email_change = array(
     3476                'description'   => __( 'Recipient has changed their email address.', 'buddypress' ),
     3477                'unsubscribe'   => false,
     3478        );
     3479
     3480        $groups_membership_request_accepted = array(
     3481                'description'   => __( 'Recipient had requested to join a group, which was accepted.', 'buddypress' ),
     3482                'unsubscribe'   => array(
     3483                        'meta_key'      => 'notification_membership_request_completed',
     3484                        'message'       => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ),
     3485                ),
     3486        );
     3487
     3488        $groups_membership_request_rejected = array(
     3489                'description'   => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ),
     3490                'unsubscribe'   => array(
     3491                        'meta_key'      => 'notification_membership_request_completed',
     3492                        'message'       => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ),
     3493                ),
     3494        );
     3495
     3496        $email_type_schema_array = array(
     3497                'activity-comment'                   => $activity_comment,
     3498                'activity-comment-author'            => $activity_comment_author,
     3499                'activity-at-message'                => $activity_at_message,
     3500                'groups-at-message'                  => $groups_at_message,
     3501                'core-user-registration'             => $core_user_registration,
     3502                'core-user-registration-with-blog'   => $core_user_registration_with_blog,
     3503                'friends-request'                    => $friends_request,
     3504                'friends-request-accepted'           => $friends_request_accepted,
     3505                'groups-details-updated'             => $groups_details_updated,
     3506                'groups-invitation'                  => $groups_invitation,
     3507                'groups-member-promoted'             => $groups_member_promoted,
     3508                'groups-membership-request'          => $groups_membership_request,
     3509                'messages-unread'                    => $messages_unread,
     3510                'settings-verify-email-change'       => $settings_verify_email_change,
     3511                'groups-membership-request-accepted' => $groups_membership_request_accepted,
     3512                'groups-membership-request-rejected' => $groups_membership_request_rejected,
     3513        );
     3514
     3515        /**
     3516        * Email types schema.
     3517        *
     3518        * @since
     3519        *
     3520        * @param array $email_type_schema_array {
     3521        *     The array of email types and their schema.
     3522        *
     3523        *     @type string $description The description of the action which causes this to trigger.
     3524        *     @type array  $email_type_schema_array['unsubscribe'] {
     3525        *           The unsubscribe array.
     3526        *           Setting the value to false indicates that a user cannot unsubscribe from this type.
     3527        *
     3528        *           @type string $email_type_schema_array['unsubscribe']['meta_key']    The meta_key used to toggle the email setting for this notification.
     3529        *           @type string $email_type_schema_array['unsubscribe']['message']     The message shown when the user has successfully unsubscribed.
     3530        *     }
     3531        * }
     3532        */
     3533        return apply_filters( 'bp_email_types_get_schema', $email_type_schema_array );
    33623534}
     3535
     3536/**
     3537 * Handles unsubscribe action to unsubscribe user from notification emails.
     3538 *
     3539 * @since
     3540 *
     3541 */
     3542function bp_emails_unsubscribe_handler() {
     3543
     3544        $request = $_GET;
     3545        $admin_email   = get_bloginfo( 'admin_email' );
     3546        $bp_email_schema = bp_email_types_get_schema();
     3547
     3548        $user_id = ( isset( $request['uid'] ) && ! empty( $request['uid'] ) ) ? (int) $request['uid'] : '';
     3549        $notification_type = ( isset( $request['nt'] ) && ! empty( $request['nt'] ) ) ? esc_attr( $request['nt'] ) : '';
     3550        $to_check = ( isset( $request['nn'] ) && ! empty( $request['nn'] ) ) ? $request['nn'] : '';
     3551
     3552        $check_args = array(
     3553                'uid' => $user_id,
     3554                'nt'  => $notification_type,
     3555        );
     3556
     3557        $check = bp_hash_array( $check_args );
     3558
     3559        $current_user = is_user_logged_in() ? wp_get_current_user() : false;
     3560
     3561        if ( empty( $user_id ) || empty( $notification_type ) || empty( $to_check ) || ! array_key_exists( $notification_type, $bp_email_schema ) ) {
     3562
     3563                $settings_link = site_url( 'wp-login.php' );
     3564                $result_message = __( 'Sorry, something has gone wrong.', 'buddypress' );
     3565                $how_to_unsubscribe_message = __( 'Please log in and go to your settings to unsubscribe from notifications.', 'buddypress' );
     3566        } elseif ( ! hash_equals( $check, $to_check ) ) {
     3567
     3568                $settings_link = site_url( 'wp-login.php' );
     3569                $result_message = __( 'Sorry the security check failed.', 'buddypress' );
     3570                $how_to_unsubscribe_message = __( 'Please log in and go to your settings to unsubscribe from notifications.', 'buddypress' );
     3571
     3572        } elseif ( is_user_logged_in() && (int) $current_user->ID !== (int) $user_id ) {
     3573
     3574                $settings_link = esc_url( sprintf(
     3575                        '%s%s/notifications/',
     3576                        bp_core_get_user_domain( (int) $current_user->ID ),
     3577                        function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings'
     3578                ) );
     3579
     3580                $result_message = __( 'Something has gone wrong.', 'buddypress' );
     3581                $how_to_unsubscribe_message = __( 'Please go to your settings to unsubscribe from notifications.', 'buddypress' );
     3582        } else {
     3583
     3584                $settings_link = esc_url( sprintf(
     3585                        '%s%s/notifications/',
     3586                        bp_core_get_user_domain( $user_id ),
     3587                        function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings'
     3588                ) );
     3589
     3590                // unsubscribe them by setting the usermeta to 'no'
     3591                $notification_meta_key = $bp_email_schema[ $notification_type ]['unsubscribe']['meta_key'];
     3592                $is_unsubscribed = bp_update_user_meta( $user_id, $notification_meta_key, 'no' );
     3593
     3594                $result_message = ( empty( $is_unsubscribed ) && bp_get_user_meta( $user_id, $notification_meta_key, true ) !== 'no' ) ? __( 'Sorry, something has gone wrong with unsubscribing you from these emails.', 'buddypress' ) : $bp_email_schema[ $notification_type ]['unsubscribe']['message'];
     3595
     3596                $how_to_unsubscribe_message = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' );
     3597        }
     3598
     3599        $message = sprintf(
     3600                '%1$s <a href="%2$s">%3$s</a>',
     3601                $result_message,
     3602                $settings_link,
     3603                $how_to_unsubscribe_message
     3604        );
     3605
     3606        bp_core_add_message( $message );
     3607        bp_core_redirect( esc_url( remove_query_arg( array_keys( $request ) ) ) );
     3608}
     3609
     3610/**
     3611 * Creates unsubscribe link for notification emails.
     3612 *
     3613 * @since
     3614 *
     3615 * @param string        $redirect_to The URL to which the unsubscribe query string is appended.
     3616 * @param array         $args        {
     3617 *
     3618 *    Used to build unsubscribe query string.
     3619 *
     3620 *    @type string $notification_type Which notification type is being sent.
     3621 *    @type string $user_id           The ID of the user to whom the notification is sent.
     3622 *    @type string $redirect_to       Optional. The url to which the user will be redirected. Default is the activity directory.
     3623 *
     3624 * }
     3625 * @return string The unsubscribe link.
     3626 */
     3627function bp_email_get_unsubscribe_link( $args = null ) {
     3628
     3629        $bp_emails_type_schema = bp_email_types_get_schema();
     3630
     3631        if ( ! is_array( $args ) || ! isset( $args['notification_type'] ) || ! array_key_exists( $args['notification_type'], $bp_emails_type_schema ) ) {
     3632                return site_url( 'wp-login.php' );
     3633        }
     3634
     3635        $notification_type = $unsubscribe_args['nt'] = esc_attr( $args['notification_type'] );
     3636        $user_id = $unsubscribe_args['uid'] = (int) $args['user_id'];
     3637
     3638        // If the activity type is not unsubscribable (ununsubscribable), return false.
     3639        if ( empty( $bp_emails_type_schema[ $notification_type ]['unsubscribe'] ) ) {
     3640                return false;
     3641        }
     3642
     3643        $redirect_to = ( isset( $args['redirect_to'] ) ) ? isset( $args['redirect_to'] ) : bp_get_activity_directory_permalink();
     3644
     3645        $check = bp_hash_array( $unsubscribe_args );
     3646
     3647        $unsubscribe_args['nn'] = $check;
     3648        $unsubscribe_args['action'] = 'unsubscribe';
     3649
     3650        $unsubscribe_link = esc_url_raw( add_query_arg( $unsubscribe_args, $redirect_to ) );
     3651
     3652        /**
     3653         * Filters the unsubscribe link.
     3654         *
     3655         * @since
     3656         *
     3657         * @param string        $redirect_to    URL to which the unsubscribe query string is appended.
     3658         * @param array         $args           Used to build unsubscribe query string.
     3659         */
     3660        return apply_filters( 'bp_email_get_unsubscribe_link', $unsubscribe_link, $redirect_to, $args );
     3661}
     3662
  • src/bp-core/bp-core-options.php

    diff --git a/src/bp-core/bp-core-options.php b/src/bp-core/bp-core-options.php
    index 7a9ba45..8f9e69f 100644
    a b function bp_get_theme_package_id( $default = 'legacy' ) { 
    853853         */
    854854        return apply_filters( 'bp_get_theme_package_id', bp_get_option( '_bp_theme_package_id', $default ) );
    855855}
     856
     857/**
     858 * Get a persistent salt not dependent on salts in wp-config.php.
     859 *
     860 * @return string
     861 *
     862 */
     863function bp_get_salt() {
     864
     865        $salt = bp_get_option( 'bp_persistent_salt' );
     866        if ( ! $salt ) {
     867                $salt = base64_encode( mcrypt_create_iv( 12, MCRYPT_DEV_URANDOM ) );
     868                bp_add_option( 'bp_persistent_salt', $salt );
     869        }
     870
     871        return $salt;
     872}
     873
     874/**
     875 * Get a function that makes a checkable hash for the given args.
     876 *
     877 * @param  array        $args   Any array.
     878 *
     879 * @return string
     880 *
     881 */
     882function bp_hash_array( $args ) {
     883
     884        $salt = bp_get_salt();
     885
     886        // order doesn't matter
     887        ksort( $args );
     888
     889        $string = ( is_array( $args ) ) ? implode( ':', $args ) : (string) $args;
     890
     891        // should this return a substring like the nonce does? It's quite long.
     892        $check = hash_hmac( 'md5', $string, $salt );
     893
     894        return $check;
     895}
  • src/bp-friends/bp-friends-notifications.php

    diff --git a/src/bp-friends/bp-friends-notifications.php b/src/bp-friends/bp-friends-notifications.php
    index c7a851e..d1ae381 100644
    a b function friends_notification_new_request( $friendship_id, $initiator_id, $frien 
    3232                return;
    3333        }
    3434
     35        $unsubscribe_args = array(
     36                'user_id'           => $friend_id,
     37                'notification_type' => 'friends-request',
     38        );
     39
    3540        $args = array(
    3641                'tokens' => array(
    3742                        'friend-requests.url' => esc_url( bp_core_get_user_domain( $friend_id ) . bp_get_friends_slug() . '/requests/' ),
    function friends_notification_new_request( $friendship_id, $initiator_id, $frien 
    4045                        'initiator.id'        => $initiator_id,
    4146                        'initiator.url'       => esc_url( bp_core_get_user_domain( $initiator_id ) ),
    4247                        'initiator.name'      => bp_core_get_user_displayname( $initiator_id ),
     48                        'unsubscribe'         => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    4349                ),
    4450        );
    4551        bp_send_email( 'friends-request', $friend_id, $args );
    function friends_notification_accepted_request( $friendship_id, $initiator_id, $ 
    6369                return;
    6470        }
    6571
     72        $unsubscribe_args = array(
     73                'user_id'           => $initiator_id,
     74                'notification_type' => 'friends-request-accepted',
     75        );
     76
    6677        $args = array(
    6778                'tokens' => array(
    6879                        'friend.id'      => $friend_id,
    function friends_notification_accepted_request( $friendship_id, $initiator_id, $ 
    7081                        'friend.name'    => bp_core_get_user_displayname( $friend_id ),
    7182                        'friendship.id'  => $friendship_id,
    7283                        'initiator.id'   => $initiator_id,
     84                        'unsubscribe'      => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    7385                ),
    7486        );
    7587        bp_send_email( 'friends-request-accepted', $initiator_id, $args );
  • src/bp-groups/bp-groups-notifications.php

    diff --git a/src/bp-groups/bp-groups-notifications.php b/src/bp-groups/bp-groups-notifications.php
    index 3ee37a2..6b6492c 100644
    a b function groups_notification_group_updated( $group_id = 0, $old_group = null ) { 
    6868                        continue;
    6969                }
    7070
     71                $unsubscribe_args = array(
     72                        'user_id'           => $user_id,
     73                        'notification_type' => 'groups-details-updated',
     74                );
     75
    7176                $args = array(
    7277                        'tokens' => array(
    7378                                'changed_text' => $changed_text,
    function groups_notification_group_updated( $group_id = 0, $old_group = null ) { 
    7580                                'group.id'     => $group_id,
    7681                                'group.url'    => esc_url( bp_get_group_permalink( $group ) ),
    7782                                'group.name'   => $group->name,
     83                                'unsubscribe'  => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    7884                        ),
    7985                );
    8086                bp_send_email( 'groups-details-updated', (int) $user_id, $args );
    function groups_notification_new_membership_request( $requesting_user_id = 0, $a 
    115121                        'item_id'           => $group_id,
    116122                        'secondary_item_id' => $requesting_user_id,
    117123                        'component_name'    => buddypress()->groups->id,
    118                         'component_action'  => 'new_membership_request'
     124                        'component_action'  => 'new_membership_request',
    119125                ) );
    120126        }
    121127
    function groups_notification_new_membership_request( $requesting_user_id = 0, $a 
    124130                return;
    125131        }
    126132
     133        $unsubscribe_args = array(
     134                'user_id'           => $admin_id,
     135                'notification_type' => 'groups-membership-request',
     136        );
     137
    127138        $group = groups_get_group( array( 'group_id' => $group_id ) );
    128139        $args  = array(
    129140                'tokens' => array(
    function groups_notification_new_membership_request( $requesting_user_id = 0, $a 
    136147                        'profile.url'          => esc_url( bp_core_get_user_domain( $requesting_user_id ) ),
    137148                        'requesting-user.id'   => $requesting_user_id,
    138149                        'requesting-user.name' => bp_core_get_user_displayname( $requesting_user_id ),
     150                        'unsubscribe'          => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    139151                ),
    140152        );
    141153        bp_send_email( 'groups-membership-request', (int) $admin_id, $args );
    function groups_notification_membership_request_completed( $requesting_user_id = 
    184196        );
    185197
    186198        if ( ! empty( $accepted ) ) {
     199
     200                $unsubscribe_args = array(
     201                        'user_id'           => $requesting_user_id,
     202                        'notification_type' => 'groups-membership-request-accepted',
     203                );
     204
     205                $args['tokens']['unsubscribe'] = esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) );
     206
    187207                bp_send_email( 'groups-membership-request-accepted', (int) $requesting_user_id, $args );
     208
    188209        } else {
     210
     211                $unsubscribe_args = array(
     212                        'user_id'           => $requesting_user_id,
     213                        'notification_type' => 'groups-membership-request-rejected',
     214                );
     215
     216                $args['tokens']['unsubscribe'] = esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) );
     217
    189218                bp_send_email( 'groups-membership-request-rejected', (int) $requesting_user_id, $args );
    190219        }
    191220}
    function groups_notification_promoted_member( $user_id = 0, $group_id = 0 ) { 
    226255                return;
    227256        }
    228257
     258        $unsubscribe_args = array(
     259                'user_id'           => $user_id,
     260                'notification_type' => 'groups-member-promoted',
     261        );
     262
    229263        $group = groups_get_group( array( 'group_id' => $group_id ) );
    230264        $args  = array(
    231265                'tokens' => array(
    function groups_notification_promoted_member( $user_id = 0, $group_id = 0 ) { 
    235269                        'group.name'  => $group->name,
    236270                        'promoted_to' => $promoted_to,
    237271                        'user.id'     => $user_id,
     272                        'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    238273                ),
    239274        );
    240275        bp_send_email( 'groups-member-promoted', (int) $user_id, $args );
    function groups_notification_group_invites( &$group, &$member, $inviter_user_id 
    277312        }
    278313
    279314        $invited_link = bp_core_get_user_domain( $invited_user_id ) . bp_get_groups_slug();
     315
     316        $unsubscribe_args = array(
     317                'user_id'           => $invited_user_id,
     318                'notification_type' => 'groups-invitation',
     319        );
     320
    280321        $args         = array(
    281322                'tokens' => array(
    282323                        'group'        => $group,
    function groups_notification_group_invites( &$group, &$member, $inviter_user_id 
    286327                        'inviter.url'  => bp_core_get_user_domain( $inviter_user_id ),
    287328                        'inviter.id'   => $inviter_user_id,
    288329                        'invites.url'  => esc_url( $invited_link . '/invites/' ),
     330                        'unsubscribe'  => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    289331                ),
    290332        );
    291333        bp_send_email( 'groups-invitation', (int) $invited_user_id, $args );
  • src/bp-messages/bp-messages-notifications.php

    diff --git a/src/bp-messages/bp-messages-notifications.php b/src/bp-messages/bp-messages-notifications.php
    index 0a0bca1..cb16804 100644
    a b function messages_notification_new_message( $raw_args = array() ) { 
    5858                        continue;
    5959                }
    6060
     61                $unsubscribe_args = array(
     62                        'user_id'           => $recipient->user_id,
     63                        'notification_type' => 'messages-unread',
     64                );
     65
    6166                $args = array(
    6267                        'tokens' => array(
    6368                                'usermessage' => wp_strip_all_tags( stripslashes( $message ) ),
    6469                                'message.url' => esc_url( bp_core_get_user_domain( $recipient->user_id ) . bp_get_messages_slug() . '/view/' . $thread_id . '/' ),
    6570                                'sender.name' => $sender_name,
    6671                                'usersubject' => sanitize_text_field( stripslashes( $subject ) ),
     72                                'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    6773                        ),
    6874                );
    6975                bp_send_email( 'messages-unread', $ud, $args );
  • tests/phpunit/testcases/admin/functions.php

    diff --git a/tests/phpunit/testcases/admin/functions.php b/tests/phpunit/testcases/admin/functions.php
    index cc6ea19..03def16 100644
    a b class BP_Tests_Admin_Functions extends BP_UnitTestCase { 
    252252                        'hide_empty' => false,
    253253                ) );
    254254
    255                 $correct_descriptions = bp_email_get_type_schema();
     255                $correct_descriptions = bp_email_types_get_schema();
    256256                foreach ( $d_terms as $d_term ) {
    257                         $correct_description = $correct_descriptions[ $d_term->slug ];
     257                        $correct_description = $correct_descriptions[ $d_term->slug ]['description'];
    258258                        $this->assertSame( $correct_description, $d_term->description );
    259259                }
    260260        }