| @@ -485,9 +485,9 @@ | ||
| 485 | 485 | * |
| 486 | 486 | * JS file edit-section-item.js: function updatePreviewItem call this method. |
| 487 | 487 | * |
| 488 | 488 | * @since 4.2.8.6 |
| 489 | - * @version 1.0.2 | |
| 489 | + * @version 1.0.3 | |
| 490 | 490 | */ |
| 491 | 491 | public static function update_item_preview() { |
| 492 | 492 | $response = new LP_REST_Response(); |
| 493 | 493 | |
| @@ -492,12 +492,12 @@ | ||
| 492 | 492 | $response = new LP_REST_Response(); |
| 493 | 493 | |
| 494 | 494 | try { |
| 495 | 495 | $data = self::check_valid(); |
| 496 | - $course_id = $data['course_id'] ?? 0; | |
| 497 | - $item_id = $data['item_id'] ?? 0; | |
| 498 | - $item_type = $data['item_type'] ?? ''; | |
| 499 | - $enable_preview = $data['enable_preview'] ?? 0; | |
| 496 | + $course_id = absint( $data['course_id'] ?? 0 ); | |
| 497 | + $item_id = absint( $data['item_id'] ?? 0 ); | |
| 498 | + $item_type = LP_Helper::sanitize_params_submitted( $data['item_type'] ?? '' ); | |
| 499 | + $enable_preview = absint( $data['enable_preview'] ?? 0 ); | |
| 500 | 500 | |
| 501 | 501 | $courseModel = CourseModel::find( $course_id, true ); |
| 502 | 502 | if ( ! $courseModel ) { |
| 503 | 503 | throw new Exception( __( 'Course not found', 'learnpress' ) ); |
| @@ -515,8 +515,9 @@ | ||
| 515 | 515 | throw new Exception( __( 'Item not found', 'learnpress' ) ); |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | $itemModel->set_preview( $enable_preview == 1 ); |
| 519 | + $itemModel->save(); | |
| 519 | 520 | |
| 520 | 521 | // Save course to update preview data of item in the curriculum. |
| 521 | 522 | $coursePostModel = new CoursePostModel( $courseModel ); |
| 522 | 523 | $coursePostModel->save(); |