LLMS_REST_Courses_Controller::prepare_item_for_database( WP_REST_Request $request )
Prepares a single post for create or update.
Parameters Parameters
- $request
-
(WP_REST_Request) (Required) Request object.
Return Return
(array|WP_Error) Array of llms post args or WP_Error.
Source Source
File: libraries/lifterlms-rest/includes/server/class-llms-rest-courses-controller.php
* * @since 1.0.0-beta.1 * @since 1.0.0-beta.7 `access_opens_date`, `access_closes_date`, `enrollment_opens_date`, `enrollment_closes_date` * treated in @see `update_additional_object_fields()` method so to better handle the update of the * course's properties `time_period` and `enrollment_period` whose values are derived from them and need to be * passed to `$course->set_bulk()` only if they differ from their current values, otherwise we'd get a WP_Error * which the consumer cannot avoid having no direct control on those properties. * Made `access_opens_date`, `access_closes_date`, `enrollment_opens_date`, `enrollment_closes_date` nullable. * @since 1.0.0-beta.8 Renamed `sales_page_page_type` and `sales_page_page_url` properties, respectively to `sales_page_type` and `sales_page_url` according to the specs. * @since 1.0.0-beta.9 Added `llms_rest_pre_insert_course` filter hook. * * @param WP_REST_Request $request Request object. * @return array|WP_Error Array of llms post args or WP_Error. */ protected function prepare_item_for_database( $request ) { $prepared_item = parent::prepare_item_for_database( $request ); $schema = $this->get_item_schema(); // Course Audio embed URL. if ( ! empty( $schema['properties']['audio_embed'] ) && isset( $request['audio_embed'] ) ) { $prepared_item['audio_embed'] = $request['audio_embed']; } // Course Video embed URL. if ( ! empty( $schema['properties']['video_embed'] ) && isset( $request['video_embed'] ) ) { $prepared_item['video_embed'] = $request['video_embed']; } // Video tile. if ( ! empty( $schema['properties']['video_tile'] ) && isset( $request['video_tile'] ) ) { $prepared_item['tile_featured_video'] = empty( $request['video_tile'] ) ? 'no' : 'yes'; } // Capacity enabled. if ( ! empty( $schema['properties']['capacity_enabled'] ) && isset( $request['capacity_enabled'] ) ) { $prepared_item['enable_capacity'] = empty( $request['capacity_enabled'] ) ? 'no' : 'yes'; } // Capacity message. if ( ! empty( $schema['properties']['capacity_message'] ) && isset( $request['capacity_message'] ) ) { if ( is_string( $request['capacity_message'] ) ) { $prepared_item['capacity_message'] = $request['capacity_message']; } elseif ( isset( $request['capacity_message']['raw'] ) ) { $prepared_item['capacity_message'] = $request['capacity_message']['raw']; } } // Capacity limit. if ( ! empty( $schema['properties']['capacity_limit'] ) && isset( $request['capacity_limit'] ) ) { $prepared_item['capacity'] = $request['capacity_limit']; } // Restricted message. if ( ! empty( $schema['properties']['restricted_message'] ) && isset( $request['restricted_message'] ) ) { if ( is_string( $request['restricted_message'] ) ) { $prepared_item['content_restricted_message'] = $request['restricted_message']; } elseif ( isset( $request['restricted_message']['raw'] ) ) { $prepared_item['content_restricted_message'] = $request['restricted_message']['raw']; } } // Length. if ( ! empty( $schema['properties']['length'] ) && isset( $request['length'] ) ) { if ( is_string( $request['length'] ) ) { $prepared_item['length'] = $request['length']; } elseif ( isset( $request['length']['raw'] ) ) { $prepared_item['length'] = $request['length']['raw']; } } // Sales page. if ( ! empty( $schema['properties']['sales_page_type'] ) && isset( $request['sales_page_type'] ) ) { $prepared_item['sales_page_content_type'] = $request['sales_page_type']; } if ( ! empty( $schema['properties']['sales_page_page_id'] ) && isset( $request['sales_page_page_id'] ) ) { $sales_page = get_post( $request['sales_page_page_id'] ); if ( $sales_page && is_a( $sales_page, 'WP_Post' ) ) { $prepared_item['sales_page_content_page_id'] = $request['sales_page_page_id']; // maybe allow only published pages? } else { $prepared_item['sales_page_content_page_id'] = 0; } } if ( ! empty( $schema['properties']['sales_page_url'] ) && isset( $request['sales_page_url'] ) ) { $prepared_item['sales_page_content_url'] = $request['sales_page_url'];
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.9 | Added llms_rest_pre_insert_course filter hook. |
1.0.0-beta.8 | Renamed sales_page_page_type and sales_page_page_url properties, respectively to sales_page_type and sales_page_url according to the specs. |
1.0.0-beta.7 | access_opens_date , access_closes_date , enrollment_opens_date , enrollment_closes_date treated in @see update_additional_object_fields() method so to better handle the update of the course's properties time_period and enrollment_period whose values are derived from them and need to be passed to $course->set_bulk() only if they differ from their current values, otherwise we'd get a WP_Error which the consumer cannot avoid having no direct control on those properties. Made access_opens_date , access_closes_date , enrollment_opens_date , enrollment_closes_date nullable. |
1.0.0-beta.1 | Introduced. |