Ticket #8139: 8139.07-just-new-parts.patch
File 8139.07-just-new-parts.patch, 20.7 KB (added by , 3 years ago) |
---|
-
src/bp-core/bp-core-filters.php
diff --git src/bp-core/bp-core-filters.php src/bp-core/bp-core-filters.php index 1b285555c..85a8978d2 100644
function bp_email_set_default_headers( $headers, $property, $transform, $email ) 1074 1074 'user_id' => $user_id, 1075 1075 'notification_type' => $email->get( 'type' ), 1076 1076 ); 1077 // If this email is not to a current member, include the nonmember's email address. 1077 1078 // If this email is not to a current member, include the nonmember's email address and the Inviter ID. 1078 1079 if ( ! $user_id ) { 1079 1080 $args['email_address'] = $tokens['recipient.email']; 1081 $args['member_id'] = bp_loggedin_user_id(); 1080 1082 } 1081 1083 1082 1084 $link = bp_email_get_unsubscribe_link( $args ); -
src/bp-core/bp-core-functions.php
diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php index 98b46f5ce..9464d61ad 100644
function bp_email_get_type_schema( $field = 'description' ) { 4027 4027 'description' => __( 'A site member has sent a site invitation to the recipient.', 'buddypress' ), 4028 4028 'unsubscribe' => array( 4029 4029 'meta_key' => 'notification_bp_members_invite', 4030 'message' => __( 'You will no longer receive emails when you are invited to join asite.', 'buddypress' ),4030 'message' => __( 'You will no longer receive emails when you are invited to join this site.', 'buddypress' ), 4031 4031 ), 4032 4032 ); 4033 4033 … … function bp_email_unsubscribe_handler() { 4071 4071 $raw_user_id = ! empty( $_GET['uid'] ) ? absint( $_GET['uid'] ) : 0; 4072 4072 $raw_user_email = ! empty( $_GET['uem'] ) ? $_GET['uem'] : ''; 4073 4073 $raw_member_id = ! empty( $_GET['mid'] ) ? absint( $_GET['mid'] ) : 0; 4074 $redirect_to = ''; 4074 4075 4075 4076 $new_hash = ''; 4076 4077 if ( ! empty( $raw_user_id ) ) { … … function bp_email_unsubscribe_handler() { 4109 4110 // This is an unsubscribe request from a nonmember. 4110 4111 } else if ( $raw_user_email ) { 4111 4112 // Unsubscribe. 4112 error_log( 'caught unsubscribe request {$raw_user_email}' ); 4113 $optout_args = array( 4114 'email_address' => $raw_user_email, 4115 'user_id' => $raw_member_id, 4116 'email_type' => $raw_email_type, 4117 'date_modified' => bp_core_current_time(), 4118 ); 4119 $result = bp_add_optout( $optout_args ); 4120 $redirect_to = home_url(); 4121 $result_msg = $emails[ $raw_email_type ]['unsubscribe']['message']; 4122 $unsub_msg = __( 'You have been unsubscribed.', 'buddypress' ); 4113 if ( bp_user_has_opted_out() ) { 4114 $result_msg = $emails[ $raw_email_type ]['unsubscribe']['message']; 4115 $unsub_msg = __( 'You have already unsubscribed from all communication from this site.', 'buddypress' ); 4116 } else { 4117 $optout_args = array( 4118 'email_address' => $raw_user_email, 4119 'user_id' => $raw_member_id, 4120 'email_type' => $raw_email_type, 4121 'date_modified' => bp_core_current_time(), 4122 ); 4123 bp_add_optout( $optout_args ); 4124 $result_msg = $emails[ $raw_email_type ]['unsubscribe']['message']; 4125 $unsub_msg = __( 'You have been unsubscribed.', 'buddypress' ); 4126 } 4123 4127 4124 4128 // This is an unsubscribe request from a current member. 4125 4129 } else { … … function bp_email_unsubscribe_handler() { 4141 4145 $unsub_msg = __( 'You can change this or any other email notification preferences in your email settings.', 'buddypress' ); 4142 4146 } 4143 4147 4144 $message = sprintf( 4145 '%1$s <a href="%2$s">%3$s</a>', 4146 $result_msg, 4147 esc_url( $redirect_to ), 4148 esc_html( $unsub_msg ) 4149 ); 4148 if ( $raw_user_id && $redirect_to ) { 4149 $message = sprintf( 4150 '%1$s <a href="%2$s">%3$s</a>', 4151 $result_msg, 4152 esc_url( $redirect_to ), 4153 esc_html( $unsub_msg ) 4154 ); 4150 4155 4151 bp_core_add_message( $message ); 4156 // Template notices are only displayed on BP pages. 4157 bp_core_add_message( $message ); 4158 bp_core_redirect( bp_core_get_user_domain( $raw_user_id ) ); 4152 4159 4153 $page_redirect = ''; 4154 if ( $raw_user_id ) { 4155 $page_redirect = bp_core_get_user_domain( $raw_user_id ); 4160 exit; 4161 } else { 4162 wp_die( 4163 sprintf( '%1$s %2$s', esc_html( $unsub_msg ), esc_html( $result_msg ) ), 4164 esc_html( $unsub_msg ), 4165 array( 4166 'link_url' => home_url(), 4167 'link_text' => __( 'Go to website\'s home page.', 'buddypress' ), 4168 ) 4169 ); 4156 4170 } 4157 4158 bp_core_redirect( $page_redirect );4159 4160 exit;4161 4171 } 4162 4172 4163 4173 /** -
src/bp-core/classes/class-bp-email.php
diff --git src/bp-core/classes/class-bp-email.php src/bp-core/classes/class-bp-email.php index 78188fe4e..7c64102df 100644
class BP_Email { 999 999 $retval = new WP_Error( 'missing_parameter', __CLASS__, $this ); 1000 1000 } 1001 1001 1002 // Has the user opted out of receiving any email from this site? 1003 $recipient_address = array_shift( $this->get_to() )->get_address(); 1004 if ( bp_user_has_opted_out( $recipient_address ) ) { 1005 $retval = new WP_Error( 'user_has_opted_out', 'The email recipient has opted out from receiving communication from this site.', $this ); 1006 } 1007 1002 1008 /** 1003 1009 * Filters whether the email passes basic validation checks. 1004 1010 * -
src/bp-core/classes/class-bp-invitation.php
diff --git src/bp-core/classes/class-bp-invitation.php src/bp-core/classes/class-bp-invitation.php index 2f5504df2..c1e941de2 100644
class BP_Invitation { 660 660 * Associative array of arguments. All arguments but $page and 661 661 * $per_page can be treated as filter values for get_where_sql() 662 662 * and get_query_clauses(). All items are optional. 663 * @type int|array $id ID of invitation being updated.663 * @type int|array $id ID of invitation being fetched. 664 664 * Can be an array of IDs. 665 665 * @type int|array $user_id ID of user being queried. Can be an 666 666 * Can be an array of IDs. -
src/bp-members/bp-members-filters.php
diff --git src/bp-members/bp-members-filters.php src/bp-members/bp-members-filters.php index fcdcf4fa3..4c6eacead 100644
function bp_members_invitations_get_registration_welcome_message() { 209 209 return $message; 210 210 } 211 211 $invite = bp_get_members_invitation_from_request(); 212 if ( ! $invite->id ) {212 if ( ! $invite->id || ! $invite->invitee_email ) { 213 213 return $message; 214 214 } 215 215 216 // Fetch the display names of all inviters to personalize the welcome message. 217 $all_invites = bp_members_invitations_get_invites( 218 array( 216 // Check if the user is already a site member. 217 $maybe_user = get_user_by( 'email', $invite->invitee_email ); 218 219 // This user is already a member 220 if ( $maybe_user ) { 221 $message = sprintf( __( 'Welcome! You are already a member of this site. Please <a href="%1s">log in</a> to continue. If you have forgotten your password, you can <a href="%2s">reset it</a>.', 'buddypress' ), wp_login_url( bp_get_root_domain() ), wp_lostpassword_url( bp_get_root_domain() ) ); 222 // This user can register! 223 } else { 224 225 // Fetch the display names of all inviters to personalize the welcome message. 226 $args = array( 219 227 'invitee_email' => $invite->invitee_email, 220 228 'invite_sent' => 'sent', 221 ) 222 );223 $inviters = array();224 foreach ( $all_invites as $inv ) {225 $inviters[] = bp_core_get_user_displayname( $inv->inviter_id );226 }229 ); 230 $all_invites = bp_members_invitations_get_invites( $all_args ); 231 $inviters = array(); 232 foreach ( $all_invites as $inv ) { 233 $inviters[] = bp_core_get_user_displayname( $inv->inviter_id ); 234 } 227 235 228 if ( ! empty( $inviters ) ) { 229 $message = sprintf( _n( 'Welcome! You’ve been invited to join the site by the following user: %s. ', 'Welcome! You’ve been invited to join the site by the following users: %s. ', count( $inviters ), 'buddypress' ), implode( ', ', $inviters ) ); 230 } else { 231 $message = __( 'Welcome! You’ve been invited to join the site. ', 'buddypress' ); 236 if ( ! empty( $inviters ) ) { 237 $message = sprintf( _n( 'Welcome! You’ve been invited to join the site by the following user: %s. ', 'Welcome! You’ve been invited to join the site by the following users: %s. ', count( $inviters ), 'buddypress' ), implode( ', ', $inviters ) ); 238 } else { 239 $message = __( 'Welcome! You’ve been invited to join the site. ', 'buddypress' ); 240 } 232 241 } 242 233 243 return $message; 234 244 } 235 245 … … function bp_members_invitations_get_registration_welcome_message() { 246 256 function bp_members_invitations_get_modified_registration_disabled_message() { 247 257 $message = ''; 248 258 if ( bp_get_members_invitations_allowed() ) { 249 $message = __( 'Member registration is allowed by invitation only.', 'buddypress' ); 250 // Is the user trying to accept an invitation but something is wrong? 251 if ( ! empty( $_GET['inv'] ) ) { 252 $message .= __( ' It looks like there is a problem with your invitation. Please try again.', 'buddypress' ); 259 260 $invite = bp_get_members_invitation_from_request(); 261 if ( ! $invite->id || ! $invite->invitee_email ) { 262 return $message; 263 } 264 265 // Check if the user is already a site member. 266 $maybe_user = get_user_by( 'email', $invite->invitee_email ); 267 268 if ( ! $maybe_user ) { 269 $message = __( 'Member registration is allowed by invitation only.', 'buddypress' ); 270 // Is the user trying to accept an invitation but something is wrong? 271 if ( ! empty( $_GET['inv'] ) ) { 272 $message .= __( ' It looks like there is a problem with your invitation. Please try again.', 'buddypress' ); 273 } 274 } else if ( 'nouveau' === bp_get_theme_package_id() ) { 275 $message = sprintf( __( 'Welcome! You are already a member of this site. Please <a href="%1s">log in</a> to continue. If you have forgotten your password, you can <a href="%2s">reset it</a>.', 'buddypress' ), wp_login_url( bp_get_root_domain() ), wp_lostpassword_url( bp_get_root_domain() ) ); 253 276 } 254 277 } 255 278 return $message; -
src/bp-members/bp-members-functions.php
diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php index b6940ebb1..b6fdc0122 100644
function bp_members_invitations_delete_by_id( $id = 0 ) { 3538 3538 */ 3539 3539 function bp_members_invitations_delete_invites( $args ) { 3540 3540 $r = bp_parse_args( $args, array( 3541 'id' => 0,3541 'id' => false, 3542 3542 'invitee_email' => '', 3543 3543 'network_id' => get_current_network_id(), 3544 3544 'inviter_id' => null, 3545 3545 'accepted' => null, 3546 3546 'invite_sent' => null 3547 ), ' community_invitation_delete_invites' );3547 ), 'members_invitations_delete_invites' ); 3548 3548 3549 3549 $inv_args = array( 3550 3550 'id' => $r['id'], 3551 3551 'invitee_email' => $r['invitee_email'], 3552 3552 'item_id' => $r['network_id'], 3553 3553 'inviter_id' => $r['inviter_id'], 3554 'accepted' => $r['accepted'], 3555 'invite_sent' => $r['invite_sent'] 3554 3556 ); 3555 3557 3556 3558 // Find the invitation(s). -
src/bp-members/bp-members-invitations.php
diff --git src/bp-members/bp-members-invitations.php src/bp-members/bp-members-invitations.php index 2e1b5458e..2a04c3dbd 100644
function bp_members_invitations_complete_signup( $user_id, $user_login, $user_pa 139 139 } 140 140 add_action( 'bp_core_signup_user', 'bp_members_invitations_complete_signup', 10, 4 ); 141 141 142 /** 143 * Delete site membership invitations when an opt-out request is saved. 144 * 145 * @since 8.0.0 146 * 147 * @param BP_Optout $optout Characteristics of the opt-out just saved. 148 */ 149 function bp_members_invitations_delete_optedout_invites( $optout ) { 150 151 $args = array( 152 'invitee_email' => $optout->email_address, 153 ); 154 bp_members_invitations_delete_invites( $args ); 155 } 156 add_action( 'bp_optout_after_save', 'bp_members_invitations_delete_optedout_invites' ); -
src/bp-members/bp-members-notifications.php
diff --git src/bp-members/bp-members-notifications.php src/bp-members/bp-members-notifications.php index 23ee17a77..6571eb1e5 100644
defined( 'ABSPATH' ) || exit; 21 21 * @param string $action The kind of notification being rendered. 22 22 * @param int $item_id The primary item ID. 23 23 * @param int $secondary_item_id The secondary item ID. 24 * @param int $total_items The total number of me ssaging-related notifications24 * @param int $total_items The total number of members-related notifications 25 25 * waiting for the user. 26 26 * @param string $format 'string' for BuddyBar-compatible notifications; 27 27 * 'array' for WP Toolbar. Default: 'string'. … … function members_format_notifications( $action, $item_id, $secondary_item_id, $t 34 34 35 35 // Set up the string and the filter. 36 36 if ( (int) $total_items > 1 ) { 37 $link = bp_get_members_directory_permalink(); 38 /* translators: %d: the number of new users */ 39 $text = sprintf( __( '%d members accepted your membership invitations', 'buddypress' ), (int) $total_items ); 37 $link = bp_get_notifications_permalink(); 40 38 $amount = 'multiple'; 39 40 // This is the inviter whose invitation was accepted. 41 if ( 0 !== (int) $secondary_item_id ) { 42 /* translators: %d: the number of new users */ 43 $text = sprintf( __( '%d members accepted your membership invitations', 'buddypress' ), (int) $total_items ); 44 // This is someone who also invited that user to join. 45 } else { 46 /* translators: %d: the number of new users */ 47 $text = sprintf( __( '%d members are now members of the site', 'buddypress' ), (int) $total_items ); 48 } 41 49 } else { 42 $link = bp_core_get_user_domain( $item_id ); 43 /* translators: %s: new user name */ 44 $text = sprintf( __( '%s accepted your membership invitation', 'buddypress' ), bp_core_get_user_displayname( $item_id ) ); 50 $link = add_query_arg( 'welcome', 1, bp_core_get_user_domain( $item_id ) ); 45 51 $amount = 'single'; 46 }47 52 53 // This is the inviter whose invitation was accepted. 54 if ( 0 !== (int) $secondary_item_id ) { 55 /* translators: %s: new user name */ 56 $text = sprintf( __( '%s accepted your membership invitation', 'buddypress' ), bp_core_get_user_displayname( $item_id ) ); // This is someone who also invited that user to join. 57 } else { 58 /* translators: %s: new user name */ 59 $text = sprintf( __( '%s is now a member of the site', 'buddypress' ), bp_core_get_user_displayname( $item_id ) ); 60 } 61 } 48 62 break; 49 63 } 50 64 … … function members_format_notifications( $action, $item_id, $secondary_item_id, $t 103 117 */ 104 118 function bp_members_invitations_accepted_invitation_notification( $invite, $new_user, $inviter_id ) { 105 119 106 $res = bp_notifications_add_notification( array( 107 'user_id' => $inviter_id, 108 'item_id' => $new_user->ID, 109 'secondary_item_id' => $invite->id, 110 'component_name' => buddypress()->members->id, 111 'component_action' => 'accepted_invitation', 112 'date_notified' => bp_core_current_time(), 113 'is_new' => 1, 114 ) ); 120 // Add "user is a member of the site" notification for other inviters. 121 $args = array( 122 'invitee_email' => $new_user->user_email, 123 'accepted' => 'all', 124 ); 125 $invites = bp_members_invitations_get_invites( $args ); 126 127 if ( ! $invites ) { 128 return; 129 } 130 foreach ( $invites as $invite) { 131 // Include the id of the "accepted" invitation. 132 if ( $invite->inviter_id === $inviter_id ) { 133 $secondary_item_id = $invite->id; 134 } else { 135 // Else don't store the invite id, so we know this is not the primary. 136 $secondary_item_id = 0; 137 } 138 $res = bp_notifications_add_notification( array( 139 'user_id' => $invite->inviter_id, 140 'item_id' => $new_user->ID, 141 'secondary_item_id' => $secondary_item_id, 142 'component_name' => buddypress()->members->id, 143 'component_action' => 'accepted_invitation', 144 'date_notified' => bp_core_current_time(), 145 'is_new' => 1, 146 ) ); 147 } 115 148 } 116 149 add_action( 'community_membership_invite_accepted', 'bp_members_invitations_accepted_invitation_notification', 10, 3 ); 117 150 151 /** 152 * Mark accepted invitation notifications as read when user visits new user profile. 153 * 154 * 155 * @since 8.0.0 156 */ 157 function bp_members_mark_read_accepted_invitation_notification() { 158 if ( false === is_singular() || false === is_user_logged_in() || ! bp_is_user() || empty( $_GET['welcome'] ) ) { 159 return; 160 } 161 162 // Mark notification as read. 163 BP_Notifications_Notification::update( 164 array( 165 'is_new' => false 166 ), 167 array( 168 'user_id' => bp_loggedin_user_id(), 169 'item_id' => bp_displayed_user_id(), 170 ) 171 ); 172 } 173 add_action( 'bp_screens', 'bp_members_mark_read_accepted_invitation_notification' ); 174 118 175 /** 119 176 * Add Friends-related settings to the Settings > Notifications page. 120 177 * … … function members_screen_notification_settings() { 127 184 return; 128 185 } 129 186 130 if ( ! $allow_acceptance_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_invitation_accepted', true ) ) 187 if ( ! $allow_acceptance_emails = bp_get_user_meta( bp_displayed_user_id(), 'notification_members_invitation_accepted', true ) ) { 131 188 $allow_acceptance_emails = 'yes'; 189 } 132 190 ?> 133 191 134 192 <table class="notification-settings" id="members-notification-settings"> -
src/bp-members/classes/class-bp-members-invitation-manager.php
diff --git src/bp-members/classes/class-bp-members-invitation-manager.php src/bp-members/classes/class-bp-members-invitation-manager.php index 061c5bade..a708ee17b 100644
class BP_Members_Invitation_Manager extends BP_Invitation_Manager { 112 112 bp_update_user_meta( $new_user->ID, 'accepted_members_invitation', $invite->id ); 113 113 114 114 // We will mark all invitations to this user as "accepted." 115 $args = array( 116 'invitee_email' => $invite->invitee_email, 117 'item_id' => get_current_network_id(), 118 'type' => 'all' 119 ); 120 $this->mark_accepted( $args ); 115 if ( ! empty( $invite->invitee_email ) ) { 116 $args = array( 117 'invitee_email' => $invite->invitee_email, 118 'item_id' => get_current_network_id(), 119 'type' => 'all' 120 ); 121 $this->mark_accepted( $args ); 122 } 121 123 122 124 /** 123 125 * Fires after a user has accepted a site membership invite. 124 126 * 125 127 * @since 8.0.0 126 128 * 127 * @param BP_Invitation $invite Invitation that was accepted.129 * @param BP_Invitation $invite Invitation that was accepted. 128 130 * @param WP_user $new_user ID of the user who accepted the membership invite. 129 131 * @param int $inviter_id ID of the user who invited this user to the site. 130 132 */ -
src/bp-members/screens/register.php
diff --git src/bp-members/screens/register.php src/bp-members/screens/register.php index b08f6ece8..77929c442 100644
function bp_core_screen_signup() { 47 47 if ( bp_get_members_invitations_allowed() ) { 48 48 // Check to see if there's a valid invitation. 49 49 $maybe_invite = bp_get_members_invitation_from_request(); 50 if ( $maybe_invite->id ) { 51 $active_invite = true; 50 if ( $maybe_invite->id && $maybe_invite->invitee_email ) { 51 // Check if this user is already a member. 52 $args = array( 53 'invitee_email' => $maybe_invite->invitee_email, 54 'accepted' => 'accepted', 55 'fields' => 'ids', 56 ); 57 $accepted_invites = bp_members_invitations_get_invites( $args ); 58 if ( ! $accepted_invites ) { 59 $active_invite = true; 60 } 52 61 } 53 62 } 54 63 -
src/bp-members/screens/send-invites.php
diff --git src/bp-members/screens/send-invites.php src/bp-members/screens/send-invites.php index 6471ebf1d..f2af326e2 100644
function bp_network_invitations_catch_send_action() { 67 67 if ( bp_verify_nonce_request( 'bp_members_invitation_send_' . bp_displayed_user_id() ) && bp_members_invitations_invite_user( $invite_args ) ) { 68 68 bp_core_add_message( __( 'Invitation successfully sent!', 'buddypress' ) ); 69 69 } else { 70 bp_core_add_message( __( 'There was a problem sending that invitation. ', 'buddypress' ), 'error' );70 bp_core_add_message( __( 'There was a problem sending that invitation. The user could already be a member of the site or have chosen not to receive invitations from this site.', 'buddypress' ), 'error' ); 71 71 } 72 72 73 73 // Redirect. -
src/bp-templates/bp-legacy/buddypress-functions.php
diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php index 03c09ac00..4da3d1ae9 100644
function bp_legacy_theme_group_manage_members_add_search() { 2026 2026 function bp_members_invitations_add_legacy_welcome_message() { 2027 2027 $message = bp_members_invitations_get_registration_welcome_message(); 2028 2028 if ( $message ) { 2029 echo '<p>' . esc_html( $message ). '</p>';2029 echo '<p>' . $message . '</p>'; 2030 2030 } 2031 2031 } 2032 2032 add_action( 'bp_before_register_page', 'bp_members_invitations_add_legacy_welcome_message' );