Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/28/2021 11:49:18 PM (4 years ago)
Author:
dcavins
Message:

BP_Optouts: Improve unsubscribe behavior.

Improve unsubscribe link behavior when user is not
a site member, meaning that the unsubscribe is an
opt-out request.

  • Introduce bp_user_has_opted_out() as convenience

function for checking an email address's status

  • Build bp_email_get_unsubscribe_link() for

non-member case.

  • bp_email_unsubscribe_handler() handles

non-member case and uses wp_die() screen
to display message.

  • Fix unsusbscribe headers for opt-out links.

Props imath.

See #8448.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-filters.php

    r12757 r12912  
    10681068    // Add 'List-Unsubscribe' header if applicable.
    10691069    if ( ! empty( $tokens['unsubscribe'] ) && $tokens['unsubscribe'] !== wp_login_url() ) {
    1070         $user = get_user_by( 'email', $tokens['recipient.email'] );
    1071 
    1072         $link = bp_email_get_unsubscribe_link( array(
    1073             'user_id'           => $user->ID,
     1070        $user    = get_user_by( 'email', $tokens['recipient.email'] );
     1071        $user_id = isset( $user->ID ) ? $user->ID : 0;
     1072
     1073        $args = array(
     1074            'user_id'           => $user_id,
    10741075            'notification_type' => $email->get( 'type' ),
    1075         ) );
     1076        );
     1077
     1078        // If this email is not to a current member, include the nonmember's email address and the Inviter ID.
     1079        if ( ! $user_id ) {
     1080            $args['email_address'] = $tokens['recipient.email'];
     1081            $args['member_id']     = bp_loggedin_user_id();
     1082        }
     1083
     1084        $link = bp_email_get_unsubscribe_link( $args );
    10761085
    10771086        if ( ! empty( $link ) ) {
Note: See TracChangeset for help on using the changeset viewer.