Changeset 12912
- Timestamp:
- 04/28/2021 11:49:18 PM (3 years ago)
- Location:
- trunk/src/bp-core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-filters.php
r12757 r12912 1068 1068 // Add 'List-Unsubscribe' header if applicable. 1069 1069 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, 1074 1075 '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 ); 1076 1085 1077 1086 if ( ! empty( $link ) ) { -
trunk/src/bp-core/bp-core-functions.php
r12905 r12912 4050 4050 $raw_hash = ! empty( $_GET['nh'] ) ? $_GET['nh'] : ''; 4051 4051 $raw_user_id = ! empty( $_GET['uid'] ) ? absint( $_GET['uid'] ) : 0; 4052 $new_hash = hash_hmac( 'sha1', "{$raw_email_type}:{$raw_user_id}", bp_email_get_salt() ); 4052 $raw_user_email = ! empty( $_GET['uem'] ) ? $_GET['uem'] : ''; 4053 $raw_member_id = ! empty( $_GET['mid'] ) ? absint( $_GET['mid'] ) : 0; 4054 $redirect_to = ''; 4055 4056 $new_hash = ''; 4057 if ( ! empty( $raw_user_id ) ) { 4058 $new_hash = hash_hmac( 'sha1', "{$raw_email_type}:{$raw_user_id}", bp_email_get_salt() ); 4059 } else if ( ! empty( $raw_user_email ) ) { 4060 $new_hash = hash_hmac( 'sha1', "{$raw_email_type}:{$raw_user_email}", bp_email_get_salt() ); 4061 } 4053 4062 4054 4063 // Check required values. 4055 if ( ! $raw_user_id|| ! $raw_email_type || ! $raw_hash || ! array_key_exists( $raw_email_type, $emails ) ) {4064 if ( ( ! $raw_user_id && ! $raw_user_email ) || ! $raw_email_type || ! $raw_hash || ! array_key_exists( $raw_email_type, $emails ) ) { 4056 4065 $redirect_to = wp_login_url(); 4057 4066 $result_msg = __( 'Something has gone wrong.', 'buddypress' ); … … 4079 4088 } 4080 4089 4090 // This is an unsubscribe request from a nonmember. 4091 } else if ( $raw_user_email ) { 4092 // Unsubscribe. 4093 if ( bp_user_has_opted_out() ) { 4094 $result_msg = $emails[ $raw_email_type ]['unsubscribe']['message']; 4095 $unsub_msg = __( 'You have already unsubscribed from all communication from this site.', 'buddypress' ); 4096 } else { 4097 $optout_args = array( 4098 'email_address' => $raw_user_email, 4099 'user_id' => $raw_member_id, 4100 'email_type' => $raw_email_type, 4101 'date_modified' => bp_core_current_time(), 4102 ); 4103 bp_add_optout( $optout_args ); 4104 $result_msg = $emails[ $raw_email_type ]['unsubscribe']['message']; 4105 $unsub_msg = __( 'You have been unsubscribed.', 'buddypress' ); 4106 } 4107 4108 // This is an unsubscribe request from a current member. 4081 4109 } else { 4082 4110 if ( bp_is_active( 'settings' ) ) { … … 4098 4126 } 4099 4127 4100 $message = sprintf( 4101 '%1$s <a href="%2$s">%3$s</a>', 4102 $result_msg, 4103 esc_url( $redirect_to ), 4104 esc_html( $unsub_msg ) 4105 ); 4106 4107 bp_core_add_message( $message ); 4108 bp_core_redirect( bp_core_get_user_domain( $raw_user_id ) ); 4109 4110 exit; 4128 if ( $raw_user_id && $redirect_to ) { 4129 $message = sprintf( 4130 '%1$s <a href="%2$s">%3$s</a>', 4131 $result_msg, 4132 esc_url( $redirect_to ), 4133 esc_html( $unsub_msg ) 4134 ); 4135 4136 // Template notices are only displayed on BP pages. 4137 bp_core_add_message( $message ); 4138 bp_core_redirect( bp_core_get_user_domain( $raw_user_id ) ); 4139 4140 exit; 4141 } else { 4142 wp_die( 4143 sprintf( '%1$s %2$s', esc_html( $unsub_msg ), esc_html( $result_msg ) ), 4144 esc_html( $unsub_msg ), 4145 array( 4146 'link_url' => home_url(), 4147 'link_text' => __( 'Go to website\'s home page.', 'buddypress' ), 4148 ) 4149 ); 4150 } 4111 4151 } 4112 4152 … … 4142 4182 } 4143 4183 4144 $link = add_query_arg( 4145 array( 4146 'action' => 'unsubscribe', 4147 'nh' => hash_hmac( 'sha1', "{$email_type}:{$user_id}", bp_email_get_salt() ), 4148 'nt' => $args['notification_type'], 4149 'uid' => $user_id, 4150 ), 4151 $redirect_to 4152 ); 4184 $link = ''; 4185 // Case where the recipient is a member of the site. 4186 if ( ! empty( $user_id ) ) { 4187 $link = add_query_arg( 4188 array( 4189 'action' => 'unsubscribe', 4190 'nh' => hash_hmac( 'sha1', "{$email_type}:{$user_id}", bp_email_get_salt() ), 4191 'nt' => $args['notification_type'], 4192 'uid' => $user_id, 4193 ), 4194 $redirect_to 4195 ); 4196 4197 // Case where the recipient is not a member of the site. 4198 } else if ( ! empty( $args['email_address'] ) ) { 4199 $email_address = $args['email_address']; 4200 $member_id = (int) $args['member_id']; 4201 $link = add_query_arg( 4202 array( 4203 'action' => 'unsubscribe', 4204 'nh' => hash_hmac( 'sha1', "{$email_type}:{$email_address}", bp_email_get_salt() ), 4205 'nt' => $args['notification_type'], 4206 'mid' => $member_id, 4207 'uem' => $email_address, 4208 ), 4209 $redirect_to 4210 ); 4211 } 4153 4212 4154 4213 /** … … 4362 4421 4363 4422 /** 4423 * Check an email address to see if that individual has opted out. 4424 * 4425 * @since 8.0.0 4426 * 4427 * @param string $email_address Email address to check. 4428 * @return bool True if the user has opted out, false otherwise. 4429 */ 4430 function bp_user_has_opted_out( $email_address = '' ) { 4431 $optout_class = new BP_Optout(); 4432 $optout_id = $optout_class->optout_exists( 4433 array( 4434 'email_address' => $email_address, 4435 ) 4436 ); 4437 return (bool) $optout_id; 4438 } 4439 4440 /** 4364 4441 * Delete a BP_Optout by ID. 4365 4442 *
Note: See TracChangeset
for help on using the changeset viewer.