Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
LLMS_Admin_Builder::update_lessons( array $lessons, LLMS_Section $section )
Update lesson from heartbeat data
Parameters Parameters
- $lessons
-
(array) (Required) Lesson data from heartbeat.
- $section
-
(LLMS_Section) (Required) instance of the parent LLMS_Section.
Return Return
(array)
Source Source
File: includes/admin/class.llms.admin.builder.php
update_post_meta( $post_data['id'], $attr, $val ); } } } } } } /** * Update lesson from heartbeat data. * * @since 3.16.0 * @since 5.1.3 Made sure a lesson moved in a just created section is correctly assigned to it. * @since 7.3.0 Skip revision creation when creating a brand new lesson. * * @param array $lessons Lesson data from heartbeat. * @param LLMS_Section $section instance of the parent LLMS_Section. * @return array */ private static function update_lessons( $lessons, $section ) { $ret = array(); foreach ( $lessons as $lesson_data ) { if ( ! isset( $lesson_data['id'] ) ) { continue; } $res = array_merge( $lesson_data, array( 'orig_id' => $lesson_data['id'], ) ); // Create a new lesson. if ( self::is_temp_id( $lesson_data['id'] ) ) { $lesson = new LLMS_Lesson( 'new', array( 'post_title' => isset( $lesson_data['title'] ) ? $lesson_data['title'] : __( 'New Lesson', 'lifterlms' ), ) ); $created = true; } else { $lesson = llms_get_post( $lesson_data['id'] ); $created = false; } if ( empty( $lesson ) || ! is_a( $lesson, 'LLMS_Lesson' ) ) { // Translators: %s = Lesson post id. $res['error'] = sprintf( esc_html__( 'Unable to update lesson "%s". Invalid lesson ID.', 'lifterlms' ), $lesson_data['id'] ); } else { // Don't create useless revision on "creating". add_filter( 'wp_revisions_to_keep', '__return_zero', 999 ); /** * If the parent section was just created the lesson will have a temp id * replace it with the newly created section's real ID. */ if ( ! isset( $lesson_data['parent_section'] ) || self::is_temp_id( $lesson_data['parent_section'] ) ) { $lesson_data['parent_section'] = $section->get( 'id' ); } // Return the real ID (important when creating a new lesson). $res['id'] = $lesson->get( 'id' ); $properties = array_merge( array_keys( $lesson->get_properties() ), array( 'content', 'title', ) ); $skip_props = apply_filters( 'llms_builder_update_lesson_skip_props', array( 'quiz' ) ); // Update all updatable properties. foreach ( $properties as $prop ) { if ( isset( $lesson_data[ $prop ] ) && ! in_array( $prop, $skip_props, true ) ) { $lesson->set( $prop, $lesson_data[ $prop ] ); } } // Update all custom fields. self::update_custom_schemas( 'lesson', $lesson, $lesson_data ); // During clone's we want to ensure custom field data comes with the lesson. if ( $created && isset( $lesson_data['custom'] ) ) { foreach ( $lesson_data['custom'] as $custom_key => $custom_vals ) { foreach ( $custom_vals as $val ) { add_post_meta( $lesson->get( 'id' ), $custom_key, maybe_unserialize( $val ) );
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
5.1.3 | Made sure a lesson moved in a just created section is correctly assigned to it. |
3.16.0 | Introduced. |