Learnpress_Helpers::select_lesson_from_section_func()

Return all the lessons of section ID provided in ajax call


Source Source

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

	public function select_lesson_from_section_func() {


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

		$fields = array();
		if ( isset( $_POST ) ) {
			$course_id = absint( $_POST['values']['LPCOURSE'] );
			if ( $course_id > 0 ) {
				$course_curd = new LP_Section_CURD( $course_id );
				$lessons     = $course_curd->get_section_items( absint( $_POST['value'] ) );

				foreach ( $lessons as $lesson ) {
					$fields[] = [
						'value' => $lesson['id'],
						'text'  => $lesson['title'],
					];
				}
			}
		}

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