Skip to:
Content

BuddyPress.org

Changeset 14132


Ignore:
Timestamp:
09/23/2025 07:58:33 PM (10 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/11.0/src/bp-core/bp-core-functions.php

    r14117 r14132  
    44174417                // Unsubscribe.
    44184418                $meta_key = $emails[ $raw_email_type ]['unsubscribe']['meta_key'];
    4419                 bp_update_user_meta( $raw_user_id, $meta_key, 'no' );
     4419
     4420                if ( 'no' !== bp_get_user_meta( $raw_user_id, $meta_key, true ) ) {
     4421                        bp_update_user_meta( $raw_user_id, $meta_key, 'no' );
     4422                }
    44204423
    44214424                $result_msg = $emails[ $raw_email_type ]['unsubscribe']['message'];
    4422                 $unsub_msg  = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' );
     4425
     4426                if ( bp_is_active( 'settings' ) ) {
     4427                        $unsub_msg = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' );
     4428                } else {
     4429                        $unsub_msg = '';
     4430                }
    44234431        }
    44244432
     
    44324440
    44334441                // Template notices are only displayed on BP pages.
    4434                 bp_core_add_message( $message );
    4435                 bp_core_redirect( bp_core_get_user_domain( $raw_user_id ) );
     4442                if ( is_user_logged_in() ) {
     4443                        bp_core_add_message( $message );
     4444                        bp_core_redirect( bp_members_get_user_url( $raw_user_id ) );
     4445                } else {
     4446                        wp_die(
     4447                                sprintf( '%1$s <a href="%2$s">%3$s</a>', esc_html( $result_msg ), esc_url( $redirect_to ), esc_html( $unsub_msg ) ),
     4448                                esc_html( $unsub_msg ),
     4449                                array(
     4450                                        'link_url'  => esc_url( home_url() ),
     4451                                        'link_text' => esc_html__( 'Go to website\'s home page.', 'buddypress' ),
     4452                                )
     4453                        );
     4454                }
    44364455
    44374456                exit;
Note: See TracChangeset for help on using the changeset viewer.