WP_Application_Passwords::update_application_password() WordPress Method

This function updates an application password. It accepts two parameters: the password ID (an integer) and an array of data containing the new password (at minimum), the name, and the user ID. If the update is successful, the function will return the updated password array. Otherwise, it will return false.

WP_Application_Passwords::update_application_password( int $user_id, string $uuid, array $update = array() ) #

Updates an application password.


Parameters

$user_id

(int)(Required)User ID.

$uuid

(string)(Required)The password's UUID.

$update

(array)(Optional)Information about the application password to update.

Default value: array()


Top ↑

Return

(true|WP_Error) True if successful, otherwise a WP_Error instance is returned on error.


Top ↑

Source

File: wp-includes/class-wp-application-passwords.php

237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
public static function update_application_password( $user_id, $uuid, $update = array() ) {
    $passwords = static::get_user_application_passwords( $user_id );
 
    foreach ( $passwords as &$item ) {
        if ( $item['uuid'] !== $uuid ) {
            continue;
        }
 
        if ( ! empty( $update['name'] ) ) {
            $update['name'] = sanitize_text_field( $update['name'] );
        }
 
        $save = false;
 
        if ( ! empty( $update['name'] ) && $item['name'] !== $update['name'] ) {
            $item['name'] = $update['name'];
            $save         = true;
        }
 
        if ( $save ) {
            $saved = static::set_user_application_passwords( $user_id, $passwords );
 
            if ( ! $saved ) {
                return new WP_Error( 'db_error', __( 'Could not save application password.' ) );
            }
        }
 
        /**
         * Fires when an application password is updated.
         *
         * @since 5.6.0
         *
         * @param int   $user_id The user ID.
         * @param array $item    The updated app password details.
         * @param array $update  The information to update.
         */
        do_action( 'wp_update_application_password', $user_id, $item, $update );
 
        return true;
    }
 
    return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.