get_user_application_passwords example

return $error;
    }

    /* * Strips out anything non-alphanumeric. This is so passwords can be used with * or without spaces to indicate the groupings for readability. * * Generated application passwords are exclusively alphanumeric. */
    $password = preg_replace( '/[^a-z\d]/i', '', $password );

    $hashed_passwords = WP_Application_Passwords::get_user_application_passwords( $user->ID );

    foreach ( $hashed_passwords as $key => $item ) {
        if ( ! wp_check_password( $password$item['password']$user->ID ) ) {
            continue;
        }

        $error = new WP_Error();

        /** * Fires when an application password has been successfully checked as valid. * * This allows for plugins to add additional constraints to prevent an application password from being used. * * @since 5.6.0 * * @param WP_Error $error The error object. * @param WP_User $user The user authenticating. * @param array $item The details about the application password. * @param string $password The raw supplied password. */


    /** * Prepares the list of items for displaying. * * @since 5.6.0 * * @global int $user_id User ID. */
    public function prepare_items() {
        global $user_id;
        $this->items = array_reverse( WP_Application_Passwords::get_user_application_passwords( $user_id ) );
    }

    /** * Handles the name column output. * * @since 5.6.0 * * @param array $item The current application password item. */
    public function column_name( $item ) {
        echo esc_html( $item['name'] );
    }
$new_item = array(
            'uuid'      => wp_generate_uuid4(),
            'app_id'    => empty( $args['app_id'] ) ? '' : $args['app_id'],
            'name'      => $args['name'],
            'password'  => $hashed_password,
            'created'   => time(),
            'last_used' => null,
            'last_ip'   => null,
        );

        $passwords   = static::get_user_application_passwords( $user_id );
        $passwords[] = $new_item;
        $saved       = static::set_user_application_passwords( $user_id$passwords );

        if ( ! $saved ) {
            return new WP_Error( 'db_error', __( 'Could not save application password.' ) );
        }

        $network_id = get_main_network_id();
        if ( ! get_network_option( $network_id, self::OPTION_KEY_IN_USE ) ) {
            update_network_option( $network_id, self::OPTION_KEY_IN_USE, true );
        }

        

    public function get_items( $request ) {
        $user = $this->get_user( $request );

        if ( is_wp_error( $user ) ) {
            return $user;
        }

        $passwords = WP_Application_Passwords::get_user_application_passwords( $user->ID );
        $response  = array();

        foreach ( $passwords as $password ) {
            $response[] = $this->prepare_response_for_collection(
                $this->prepare_item_for_response( $password$request )
            );
        }

        return new WP_REST_Response( $response );
    }

    
Home | Imprint | This part of the site doesn't use cookies.