wp/wp-includes/class-wp-application-passwords.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     9 /**
     9 /**
    10  * Class for displaying, modifying, and sanitizing application passwords.
    10  * Class for displaying, modifying, and sanitizing application passwords.
    11  *
    11  *
    12  * @package WordPress
    12  * @package WordPress
    13  */
    13  */
       
    14 #[AllowDynamicProperties]
    14 class WP_Application_Passwords {
    15 class WP_Application_Passwords {
    15 
    16 
    16 	/**
    17 	/**
    17 	 * The application passwords user meta key.
    18 	 * The application passwords user meta key.
    18 	 *
    19 	 *
    21 	 * @var string
    22 	 * @var string
    22 	 */
    23 	 */
    23 	const USERMETA_KEY_APPLICATION_PASSWORDS = '_application_passwords';
    24 	const USERMETA_KEY_APPLICATION_PASSWORDS = '_application_passwords';
    24 
    25 
    25 	/**
    26 	/**
    26 	 * The option name used to store whether application passwords is in use.
    27 	 * The option name used to store whether application passwords are in use.
    27 	 *
    28 	 *
    28 	 * @since 5.6.0
    29 	 * @since 5.6.0
    29 	 *
    30 	 *
    30 	 * @var string
    31 	 * @var string
    31 	 */
    32 	 */
    39 	 * @var int
    40 	 * @var int
    40 	 */
    41 	 */
    41 	const PW_LENGTH = 24;
    42 	const PW_LENGTH = 24;
    42 
    43 
    43 	/**
    44 	/**
    44 	 * Checks if Application Passwords are being used by the site.
    45 	 * Checks if application passwords are being used by the site.
    45 	 *
    46 	 *
    46 	 * This returns true if at least one Application Password has ever been created.
    47 	 * This returns true if at least one application password has ever been created.
    47 	 *
    48 	 *
    48 	 * @since 5.6.0
    49 	 * @since 5.6.0
    49 	 *
    50 	 *
    50 	 * @return bool
    51 	 * @return bool
    51 	 */
    52 	 */
    65 	 *     Arguments used to create the application password.
    66 	 *     Arguments used to create the application password.
    66 	 *
    67 	 *
    67 	 *     @type string $name   The name of the application password.
    68 	 *     @type string $name   The name of the application password.
    68 	 *     @type string $app_id A UUID provided by the application to uniquely identify it.
    69 	 *     @type string $app_id A UUID provided by the application to uniquely identify it.
    69 	 * }
    70 	 * }
    70 	 * @return array|WP_Error The first key in the array is the new password, the second is its detailed information.
    71 	 * @return array|WP_Error {
    71 	 *                        A WP_Error instance is returned on error.
    72 	 *     Application password details, or a WP_Error instance if an error occurs.
       
    73 	 *
       
    74 	 *     @type string $0 The unhashed generated application password.
       
    75 	 *     @type array  $1 {
       
    76 	 *         The details about the created password.
       
    77 	 *
       
    78 	 *         @type string $uuid      The unique identifier for the application password.
       
    79 	 *         @type string $app_id    A UUID provided by the application to uniquely identify it.
       
    80 	 *         @type string $name      The name of the application password.
       
    81 	 *         @type string $password  A one-way hash of the password.
       
    82 	 *         @type int    $created   Unix timestamp of when the password was created.
       
    83 	 *         @type null   $last_used Null.
       
    84 	 *         @type null   $last_ip   Null.
       
    85 	 *     }
       
    86 	 * }
    72 	 */
    87 	 */
    73 	public static function create_new_application_password( $user_id, $args = array() ) {
    88 	public static function create_new_application_password( $user_id, $args = array() ) {
    74 		if ( ! empty( $args['name'] ) ) {
    89 		if ( ! empty( $args['name'] ) ) {
    75 			$args['name'] = sanitize_text_field( $args['name'] );
    90 			$args['name'] = sanitize_text_field( $args['name'] );
    76 		}
    91 		}
   310 			}
   325 			}
   311 
   326 
   312 			return true;
   327 			return true;
   313 		}
   328 		}
   314 
   329 
   315 		// Specified Application Password not found!
   330 		// Specified application password not found!
   316 		return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
   331 		return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
   317 	}
   332 	}
   318 
   333 
   319 	/**
   334 	/**
   320 	 * Deletes an application password.
   335 	 * Deletes an application password.