LLMS_REST_Sections_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-sections-controller.php
* * @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(); // LLMS Section parent id. if ( ! empty( $schema['properties']['parent_id'] ) && isset( $request['parent_id'] ) ) { $parent_course = llms_get_post( $request['parent_id'] ); if ( ! $parent_course || ! is_a( $parent_course, 'LLMS_Course' ) ) { return llms_rest_bad_request_error( __( 'Invalid parent_id param. It must be a valid Course ID.', 'lifterlms' ) ); } $prepared_item['parent_course'] = $request['parent_id']; } // LLMS Section order. if ( ! empty( $schema['properties']['order'] ) && isset( $request['order'] ) ) { // order must be > 0. It's sanitized as absint so it cannot come as negative value. if ( 0 === $request['order'] ) { return llms_rest_bad_request_error( __( 'Invalid order param. It must be greater than 0.', 'lifterlms' ) ); } $prepared_item['order'] = $request['order']; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.1 | Introduced. |