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_section( array $section_data, obj $course_id )

Update a section with data from the heartbeat


Description Description


Parameters Parameters

$section_data

(array) (Required) array of section data

$course_id

(obj) (Required) instance of the parent LLMS_Course


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/admin/class.llms.admin.builder.php

	private static function update_section( $section_data, $course_id ) {

		$res = array_merge( $section_data, array(
			'orig_id' => $section_data['id'],
		) );

		// create a new section
		if ( self::is_temp_id( $section_data['id'] ) ) {

			$section = new LLMS_Section( 'new' );
			$section->set( 'parent_course', $course_id );

			// update existing section
		} else {

			$section = llms_get_post( $section_data['id'] );

		}

		// we don't have a proper section to work with...
		if ( empty( $section ) || ! is_a( $section, 'LLMS_Section' ) ) {
			$res['error'] = sprintf( esc_html__( 'Unable to update section "%s". Invalid section ID.', 'lifterlms' ), $section_data['id'] );
		} else {

			// return the real ID (important when creating a new section)
			$res['id'] = $section->get( 'id' );

			// run through all possible updated fields
			foreach ( array( 'order', 'title' ) as $key ) {

				// update those that were sent through
				if ( isset( $section_data[ $key ] ) ) {

					$section->set( $key, $section_data[ $key ] );

				}
			}

			if ( isset( $section_data['lessons'] ) && is_array( $section_data['lessons'] ) ) {

				$res['lessons'] = self::update_lessons( $section_data['lessons'], $section );

			}
		}

		return $res;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.16.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: