WP_REST_Application_Passwords_Controller::get_user()
Gets the requested user.
Метод класса: WP_REST_Application_Passwords_Controller{}
Хуков нет.
Возвращает
WP_User|WP_Error
. The WordPress user associated with the request, or a WP_Error if none found.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_user( $request );
- $request(WP_REST_Request) (обязательный)
- The request object.
Список изменений
С версии 5.6.0 | Введена. |
Код WP_REST_Application_Passwords_Controller::get_user() WP REST Application Passwords Controller::get user WP 6.2.2
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 ) ); $id = $request['user_id']; if ( 'me' === $id ) { if ( ! is_user_logged_in() ) { return new WP_Error( 'rest_not_logged_in', __( 'You are not currently logged in.' ), array( 'status' => 401 ) ); } $user = wp_get_current_user(); } else { $id = (int) $id; if ( $id <= 0 ) { return $error; } $user = get_userdata( $id ); } if ( empty( $user ) || ! $user->exists() ) { return $error; } if ( is_multisite() && ! user_can( $user->ID, 'manage_sites' ) && ! is_user_member_of_blog( $user->ID ) ) { return $error; } if ( ! wp_is_application_passwords_available_for_user( $user ) ) { return new WP_Error( 'application_passwords_disabled_for_user', __( 'Application passwords are not available for your account. Please contact the site administrator for assistance.' ), array( 'status' => 501 ) ); } return $user; }