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, LLMS_Course $course_id )

Update a section with data from the heartbeat


Parameters Parameters

$section_data

(array) (Required) Array of section data.

$course_id

(LLMS_Course) (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' ) ) {
			// Translators: %s = Section post id.
			$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.11 Unknown.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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