BP_REST_Learndash_Courses_Endpoint::prepare_item_for_response( array $course, WP_REST_Request $request )
Prepares component data for return as an object.
Description
Parameters
- $course
-
(Required) The component and its values.
- $request
-
(Required) Full details about the request.
Return
(WP_REST_Response)
Source
File: bp-integrations/learndash/classes/class-bp-rest-learndash-courses-endpoint.php
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | public function prepare_item_for_response( $course , $request ) { $context = ! empty ( $request [ 'context' ] ) ? $request [ 'context' ] : 'view' ; // Base fields for every post. $data = array ( 'id' => $course ->ID, 'date' => $this ->prepare_date_response( $course ->post_date_gmt, $course ->post_date ), 'date_gmt' => $this ->prepare_date_response( $course ->post_date_gmt ), 'guid' => array ( 'rendered' => esc_url( get_the_permalink( $course ->ID ) ), 'raw' => $course ->guid, ), 'modified' => $this ->prepare_date_response( $course ->post_modified_gmt, $course ->post_modified ), 'modified_gmt' => $this ->prepare_date_response( $course ->post_modified_gmt ), 'slug' => $course ->post_name, 'status' => $course ->post_status, 'type' => $course ->post_type, 'author' => (int) $course ->post_author, 'menu_order' => (int) $course ->menu_order, 'featured_media' => $this ->get_feature_media( $course ), 'lessons_count' => count ( learndash_get_lesson_list( $course ->ID ) ), 'has_access' => sfwd_lms_has_access( $course ->ID, get_current_user_id() ), 'purchasable' => $this ->is_purchasable( $course ), 'status_bubble' => $this ->get_bubble_status( $course ), 'progress' => learndash_course_progress( array ( 'user_id' => get_current_user_id(), 'course_id' => $course ->ID, 'array' => true, ) ), 'last_activity' => $this ->get_last_activity( $course ), ); $data [ 'title' ] = array ( 'raw' => $course ->post_title, 'rendered' => bbp_get_topic_title( $course ->ID ), ); /* Prepare content */ if ( ! empty ( $course ->post_password ) ) { $this ->prepare_password_response( $course ->post_password ); } $data [ 'excerpt' ] = get_the_excerpt( $course ); $content = apply_filters( 'the_content' , $course ->post_content ); $data [ 'content' ] = array ( 'raw' => $course ->post_content, 'rendered' => $content , ); // Don't leave our cookie lying around: https://github.com/WP-API/WP-API/issues/1055. if ( ! empty ( $course ->post_password ) ) { $_COOKIE [ 'wp-postpass_' . COOKIEHASH ] = '' ; } /* -- Prepare content */ $data = $this ->add_additional_fields_to_object( $data , $request ); $data = $this ->filter_response_by_context( $data , $context ); // @todo add prepare_links $response = rest_ensure_response( $data ); $response ->add_links( $this ->prepare_links( $course ) ); /** * Filter a component value returned from the API. * * @param WP_REST_Response $response The Response data. * @param WP_REST_Request $request Request used to generate the response. * @param array $course The component and its values. * * @since 0.1.0 */ return apply_filters( 'bp_rest_learndash_course_prepare_value' , $response , $request , $course ); } |
Changelog
Version | Description |
---|---|
0.1.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.