Ticket #6932: 6932.diff
File 6932.diff, 19.8 KB (added by , 9 years ago) |
---|
-
src/bp-activity/bp-activity-notifications.php
40 40 * @param int $receiver_user_id The ID of the user who is receiving the update. 41 41 */ 42 42 function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) { 43 43 44 $notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' ); 44 45 45 46 // Don't leave multiple notifications for the same activity item. … … 73 74 $group_name = bp_get_current_group_name(); 74 75 } 75 76 77 $activity_link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/'; 78 $unsubscribe_args = array( 79 'uid' => (int)$receiver_user_id, 80 'nt' => 'notification_activity_new_mention' 81 ); 82 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $activity_link, $unsubscribe_args ) ); 83 76 84 $args = array( 77 85 'tokens' => array( 78 86 'activity' => $activity, … … 81 89 'mentioned.url' => $message_link, 82 90 'poster.name' => $poster_name, 83 91 'receiver-user.id' => $receiver_user_id, 92 'unsubscribe' => $unsubscribe_link 84 93 ), 85 94 ); 86 95 … … 152 161 153 162 // Send an email if the user hasn't opted-out. 154 163 if ( 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) { 164 165 $activity_link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/'; 166 $unsubscribe_args = array( 167 'uid' => (int)$original_activity->user_id, 168 'nt' => 'notification_activity_new_reply' 169 ); 170 171 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $activity_link, $unsubscribe_args ) ); 155 172 $args = array( 156 173 'tokens' => array( 157 174 'comment.id' => $comment_id, … … 160 177 'original_activity.user_id' => $original_activity->user_id, 161 178 'poster.name' => $poster_name, 162 179 'thread.url' => esc_url( $thread_link ), 180 'unsubscribe' => $unsubscribe_link 163 181 ), 164 182 ); 165 183 -
src/bp-core/bp-core-actions.php
108 108 109 109 // Activation redirect. 110 110 add_action( 'bp_activation', 'bp_add_activation_redirect' ); 111 112 // Email unsubscribe. 113 add_action( 'bp_get_request_unsubscribe', 'bp_emails_unsubscribe' ); 114 -
src/bp-core/bp-core-filters.php
1024 1024 $tokens['recipient.email'] = ''; 1025 1025 $tokens['recipient.name'] = ''; 1026 1026 $tokens['recipient.username'] = ''; 1027 $tokens['unsubscribe'] = site_url( 'wp-login.php' );1028 1027 1029 1028 1030 1029 // Who is the email going to? … … 1041 1040 } 1042 1041 1043 1042 if ( $user_obj ) { 1044 // Unsubscribe link.1045 $tokens['unsubscribe'] = esc_url( sprintf(1046 '%s%s/notifications/',1047 bp_core_get_user_domain( $user_obj->ID ),1048 function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings'1049 ) );1050 1043 $tokens['recipient.username'] = $user_obj->user_login; 1051 1044 } 1052 1045 } -
src/bp-core/bp-core-functions.php
2898 2898 * on the email delivery class you are using. 2899 2899 */ 2900 2900 function bp_send_email( $email_type, $to, $args = array() ) { 2901 2901 2902 static $is_default_wpmail = null; 2902 2903 static $wp_html_emails = null; 2903 2904 … … 2954 2955 2955 2956 if ( $must_use_wpmail ) { 2956 2957 $to = $email->get( 'to' ); 2957 2958 2958 return wp_mail( 2959 2959 array_shift( $to )->get_address(), 2960 2960 $email->get( 'subject', 'replace-tokens' ), … … 2989 2989 } 2990 2990 2991 2991 $delivery = new $delivery_class(); 2992 2992 2993 $status = $delivery->bp_email( $email ); 2993 2994 2994 2995 if ( is_wp_error( $status ) ) { … … 3292 3293 'groups-membership-request-rejected' => __( 'Recipient had requested to join a group, which was rejected.', 'buddypress' ), 3293 3294 ); 3294 3295 } 3296 3297 /** 3298 * Handles unsubscribe action to unsubscribe user from notification emails. 3299 * 3300 * @since 3301 * 3302 */ 3303 function bp_emails_unsubscribe(){ 3304 3305 $request = $_GET; 3306 $admin_email = get_bloginfo( 'admin_email' ); 3307 $notifications_with_unsubscribe = array( 3308 'notification_activity_new_mention' => __( 'You will no longer receive emails when someone mentions you in an update.', 'buddypress' ), 3309 'notification_activity_new_reply' => __( 'You will no longer receive emails when someone replies to an update or comment you posted.', 'buddypress' ), 3310 'notification_messages_new_message' => __( 'You will no longer receive emails when someone sends you a message.', 'buddypress' ), 3311 'notification_friends_friendship_request' => __( 'You will no longer receive emails when someone sends you a friend request.', 'buddypress' ), 3312 'notification_friends_friendship_accepted' => __( 'You will no longer receive emails when someone accepts your friendship request.', 'buddypress' ), 3313 'notification_groups_invite' => __( 'You will no longer receive emails when you are invited to join a group.', 'buddypress' ), 3314 'notification_groups_group_updated' => __( 'You will no longer receive emails when one of your groups is updated.', 'buddypress' ), 3315 'notification_groups_membership_request' => __( 'You will no longer receive emails when someone requests to be a member of your group.', 'buddypress' ), 3316 'notification_membership_request_completed' => __( 'You will no longer receive emails when your request to join a group has been accepted or denied.', 'buddypress' ), 3317 'notification_groups_admin_promotion' => __( 'You will no longer receive emails when you have been promoted in a group.', 'buddypress' ) 3318 ); 3319 3320 $user_id = ( isset( $request['uid'] ) && !empty( $request['uid'] ) ) ? $request['uid'] : ''; 3321 $notification_type = ( isset( $request['nt'] ) && !empty( $request['nt'] ) ) ? $request['nt'] : ''; 3322 $to_check = ( isset( $request['nn'] ) && !empty( $request['nn'] ) ) ? $request['nn'] : ''; 3323 3324 $check_args = array( 3325 'uid' => $user_id, 3326 'nt' => $notification_type 3327 ); 3328 3329 $check = bp_check( $check_args ); 3330 3331 $current_user = is_user_logged_in() ? wp_get_current_user() : false; 3332 3333 if( empty( $user_id ) || empty( $notification_type ) || empty( $to_check ) || ! array_key_exists( $notification_type, $notifications_with_unsubscribe ) ){ 3334 3335 $settings_link = site_url( 'wp-login.php' ); 3336 $result_message = __( 'Sorry, something has gone wrong.', 'buddypress' ); 3337 $how_to_unsubscribe_message = __( 'Please log in and go to your settings to unsubscribe from notifications.', 'buddypress' ); 3338 } 3339 elseif( ! hash_equals( $check, $to_check ) ){ 3340 3341 $settings_link = site_url( 'wp-login.php' ); 3342 $result_message = __( 'Sorry the security check failed.', 'buddypress' ); 3343 $how_to_unsubscribe_message = __( 'Please log in and go to your settings to unsubscribe from notifications.', 'buddypress' ); 3344 3345 } 3346 elseif( is_user_logged_in() && (int)$current_user->ID !== (int)$user_id ){ 3347 3348 $settings_link = esc_url( sprintf( 3349 '%s%s/notifications/', 3350 bp_core_get_user_domain( (int)$current_user->ID ), 3351 function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings' 3352 ) ); 3353 3354 $result_message = __( 'Something has gone wrong.', 'buddypress' ); 3355 $how_to_unsubscribe_message = __( 'Please go to your settings to unsubscribe from notifications.', 'buddypress' ); 3356 } 3357 else{ 3358 3359 $settings_link = esc_url( sprintf( 3360 '%s%s/notifications/', 3361 bp_core_get_user_domain( $user_id ), 3362 function_exists( 'bp_get_settings_slug' ) ? bp_get_settings_slug() : 'settings' 3363 ) ); 3364 3365 // unsubscribe them by setting the usermeta to 'no' 3366 $is_unsubscribed = bp_update_user_meta( $user_id, $notification_type, 'no' ); 3367 $result_message = ( empty( $is_unsubscribed ) && bp_get_user_meta( $user_id, $notification_type, true ) !== 'no' ) ? __( 'Sorry, something has gone wrong with unsubscribing you from these emails.', 'buddypress' ) : $notifications_with_unsubscribe[ $notification_type ]; 3368 $how_to_unsubscribe_message = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' ); 3369 } 3370 3371 $message = sprintf( 3372 '%1$s <a href="%2$s">%3$s</a>', 3373 $result_message, 3374 $settings_link, 3375 $how_to_unsubscribe_message 3376 ); 3377 3378 bp_core_add_message( $message ); 3379 bp_core_redirect( esc_url( remove_query_arg( array_keys( $request ) ) ) ); 3380 } 3381 3382 /** 3383 * Creates unsubscribe link for notification emails. 3384 * 3385 * @since 3386 * 3387 * @param string $link URL to which the unsubscribe query string is appended. 3388 * @param array $args Used to build unsubscribe query string. 3389 * 3390 * @return string The unsubscribe link. 3391 */ 3392 function bp_email_get_unsubscribe_link( $link = null, $args = null ){ 3393 3394 if( ! is_array( $args ) ){ 3395 return site_url( 'wp-login.php' ); 3396 } 3397 3398 $check = bp_check( $args ); 3399 3400 $args['nn'] = $check; 3401 $args['action'] = 'unsubscribe'; 3402 3403 $unsubscribe_link = esc_url( add_query_arg( $args, $link ) ); 3404 3405 $args['link'] = esc_url( $link ); 3406 3407 /** 3408 * Filters the unsubscribe link. 3409 * 3410 * @since 3411 * 3412 * @param string $link URL to which the unsubscribe query string is appended. 3413 * @param array $args Used to build unsubscribe query string. 3414 */ 3415 return apply_filters( 'bp_email_get_unsubscribe_link', $unsubscribe_link, $args ); 3416 } 3417 -
src/bp-core/bp-core-options.php
893 893 */ 894 894 return apply_filters( 'bp_get_theme_package_id', bp_get_option( '_bp_theme_package_id', $default ) ); 895 895 } 896 897 /** 898 * Get a persistent salt not dependent on salts in wp-config.php. 899 * 900 * @return string 901 * 902 */ 903 function bp_get_salt(){ 904 905 $salt = bp_get_option( 'bp_persistent_salt' ); 906 if( ! $salt ){ 907 $salt = base64_encode( mcrypt_create_iv(12, MCRYPT_DEV_URANDOM) ); 908 bp_add_option( 'bp_persistent_salt', $salt ); 909 } 910 911 return $salt; 912 } 913 914 /** 915 * Get a function that makes a check for the given args. 916 * 917 * @param array $args Any array. 918 * 919 * @return string 920 * 921 */ 922 function bp_check( $args ){ 923 924 $salt = bp_get_salt(); 925 $string = ( is_array( $args) ) ? implode( ':', $args ) : (string)$args; 926 927 // should this return a substring like the nonce does? It's quite long. 928 $check = hash_hmac( 'md5', $string, $salt ); 929 930 return $check; 931 } -
src/bp-friends/bp-friends-notifications.php
32 32 return; 33 33 } 34 34 35 $friends_link = trailingslashit( esc_url( bp_core_get_user_domain( (int)$friend_id ) . bp_get_friends_slug() ) ); 36 $unsubscribe_args = array( 37 'uid' => (int)$friend_id, 38 'nt' => 'notification_friends_friendship_request' 39 ); 40 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $friends_link, $unsubscribe_args ) ); 41 35 42 $args = array( 36 43 'tokens' => array( 37 44 'friend-requests.url' => esc_url( bp_core_get_user_domain( $friend_id ) . bp_get_friends_slug() . '/requests/' ), … … 40 47 'initiator.id' => $initiator_id, 41 48 'initiator.url' => esc_url( bp_core_get_user_domain( $initiator_id ) ), 42 49 'initiator.name' => bp_core_get_user_displayname( $initiator_id ), 50 'unsubscribe' => $unsubscribe_link 43 51 ), 44 52 ); 45 53 bp_send_email( 'friends-request', $friend_id, $args ); … … 63 71 return; 64 72 } 65 73 74 $friends_link = trailingslashit( esc_url( bp_core_get_user_domain( (int)$initiator_id ) . bp_get_friends_slug() ) ); 75 $unsubscribe_args = array( 76 'uid' => (int)$initiator_id, 77 'nt' => 'notification_friends_friendship_accepted' 78 ); 79 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $friends_link, $unsubscribe_args ) ); 80 66 81 $args = array( 67 82 'tokens' => array( 68 83 'friend.id' => $friend_id, … … 70 85 'friend.name' => bp_core_get_user_displayname( $friend_id ), 71 86 'friendship.id' => $friendship_id, 72 87 'initiator.id' => $initiator_id, 88 'unsubscribe' => $unsubscribe_link 73 89 ), 74 90 ); 75 91 bp_send_email( 'friends-request-accepted', $initiator_id, $args ); -
src/bp-groups/bp-groups-notifications.php
68 68 continue; 69 69 } 70 70 71 $user_groups_link = bp_core_get_user_domain( (int)$user_id ) . bp_get_groups_slug(); 72 $unsubscribe_args = array( 73 'uid' => (int)$user_id, 74 'nt' => 'notification_groups_group_updated' 75 ); 76 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $user_groups_link, $unsubscribe_args ) ); 77 71 78 $args = array( 72 79 'tokens' => array( 73 80 'changed_text' => $changed_text, … … 75 82 'group.id' => $group_id, 76 83 'group.url' => esc_url( bp_get_group_permalink( $group ) ), 77 84 'group.name' => $group->name, 85 'unsubscribe' => $unsubscribe_link 78 86 ), 79 87 ); 80 88 bp_send_email( 'groups-details-updated', (int) $user_id, $args ); … … 124 132 return; 125 133 } 126 134 135 $user_groups_link = bp_core_get_user_domain( (int)$admin_id ) . bp_get_groups_slug(); 136 137 $unsubscribe_args = array( 138 'uid' => (int)$admin_id, 139 'nt' => 'notification_groups_membership_request' 140 ); 141 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $user_groups_link, $unsubscribe_args ) ); 142 127 143 $group = groups_get_group( array( 'group_id' => $group_id ) ); 128 144 $args = array( 129 145 'tokens' => array( … … 136 152 'profile.url' => esc_url( bp_core_get_user_domain( $requesting_user_id ) ), 137 153 'requesting-user.id' => $requesting_user_id, 138 154 'requesting-user.name' => bp_core_get_user_displayname( $requesting_user_id ), 155 'unsubscribe' => $unsubscribe_link 139 156 ), 140 157 ); 141 158 bp_send_email( 'groups-membership-request', (int) $admin_id, $args ); … … 172 189 return; 173 190 } 174 191 192 $user_groups_link = bp_core_get_user_domain( (int)$requesting_user_id ) . bp_get_groups_slug(); 193 194 $unsubscribe_args = array( 195 'uid' => (int)$requesting_user_id, 196 'nt' => 'notification_membership_request_completed' 197 ); 198 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $user_groups_link, $unsubscribe_args ) ); 199 175 200 $group = groups_get_group( array( 'group_id' => $group_id ) ); 176 201 $args = array( 177 202 'tokens' => array( … … 180 205 'group.name' => $group->name, 181 206 'group.url' => esc_url( bp_get_group_permalink( $group ) ), 182 207 'requesting-user.id' => $requesting_user_id, 208 'unsubscribe' => $unsubscribe_link 183 209 ), 184 210 ); 185 211 … … 226 252 return; 227 253 } 228 254 255 $user_groups_link = bp_core_get_user_domain( (int)$user_id ) . bp_get_groups_slug(); 256 257 $unsubscribe_args = array( 258 'uid' => (int)$user_id, 259 'nt' => 'notification_groups_admin_promotion' 260 ); 261 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $user_groups_link, $unsubscribe_args ) ); 262 229 263 $group = groups_get_group( array( 'group_id' => $group_id ) ); 230 264 $args = array( 231 265 'tokens' => array( … … 235 269 'group.name' => $group->name, 236 270 'promoted_to' => $promoted_to, 237 271 'user.id' => $user_id, 272 'unsubscribe' => $unsubscribe_link 238 273 ), 239 274 ); 240 275 bp_send_email( 'groups-member-promoted', (int) $user_id, $args ); … … 276 311 return; 277 312 } 278 313 279 $invited_link = bp_core_get_user_domain( $invited_user_id ) . bp_get_groups_slug(); 314 $invited_link = bp_core_get_user_domain( (int)$invited_user_id ) . bp_get_groups_slug(); 315 $unsubscribe_args = array( 316 'uid' => (int)$invited_user_id, 317 'nt' => 'notification_groups_invite' 318 ); 319 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $invited_link, $unsubscribe_args ) ); 320 280 321 $args = array( 281 322 'tokens' => array( 282 323 'group' => $group, … … 286 327 'inviter.url' => bp_core_get_user_domain( $inviter_user_id ), 287 328 'inviter.id' => $inviter_user_id, 288 329 'invites.url' => esc_url( $invited_link . '/invites/' ), 330 'unsubscribe' => $unsubscribe_link 289 331 ), 290 332 ); 291 333 bp_send_email( 'groups-invitation', (int) $invited_user_id, $args ); -
src/bp-groups/bp-groups-screens.php
1423 1423 $group_promo = 'yes'; 1424 1424 1425 1425 if ( !$group_request = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_membership_request', true ) ) 1426 $group_request = 'yes'; ?>1426 $group_request = 'yes'; 1427 1427 1428 if ( !$group_request_completed = bp_get_user_meta( bp_displayed_user_id(), 'notification_membership_request_completed', true ) ) 1429 $group_request_completed = 'yes'; ?> 1430 1428 1431 <table class="notification-settings" id="groups-notification-settings"> 1429 1432 <thead> 1430 1433 <tr> … … 1460 1463 <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-yes" value="yes" <?php checked( $group_request, 'yes', true ) ?>/><label for="notification-groups-membership-request-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td> 1461 1464 <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-no" value="no" <?php checked( $group_request, 'no', true ) ?>/><label for="notification-groups-membership-request-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td> 1462 1465 </tr> 1466 <tr id="groups-notification-settings-request-completed"> 1467 <td></td> 1468 <td><?php _ex( 'Your request to join a group has been approved or denied', 'group settings on notification settings page', 'buddypress' ) ?></td> 1469 <td class="yes"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-yes" value="yes" <?php checked( $group_request_completed, 'yes', true ) ?>/><label for="notification-groups-membership-request-completed-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td> 1470 <td class="no"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-no" value="no" <?php checked( $group_request_completed, 'no', true ) ?>/><label for="notification-groups-membership-request-completed-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td> 1471 </tr> 1463 1472 1464 1473 <?php 1465 1474 -
src/bp-messages/bp-messages-notifications.php
58 58 continue; 59 59 } 60 60 61 $messages_link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/'; 62 $unsubscribe_args = array( 63 'uid' => (int)$recipient->user_id, 64 'nt' => 'notification_messages_new_message' 65 ); 66 $unsubscribe_link = esc_url( bp_email_get_unsubscribe_link( $messages_link, $unsubscribe_args ) ); 67 61 68 $args = array( 62 69 'tokens' => array( 63 70 'usermessage' => wp_strip_all_tags( stripslashes( $message ) ), … … 64 71 'message.url' => esc_url( bp_core_get_user_domain( $recipient->user_id ) . bp_get_messages_slug() . '/view/' . $thread_id . '/' ), 65 72 'sender.name' => $sender_name, 66 73 'usersubject' => sanitize_text_field( stripslashes( $subject ) ), 74 'unsubscribe' => $unsubscribe_link 67 75 ), 68 76 ); 69 77 bp_send_email( 'messages-unread', $ud, $args );