elete_application_password( $user_id, $uuid ) { $passwords = static::get_user_application_passwords( $user_id ); foreach ( $passwords as $key => $item ) { if ( $item['uuid'] === $uuid ) { unset( $passwords[ $key ] ); $saved = static::set_user_application_passwords( $user_id, $passwords ); if ( ! $saved ) { return new WP_Error( 'db_error', __( 'Could not delete application password.' ) ); } /** * Fires when an application password is deleted. * * @since 5.6.0 * * @param int $user_id The user ID. * @param array $item The data about the application password. */ do_action( 'wp_delete_application_password', $user_id, $item ); return true; } } return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) ); } /** * Deletes all application passwords for the given user. * * @since 5.6.0 * * @param int $user_id User ID. * @return int|WP_Error The number of passwords that were deleted or a WP_Error on failure. */ public static function delete_all_application_passwords( $user_id ) { $passwords = static::get_user_application_passwords( $user_id ); if ( $passwords ) { $saved = static::set_user_application_passwords( $user_id, array() ); if ( ! $saved ) { return new WP_Error( 'db_error', __( 'Could not delete application passwords.' ) ); } foreach ( $passwords as $item ) { /** This action is documented in wp-includes/class-wp-application-passwords.php */ do_action( 'wp_delete_application_password', $user_id, $item ); } return count( $passwords ); } return 0; } /** * Sets a users application passwords. * * @since 5.6.0 * * @param int $user_id User ID. * @param array $passwords Application passwords. * * @return bool */ protected static function set_user_application_passwords( $user_id, $passwords ) { return update_user_meta( $user_id, static::USERMETA_KEY_APPLICATION_PASSWORDS, $passwords ); } /** * Sanitizes and then splits a password into smaller chunks. * * @since 5.6.0 * * @param string $raw_password The raw application password. * @return string The chunked password. */ public static function chunk_password( $raw_password ) { $raw_password = preg_replace( '/[^a-z\d]/i', '', $raw_password ); return trim( chunk_split( $raw_password, 4, ' ' ) ); } } {"id":289,"date":"2021-04-05T10:37:31","date_gmt":"2021-04-05T08:37:31","guid":{"rendered":"http:\/\/partelec.fr\/?page_id=289"},"modified":"2021-04-05T11:29:51","modified_gmt":"2021-04-05T09:29:51","slug":"demo","status":"publish","type":"page","link":"http:\/\/partelec.fr\/en\/demo\/","title":{"rendered":"Demonstration"},"content":{"rendered":"","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"http:\/\/partelec.fr\/wp-json\/wp\/v2\/pages\/289"}],"collection":[{"href":"http:\/\/partelec.fr\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/partelec.fr\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/partelec.fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/partelec.fr\/wp-json\/wp\/v2\/comments?post=289"}],"version-history":[{"count":1,"href":"http:\/\/partelec.fr\/wp-json\/wp\/v2\/pages\/289\/revisions"}],"predecessor-version":[{"id":290,"href":"http:\/\/partelec.fr\/wp-json\/wp\/v2\/pages\/289\/revisions\/290"}],"wp:attachment":[{"href":"http:\/\/partelec.fr\/wp-json\/wp\/v2\/media?parent=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}