WP_REST_Application_Passwords_Controller::prepare_item_for_response()
Prepares the application password for the REST response.
Method of the class: WP_REST_Application_Passwords_Controller{}
Hooks from the method
Return
WP_REST_Response|WP_Error
. Response object on success, or WP_Error object on failure.
Usage
$WP_REST_Application_Passwords_Controller = new WP_REST_Application_Passwords_Controller(); $WP_REST_Application_Passwords_Controller->prepare_item_for_response( $item, $request );
- $item(array) (required)
- WordPress representation of the item.
- $request(WP_REST_Request) (required)
- Request object.
Changelog
Since 5.6.0 | Introduced. |
WP_REST_Application_Passwords_Controller::prepare_item_for_response() WP REST Application Passwords Controller::prepare item for response code WP 6.6.1
public function prepare_item_for_response( $item, $request ) { $user = $this->get_user( $request ); if ( is_wp_error( $user ) ) { return $user; } $fields = $this->get_fields_for_response( $request ); $prepared = array( 'uuid' => $item['uuid'], 'app_id' => empty( $item['app_id'] ) ? '' : $item['app_id'], 'name' => $item['name'], 'created' => gmdate( 'Y-m-d\TH:i:s', $item['created'] ), 'last_used' => $item['last_used'] ? gmdate( 'Y-m-d\TH:i:s', $item['last_used'] ) : null, 'last_ip' => $item['last_ip'] ? $item['last_ip'] : null, ); if ( isset( $item['new_password'] ) ) { $prepared['password'] = $item['new_password']; } $prepared = $this->add_additional_fields_to_object( $prepared, $request ); $prepared = $this->filter_response_by_context( $prepared, $request['context'] ); $response = new WP_REST_Response( $prepared ); if ( rest_is_field_included( '_links', $fields ) || rest_is_field_included( '_embedded', $fields ) ) { $response->add_links( $this->prepare_links( $user, $item ) ); } /** * Filters the REST API response for an application password. * * @since 5.6.0 * * @param WP_REST_Response $response The response object. * @param array $item The application password array. * @param WP_REST_Request $request The request object. */ return apply_filters( 'rest_prepare_application_password', $response, $item, $request ); }