CourseBuilder::dozent_save_lecture()
Add Lecture Action
Source
File: classes/CourseBuilder.php
public function dozent_save_lecture() { $course_id = (int) dozent_input_text( 'course_id' ); $item_id = (int) dozent_input_text( 'item_id' ); $title = dozent_input_text( 'title' ); $lecture_content = dozent_input_array_field( 'lecture_content' ); $section_id = dozent_input_array_field( 'section_id' ); $preview = dozent_input_text( 'lecture_preview' ); $post_arr = [ 'post_type' => 'dozent_lecture', 'post_title' => $title, 'post_content' => $lecture_content, 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_parent' => $section_id, ]; if ( $item_id ) { $item = get_post( $item_id ); $post_arr['ID'] = $item_id; $post_arr['menu_order'] = $item->menu_order; } else { $menu_order_id = dozent_get_next_curriculum_item_order_id( $course_id ); $post_arr['menu_order'] = $menu_order_id; } $lecture_id = wp_insert_post( $post_arr ); if ( $lecture_id ) { update_post_meta( $lecture_id, '_dozent_course_id', $course_id ); //Save Video Info $video = dozent_input_array_field( 'video' ); update_post_meta( $lecture_id, '_video', $video ); /** * Adding Attachments if users select anyone. */ $attachments = dozent_input_array_field( 'attachments' ); if ( dozent_count( $attachments ) ) { update_post_meta( $lecture_id, '_attachments', $attachments ); } else { delete_post_meta( $lecture_id, '_attachments' ); } if ( $preview ) { update_post_meta( $lecture_id, '_lecture_preview', $preview ); } else { delete_post_meta( $lecture_id, '_lecture_preview' ); } //Register Action Hooks do_action( 'dozent/lecture/saved', $lecture_id, $course_id, $post_arr ); if ( $lecture_id ) { do_action( 'dozent/lecture/updated', $lecture_id, $course_id, $post_arr ); } else { do_action( 'dozent/lecture/created', $lecture_id, $course_id, $post_arr ); } } ob_start(); include DOZENT_ABSPATH . 'views/course_builder/curriculum.php'; $course_contents = ob_get_clean(); wp_send_json_success( [ 'lecture_id' => $lecture_id, 'curriculum' => $course_contents ] ); }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |