LLMS_REST_Posts_Controller::prepare_item_for_response( LLMS_Post_Model $object, WP_REST_Request $request )
Prepare a single item for the REST response
Parameters Parameters
- $object
-
(LLMS_Post_Model) (Required) LLMS post object.
- $request
-
(WP_REST_Request) (Required) Request object.
Return Return
(WP_Error|WP_REST_Response) Response object on success, or WP_Error object on failure.
Source Source
File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-posts-controller.php
'protected' => (bool) $password, ), 'excerpt' => array( 'raw' => $object->get( 'excerpt', true ), 'rendered' => $password_required ? '' : apply_filters( 'the_excerpt', $object->get( 'excerpt' ) ), 'protected' => (bool) $password, ), ); return $data; } /** * Prepares data of a single object for response. * * @since 1.0.0-beta.27 * * @param obj $object Raw object from database. * @param WP_REST_Request $request Request object. * @return array */ protected function prepare_object_data_for_response( $object, $request ) { // Need to set the global $post because of references to the global $post when e.g. filtering the content, or processing blocks/shortcodes. global $post; $temp = $post; $post = $object->get( 'post' ); // phpcs:ignore setup_postdata( $post ); $removed_filters_for_response = $this->maybe_remove_filters_for_response( $object ); $has_password_filter = false; if ( $this->can_access_password_content( $object, $request ) ) { // Allow access to the post, permissions already checked before. add_filter( 'post_password_required', '__return_false' ); $has_password_filter = true; } $data = parent::prepare_object_data_for_response( $object, $request ); // Filter data including only schema props. $data = array_intersect_key( $data, array_flip( $this->get_fields_for_response( $request ) ) );
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.14 | Pass the $request parameter to prepare_links() . |
1.0.0-beta.1 | Introduced. |