CourseBuilder::front_save_course()
Source
File: classes/CourseBuilder.php
public function front_save_course(){ $course_id = dozent_input_text( 'frontend_course_id' ); $course_title = dozent_input_text( 'course_title' ); $short_description = dozent_input_textarea( 'short_description' ); $course_description = ! empty( $_POST[ 'course_description' ] ) ? wp_kses_post( $_POST[ 'course_description' ] ) : ''; $course_thumbnail = (int) dozent_input_textarea( 'course_thumbnail' ); $save_type = dozent_input_text( 'save_type' ); $front_course = get_post( $course_id ); $tax_input = dozent_input_array_field( 'tax_input' ); $course_data = [ 'ID' => $course_id, 'post_title' => $course_title, 'post_name' => sanitize_title( $course_title ), 'post_content' => $course_description, 'post_excerpt' => $short_description, ]; /** * Course Publish, save as draft or submit for review. */ if ( $save_type === 'save' ){ $course_data['post_status'] = 'draft'; }else{ if ( current_user_can( 'instructor_can_publish_course' ) ){ $course_data['post_status'] = 'publish'; }else{ $course_data['post_status'] = 'pending'; } } wp_update_post( $course_data ); /** * Update or remove thumbnail */ if ( $course_thumbnail ){ update_post_meta( $course_id , '_thumbnail_id', $course_thumbnail); } else { delete_post_meta( $course_id , '_thumbnail_id' ); } /** * Adding course categories */ if ( dozent_count( $tax_input ) ) { foreach ( $tax_input as $taxonomy => $tags ) { $taxonomy_obj = get_taxonomy( $taxonomy ); if ( ! $taxonomy_obj ) { /* translators: %s: taxonomy name */ _doing_it_wrong( __FUNCTION__, sprintf( __( 'Invalid taxonomy: %s.', 'dozent' ), $taxonomy ), '4.4.0' ); continue; } // array = hierarchical, string = non-hierarchical. if ( is_array( $tags ) ) { $tags = array_filter( $tags ); } wp_set_post_terms( $course_id, $tags, $taxonomy ); } } /** * Supports for others meta save */ $redirect_url = null; if ( $front_course->post_status === 'auto-draft' ){ $redirect_url = dozent_get_dashboard_permalink( 'my-courses/create-course' ); $redirect_url = add_query_arg( [ 'course_id' => $course_id ], $redirect_url ); } if ( $save_type === 'publish' ){ $redirect_url = dozent_get_dashboard_permalink( 'my-courses' ); } $response = [ 'redirect_url' => $redirect_url, ]; wp_send_json_success( $response ); }