- Timestamp:
- 01/27/2021 07:03:42 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-application-passwords.php
r49787 r50030 59 59 * 60 60 * @since 5.6.0 61 * @since 5.7.0 Returns WP_Error if application name already exists. 61 62 * 62 63 * @param int $user_id User ID. … … 66 67 */ 67 68 public static function create_new_application_password( $user_id, $args = array() ) { 69 if ( ! empty( $args['name'] ) ) { 70 $args['name'] = sanitize_text_field( $args['name'] ); 71 } 72 68 73 if ( empty( $args['name'] ) ) { 69 return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ) ); 74 return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ), array( 'status' => 400 ) ); 75 } 76 77 if ( self::application_name_exists_for_user( $user_id, $args['name'] ) ) { 78 return new WP_Error( 'application_password_duplicate_name', __( 'Each application name should be unique.' ), array( 'status' => 409 ) ); 70 79 } 71 80 … … 164 173 165 174 /** 175 * Check if application name exists before for this user. 176 * 177 * @since 5.7.0 178 * 179 * @param int $user_id User ID. 180 * @param string $name Application name. 181 * 182 * @return bool Provided application name exists or not. 183 */ 184 public static function application_name_exists_for_user( $user_id, $name ) { 185 $passwords = static::get_user_application_passwords( $user_id ); 186 187 foreach ( $passwords as $password ) { 188 if ( strtolower( $password['name'] ) === strtolower( $name ) ) { 189 return true; 190 } 191 } 192 193 return false; 194 } 195 196 /** 166 197 * Updates an application password. 167 198 * … … 179 210 if ( $item['uuid'] !== $uuid ) { 180 211 continue; 212 } 213 214 if ( ! empty( $update['name'] ) ) { 215 $update['name'] = sanitize_text_field( $update['name'] ); 181 216 } 182 217
Note: See TracChangeset
for help on using the changeset viewer.