wp_is_application_passwords_available example



    /** * Gets the requested user. * * @since 5.6.0 * * @param WP_REST_Request $request The request object. * @return WP_User|WP_Error The WordPress user associated with the request, or a WP_Error if none found. */
    protected function get_user( $request ) {
        if ( ! wp_is_application_passwords_available() ) {
            return new WP_Error(
                'application_passwords_disabled',
                __( 'Application passwords are not available.' ),
                array( 'status' => 501 )
            );
        }

        $error = new WP_Error(
            'rest_user_invalid_id',
            __( 'Invalid user ID.' ),
            array( 'status' => 404 )
        );
__( 'Your website appears to use Basic Authentication, which is not currently compatible with application passwords.' ),
        __( 'Cannot Authorize Application' ),
        array(
            'response'  => 501,
            'link_text' => __( 'Go Back' ),
            'link_url'  => $reject_url ? add_query_arg( 'error', 'disabled', $reject_url ) : admin_url(),
        )
    );
}

if ( ! wp_is_application_passwords_available_for_user( $user ) ) {
    if ( wp_is_application_passwords_available() ) {
        $message = __( 'Application passwords are not available for your account. Please contact the site administrator for assistance.' );
    } else {
        $message = __( 'Application passwords are not available.' );
    }

    wp_die(
        $message,
        __( 'Cannot Authorize Application' ),
        array(
            'response'  => 501,
            'link_text' => __( 'Go Back' ),
            


/** * Adds Application Passwords info to the REST API index. * * @since 5.6.0 * * @param WP_REST_Response $response The index response object. * @return WP_REST_Response */
function rest_add_application_passwords_to_index( $response ) {
    if ( ! wp_is_application_passwords_available() ) {
        return $response;
    }

    $response->data['authentication']['application-passwords'] = array(
        'endpoints' => array(
            'authorization' => admin_url( 'authorize-application.php' ),
        ),
    );

    return $response;
}

if ( is_email( $username ) ) {
            $error = new WP_Error(
                'invalid_email',
                __( '<strong>Error:</strong> Unknown email address. Check again or try your username.' )
            );
        } else {
            $error = new WP_Error(
                'invalid_username',
                __( '<strong>Error:</strong> Unknown username. Check again or try your email address.' )
            );
        }
    } elseif ( ! wp_is_application_passwords_available() ) {
        $error = new WP_Error(
            'application_passwords_disabled',
            __( 'Application passwords are not available.' )
        );
    } elseif ( ! wp_is_application_passwords_available_for_user( $user ) ) {
        $error = new WP_Error(
            'application_passwords_disabled_for_user',
            __( 'Application passwords are not available for your account. Please contact the site administrator for assistance.' )
        );
    }

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