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_Generator::create_course( array $raw )

Create a new course


Parameters Parameters

$raw

(array) (Required) Raw course data.


Top ↑

Return Return

(void|int)


Top ↑

Source Source

File: includes/class.llms.generator.php

	 */
	protected function parse_raw( $raw ) {

		if ( is_string( $raw ) ) {
			$raw = json_decode( $raw, true );
		}

		return (array) $raw;

	}

	/**
	 * Records a generated post id
	 *
	 * @since 3.14.8
	 * @since 4.7.0 Modified method access from `private` to `protected`.
	 *               Add IDs to the `generated` variable in favor of `posts`.
	 *
	 * @param int    $id  WP Post ID of the generated post.
	 * @param string $key Key of the stat to increment.
	 * @return void
	 */
	protected function record_generation( $id, $key ) {

		// Remove LifterLMS Prefix from the key (if it exists).
		$key = str_replace( 'llms_', '', $key );

		// Add an array if it doesn't already exist.
		if ( ! isset( $this->generated[ $key ] ) ) {
			$this->generated[ $key ] = array();
		}

		// Record the ID.
		$this->generated[ $key ][] = $id;

	}

	/**
	 * Configure the default post status for generated posts at runtime
	 *
	 * @since 3.7.3
	 * @since 4.7.0 Call `set_default_post_status()` from the configured generator.
	 *
	 * @param string $status Any valid WP Post Status.
	 * @return void
	 */
	public function set_default_post_status( $status ) {
		call_user_func( array( $this->generator[0], 'set_default_post_status' ), $status );
	}

	/**
	 * Sets the generator to use for the current instance
	 *
	 * @since 3.3.0
	 * @since 3.36.3 Fix error causing `null` to be returned instead of expected `WP_Error`.
	 *               Return the generator name on success instead of void.
	 *
	 * @param string $generator Generator string, eg: "LifterLMS/SingleCourseExporter"
	 * @return string|WP_Error Name of the generator on success, otherwise an error object.
	 */
	public function set_generator( $generator = null ) {

		// Interpret the generator from the raw data.
		if ( empty( $generator ) ) {

			// No generator can be interpreted.
			if ( ! isset( $this->raw['_generator'] ) ) {

				$this->error->add( 'missing-generator', __( 'The supplied file cannot be processed by the importer.', 'lifterlms' ) );
				return $this->error;

			}

			// Set the generator using the interpreted data.
			return $this->set_generator( $this->raw['_generator'] );

		}

		// Invalid generator.

Top ↑

Changelog Changelog

Changelog
Version Description
4.3.3 Use an empty string in favor of null for empty post_content and post_excerpt fields.
3.30.2 Added hooks.
3.3.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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