Changeset 7087 for branches/2.6/src/includes/users/signups.php
- Timestamp:
- 05/28/2020 03:43:58 PM (6 years ago)
- File:
-
- 1 edited
-
branches/2.6/src/includes/users/signups.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/2.6/src/includes/users/signups.php
r6675 r7087 20 20 */ 21 21 function bbp_add_user_form_role_field() { 22 ?> 22 23 // Bail if current user cannot promote users 24 if ( ! current_user_can( 'promote_users' ) ) { 25 return; 26 } ?> 23 27 24 28 <table class="form-table"> … … 67 71 function bbp_user_add_role_to_signup_meta( $meta = array() ) { 68 72 69 // Posted role 70 $forum_role = isset( $_POST['bbp-forums-role'] ) 73 // Bail if already added 74 if ( ! empty( $meta['bbp_new_role'] ) ) { 75 return $meta; 76 } 77 78 // Role to validate 79 $to_validate = ! empty( $_POST['bbp-forums-role'] ) && is_string( $_POST['bbp-forums-role'] ) 71 80 ? sanitize_key( $_POST['bbp-forums-role'] ) 72 : bbp_get_default_role();73 74 // Role keys75 $ roles = array_keys( bbp_get_dynamic_roles());76 77 // Bail if posted role is not in dynamic roles78 if ( empty( $forum_role ) || ! in_array( $forum_role, $roles, true) ) {81 : ''; 82 83 // Validate the signup role 84 $valid_role = bbp_validate_registration_role( $to_validate ); 85 86 // Bail if errors 87 if ( bbp_has_errors() ) { 79 88 return $meta; 80 89 } 81 90 82 91 // Add role to meta 83 $meta['bbp_new_role'] = $ forum_role;92 $meta['bbp_new_role'] = $valid_role; 84 93 85 94 // Return meta … … 98 107 function bbp_user_add_role_on_invite( $user_id = '', $role = '', $newuser_key = '' ) { 99 108 100 // Posted role101 $ forum_role = isset( $_POST['bbp-forums-role'] )109 // Role to validate 110 $to_validate = ! empty( $_POST['bbp-forums-role'] ) && is_string( $_POST['bbp-forums-role'] ) 102 111 ? sanitize_key( $_POST['bbp-forums-role'] ) 103 : bbp_get_default_role();104 105 // Role keys106 $ roles = array_keys( bbp_get_dynamic_roles());107 108 // Bail if posted role is not in dynamic roles109 if ( empty( $forum_role ) || ! in_array( $forum_role, $roles, true) ) {112 : ''; 113 114 // Validate the signup role 115 $valid_role = bbp_validate_registration_role( $to_validate ); 116 117 // Bail if errors 118 if ( bbp_has_errors() ) { 110 119 return; 111 120 } … … 118 127 119 128 // Add the new role 120 $user_option['bbp_new_role'] = $ forum_role;129 $user_option['bbp_new_role'] = $valid_role; 121 130 122 131 // Update the invitation … … 133 142 function bbp_user_add_role_on_register( $user_id = '' ) { 134 143 135 // Posted role136 $ forum_role = isset( $_POST['bbp-forums-role'] )144 // Role to validate 145 $to_validate = ! empty( $_POST['bbp-forums-role'] ) && is_string( $_POST['bbp-forums-role'] ) 137 146 ? sanitize_key( $_POST['bbp-forums-role'] ) 138 : bbp_get_default_role();139 140 // Role keys141 $ roles = array_keys( bbp_get_dynamic_roles());142 143 // Bail if posted role is not in dynamic roles144 if ( empty( $forum_role ) || ! in_array( $forum_role, $roles, true) ) {147 : ''; 148 149 // Validate the signup role 150 $valid_role = bbp_validate_registration_role( $to_validate ); 151 152 // Bail if errors 153 if ( bbp_has_errors() ) { 145 154 return; 146 155 } 147 156 148 157 // Set the user role 149 bbp_set_user_role( $user_id, $ forum_role );158 bbp_set_user_role( $user_id, $valid_role ); 150 159 } 151 160 … … 159 168 function bbp_user_add_role_on_activate( $user_id = 0, $password = '', $meta = array() ) { 160 169 161 // Posted role162 $ forum_role = isset( $meta['bbp_new_role'] )170 // Role to validate 171 $to_validate = ! empty( $meta['bbp_new_role'] ) && is_string( $meta['bbp_new_role'] ) 163 172 ? sanitize_key( $meta['bbp_new_role'] ) 164 : bbp_get_default_role();165 166 // Sanitizerole167 $ roles = array_keys( bbp_get_dynamic_roles());168 169 // Bail if posted role is not in dynamic roles170 if ( empty( $forum_role ) || ! in_array( $forum_role, $roles, true) ) {173 : ''; 174 175 // Validate the signup role 176 $valid_role = bbp_validate_activation_role( $to_validate ); 177 178 // Bail if errors 179 if ( bbp_has_errors() ) { 171 180 return; 172 181 } 173 182 174 183 // Set the user role 175 bbp_set_user_role( $user_id, $forum_role ); 176 } 184 bbp_set_user_role( $user_id, $valid_role ); 185 } 186 187 /** Validators ****************************************************************/ 188 189 /** 190 * Validate the Forum role during signup 191 * 192 * This helper function performs a number of generic checks, and encapsulates 193 * the logic used to validate if a Forum Role is valid, typically during new 194 * user registration, but also when adding an existing user to a site in 195 * Multisite installations. 196 * 197 * @since 2.6.5 198 * 199 * @param string $to_validate A role ID to validate 200 * @return string A valid role ID, or empty string on error 201 */ 202 function bbp_validate_signup_role( $to_validate = '' ) { 203 204 // Default return value 205 $retval = ''; 206 207 // Add error if role is empty 208 if ( empty( $to_validate ) ) { 209 bbp_add_error( 'bbp_signup_role_empty', __( '<strong>ERROR</strong>: Empty role.', 'bbpress' ) ); 210 } 211 212 // Add error if posted role is not a valid role 213 if ( ! bbp_is_valid_role( $to_validate ) ) { 214 bbp_add_error( 'bbp_signup_role_invalid', __( '<strong>ERROR</strong>: Invalid role.', 'bbpress' ) ); 215 } 216 217 // If no errors, set return value to the role to validate 218 if ( ! bbp_has_errors() ) { 219 $retval = $to_validate; 220 } 221 222 // Filter & return 223 return (string) apply_filters( 'bbp_validate_signup_role', $retval, $to_validate ); 224 } 225 226 /** 227 * Validate the Forum role during the registration process 228 * 229 * @since 2.6.5 230 * 231 * @param string $to_validate A well-formed (string) role ID to validate 232 * @return string A valid role ID, or empty string on error 233 */ 234 function bbp_validate_registration_role( $to_validate = '' ) { 235 236 // Default return value 237 $retval = bbp_get_default_role(); 238 239 // Conditionally handle posted values for capable users 240 if ( is_admin() && current_user_can( 'create_users' ) ) { 241 $retval = $to_validate; 242 } 243 244 // Validate & return 245 return bbp_validate_signup_role( $retval ); 246 } 247 248 /** 249 * Validate the Forum role during activation 250 * 251 * This function exists simply for parity with registrations, and to maintain an 252 * intentional layer of abstraction from the more generic function it uses. 253 * 254 * @since 2.6.5 255 * 256 * @param string $to_validate A well-formed (string) role ID to validate 257 * @return string A valid role ID, or empty string on error 258 */ 259 function bbp_validate_activation_role( $to_validate = '' ) { 260 261 // Validate & return 262 return bbp_validate_signup_role( $to_validate ); 263 }
Note: See TracChangeset
for help on using the changeset viewer.