CourseBuilder::save_new_section()


Source

File: classes/CourseBuilder.php

	public function save_new_section() {
		$course_id        = (int) dozent_input_text( 'course_id' );
		$section_name     = dozent_input_text( 'section_name' );
		$section_summery  = dozent_input_textarea( 'section_summery' );
		$section_order_id = dozent_get_next_curriculum_item_order_id( $course_id );

		if ( ! $section_name ) {
			wp_send_json_error();
		}

		$post_arr   = apply_filters( 'dozent_new_section_attr', [
			'post_type'    => 'dozent_section',
			'post_title'   => $section_name,
			'post_content' => $section_summery,
			'post_status'  => 'publish',
			'post_author'  => get_current_user_id(),
			'post_parent'  => $course_id,
			'menu_order'   => $section_order_id,
		] );
		$section_id = wp_insert_post( $post_arr );

		ob_start();
		include DOZENT_ABSPATH . 'views/course_builder/curriculum.php';
		$course_contents = ob_get_clean();

		wp_send_json_success( [ 'curriculum' => $course_contents ] );
	}