Learndash_Helpers::select_lesson_from_course_func()

Return all the specific fields of a form ID provided in ajax call


Parameters Parameters

$include_any

(string) (Required)


Source Source

File: src/integrations/learndash/helpers/learndash-helpers.php

	public function select_lesson_from_course_func() {



		// Nonce and post object validation
		Automator()->utilities->ajax_auth_check( $_POST );

		$fields = array();
		if ( ! isset( $_POST ) ) {
			echo wp_json_encode( $fields );
			die();
		}

		$ld_post_value = sanitize_text_field( $_POST['value'] );

		if ( 'automator_custom_value' === (string) $ld_post_value && '-1' !== absint( $ld_post_value ) ) {
			$ld_course_id = isset( $_POST['values']['LDCOURSE_custom'] ) ? absint( $_POST['values']['LDCOURSE_custom'] ) : 0;
		} else {
			$ld_course_id = absint( $_POST['values']['LDCOURSE'] );
		}

		if ( absint( '-1' ) === absint( $ld_course_id ) || true === (bool) $this->load_any_options ) {
			$fields[] = array(
				'value' => '-1',
				'text'  => 'Any lesson',
			);
		}

		if ( absint( '-1' ) !== absint( $ld_course_id ) ) {
			$lessons = learndash_get_lesson_list( $ld_course_id, array( 'num' => 0 ) );

			foreach ( $lessons as $lesson ) {
				$fields[] = array(
					'value' => $lesson->ID,
					'text'  => $lesson->post_title,
				);
			}

		}

		echo wp_json_encode( $fields );
		die();
	}