LLMS_REST_Lessons_Controller::update_additional_object_fields( LLMS_Lesson $lesson, WP_REST_Request $request, array $schema, array $prepared_item, bool $creating = true )
Updates a single llms lesson.
Parameters Parameters
- $lesson
-
(LLMS_Lesson) (Required) LLMS_Lesson instance.
- $request
-
(WP_REST_Request) (Required) Full details about the request.
- $schema
-
(array) (Required) The item schema.
- $prepared_item
-
(array) (Required) Array.
- $creating
-
(bool) (Optional) Whether we're in creation or update phase. Default true (create).
Default value: true
Return Return
(bool|WP_Error) True on success or false if nothing to update, WP_Error object if something went wrong during the update.
Source Source
File: libraries/lifterlms-rest/includes/server/class-llms-rest-lessons-controller.php
260 261 262 263 264 265 266 267 268 269 270 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 | /** * Updates a single llms lesson. * * @since 1.0.0-beta.7 * @since 1.0.0-beta.8 Call `set_bulk()` llms post method passing `true` as second parameter, * so to instruct it to return a WP_Error on failure. * @since 1.0.0-beta.25 Allow updating meta with the same value as the stored one. * * @param LLMS_Lesson $lesson LLMS_Lesson instance. * @param WP_REST_Request $request Full details about the request. * @param array $schema The item schema. * @param array $prepared_item Prepared item array. * @param bool $creating Optional. Whether we're in creation or update phase. Default true (create). * @return bool|WP_Error True on success or false if nothing to update, WP_Error object if something went wrong during the update. */ protected function update_additional_object_fields( $lesson , $request , $schema , $prepared_item , $creating = true ) { $error = new WP_Error(); $to_set = array (); // Prerequisite. if ( ! empty ( $schema [ 'properties' ][ 'prerequisite' ] ) && isset( $request [ 'prerequisite' ] ) ) { // check if lesson exists. $prerequisite = llms_get_post( $request [ 'prerequisite' ] ); if ( is_a ( $prerequisite , 'LLMS_Lesson' ) ) { $to_set [ 'prerequisite' ] = $request [ 'prerequisite' ]; } else { $to_set [ 'prerequisite' ] = 0; } } // Needed until the following will be implemented: https://github.com/gocodebox/lifterlms/issues/908. $to_set [ 'has_prerequisite' ] = empty ( $to_set [ 'prerequisite' ] ) ? 'no' : 'yes' ; |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.8 | Call set_bulk() llms post method passing true as second parameter, so to instruct it to return a WP_Error on failure. |
1.0.0-beta.7 | |
1.0.0-beta.25 | Introduced. |