Skip to:
Content

BuddyPress.org

Changeset 14125


Ignore:
Timestamp:
09/23/2025 02:14:55 PM (3 months ago)
Author:
dcavins
Message:

Improve behavior of bp_email_unsubscribe_handler().

After the changes in the "Improve security of status update messages" changeset, non-logged-in users clicking an unsubscribe link received no feedback on the success of their action.

Props emaralive.

Fixes #9301.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/14.0/src/bp-core/bp-core-functions.php

    r14103 r14125  
    45784578        // Unsubscribe.
    45794579        $meta_key = $emails[ $raw_email_type ]['unsubscribe']['meta_key'];
    4580         bp_update_user_meta( $raw_user_id, $meta_key, 'no' );
     4580
     4581        if ( 'no' !== bp_get_user_meta( $raw_user_id, $meta_key, true ) ) {
     4582            bp_update_user_meta( $raw_user_id, $meta_key, 'no' );
     4583        }
    45814584
    45824585        $result_msg = $emails[ $raw_email_type ]['unsubscribe']['message'];
    4583         $unsub_msg  = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' );
     4586
     4587        if ( bp_is_active( 'settings' ) ) {
     4588            $unsub_msg = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' );
     4589        } else {
     4590            $unsub_msg = '';
     4591        }
    45844592    }
    45854593
     
    45934601
    45944602        // Template notices are only displayed on BP pages.
    4595         bp_core_add_message( $message );
    4596         bp_core_redirect( bp_members_get_user_url( $raw_user_id ) );
     4603        if ( is_user_logged_in() ) {
     4604            bp_core_add_message( $message );
     4605            bp_core_redirect( bp_members_get_user_url( $raw_user_id ) );
     4606        } else {
     4607            wp_die(
     4608                sprintf( '%1$s <a href="%2$s">%3$s</a>', esc_html( $result_msg ), esc_url( $redirect_to ), esc_html( $unsub_msg ) ),
     4609                esc_html( $unsub_msg ),
     4610                array(
     4611                    'link_url'  => esc_url( home_url() ),
     4612                    'link_text' => esc_html__( 'Go to website\'s home page.', 'buddypress' ),
     4613                )
     4614            );
     4615        }
    45974616
    45984617        exit;
Note: See TracChangeset for help on using the changeset viewer.