PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.10
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.10
4.4.10 4.4.9.1 4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 All 142 releases
← All changes | inc/Ajax/CourseBuilder/CourseBuilderAjax.php +32 -14 4.4.9 → 4.4.10 View file →
@@ -1110,8 +1110,10 @@
1110 1110
1111 1111 try {
1112 1112 $data = self::check_valid_lesson();
1113 1113 $lesson_id = $data['lesson_id'] ?? 0;
1114 + $has_title = array_key_exists( 'lesson_title', $data );
1115 + $has_content = array_key_exists( 'lesson_description', $data );
1114 1116 $title = LP_Helper::sanitize_params_submitted( $data['lesson_title'] ?? '' );
1115 1117 $description = LP_Helper::sanitize_params_submitted(
1116 1118 $data['lesson_description'] ?? '',
1117 1119 'html'
@@ -1132,9 +1134,9 @@
1132 1134 'key'
1133 1135 );
1134 1136 $restore_with_custom_slug = false;
1135 1137
1136 - if ( empty( $title ) ) {
1138 + if ( ( $insert || $has_title ) && empty( $title ) ) {
1137 1139 throw new Exception( __( 'Lesson title is required', 'learnpress' ) );
1138 1140 }
1139 1141
1140 1142 if ( $insert ) {
@@ -1178,23 +1180,39 @@
1178 1180 'post_type' => LP_LESSON_CPT,
1179 1181 'post_status' => $target_status,
1180 1182 );*/
1181 1183
1182 - if ( defined( 'ELEMENTOR_VERSION' ) ) {
1184 + if ( defined( 'ELEMENTOR_VERSION' ) && array_key_exists( 'is_elementor', $data ) ) {
1183 1185 \Elementor\Plugin::$instance->documents->get( $lesson_id )->set_is_built_with_elementor( ! empty( $is_elementor ) );
1184 1186 }
1185 1187
1186 - $lesson_model->post_title = $title;
1187 - $lesson_model->post_content = $description;
1188 - $lesson_model->post_status = $target_status;
1188 + $must_save_lesson = false;
1189 + if ( $has_title ) {
1190 + $lesson_model->post_title = $title;
1191 + $must_save_lesson = true;
1192 + }
1193 +
1194 + if ( $has_content ) {
1195 + $lesson_model->post_content = $description;
1196 + $must_save_lesson = true;
1197 + }
1198 +
1199 + if ( ! empty( $target_status ) ) {
1200 + $lesson_model->post_status = $target_status;
1201 + $must_save_lesson = true;
1202 + }
1203 +
1189 1204 if ( ! empty( $lesson_slug ) ) {
1190 1205 $lesson_model->post_name = $lesson_slug;
1206 + $must_save_lesson = true;
1191 1207 }
1192 1208
1193 1209 //$restore_with_custom_slug = $this->prepare_desired_slug_for_restore( $lesson_id, $target_status, $lesson_slug );
1194 1210
1195 1211 //$update = wp_update_post( $update_arg );
1196 - $lesson_model->save();
1212 + if ( $must_save_lesson ) {
1213 + $lesson_model->save();
1214 + }
1197 1215
1198 1216 /*if ( $restore_with_custom_slug ) {
1199 1217 $this->sync_slug_after_restore( $lesson_id, $lesson_slug );
1200 1218 }*/
@@ -1214,9 +1232,9 @@
1214 1232 $this->save_lesson_settings_to_model( $lesson_model, $data );
1215 1233 }
1216 1234
1217 1235 // Remove lesson from curriculum if status is not public
1218 - if ( $target_status !== 'publish' ) {
1236 + if ( ! empty( $target_status ) && $target_status !== 'publish' ) {
1219 1237 $this->remove_course_item_from_curriculum( $lesson_id, $course_id );
1220 1238 }
1221 1239
1222 1240 $response->status = 'success';
@@ -1241,9 +1259,9 @@
1241 1259 $response->data->lesson_permalink = urldecode( $course->get_item_link( $lesson_id ) );
1242 1260 }
1243 1261 }
1244 1262
1245 - $lesson_model_for_html = LessonPostModel::find( $lesson_id, true );
1263 + $lesson_model_for_html = LessonPostModel::find( $lesson_id, false );
1246 1264 if ( $return_html ) {
1247 1265 $response->data->list_item_html = $lesson_model_for_html
1248 1266 ? BuilderListLessonsTemplate::render_lesson( $lesson_model_for_html )
1249 1267 : '';
@@ -1276,9 +1294,9 @@
1276 1294 try {
1277 1295 $data = self::check_valid_lesson();
1278 1296 $lesson_id = $data['lesson_id'] ?? 0;
1279 1297 $status = $data['status'] ?? 'trash';
1280 - $lesson_model = $data['lesson_model'] ?? [];
1298 + $lesson_model = LessonPostModel::find( $lesson_id, false );
1281 1299 $lesson_slug = ! empty( $data['lesson_permalink'] )
1282 1300 ? sanitize_title( wp_unslash( (string) $data['lesson_permalink'] ) )
1283 1301 : '';
1284 1302
@@ -1380,9 +1398,9 @@
1380 1398 }
1381 1399 }
1382 1400
1383 1401 if ( 'delete' !== $status ) {
1384 - $lesson_model_new = LessonPostModel::find( $lesson_id, true );
1402 + $lesson_model_new = LessonPostModel::find( $lesson_id, false );
1385 1403 $response->data->html = $lesson_model_new ? BuilderListLessonsTemplate::render_lesson( $lesson_model_new ) : '';
1386 1404 }
1387 1405
1388 1406 $response->status = 'success';
@@ -1693,9 +1711,9 @@
1693 1711 try {
1694 1712 $data = self::check_valid_quiz();
1695 1713 $quiz_id = $data['quiz_id'] ?? 0;
1696 1714 $status = $data['status'] ?? 'trash';
1697 - $quiz_model = $data['quiz_model'] ?? [];
1715 + $quiz_model = QuizPostModel::find( $quiz_id, false );
1698 1716 $quiz_slug = ! empty( $data['quiz_permalink'] )
1699 1717 ? sanitize_title( wp_unslash( (string) $data['quiz_permalink'] ) )
1700 1718 : '';
1701 1719
@@ -1797,9 +1815,9 @@
1797 1815 }
1798 1816 }
1799 1817
1800 1818 if ( 'delete' !== $status ) {
1801 - $fresh_quiz_model = QuizPostModel::find( $quiz_id, true );
1819 + $fresh_quiz_model = QuizPostModel::find( $quiz_id, false );
1802 1820 $response->data->html = $fresh_quiz_model
1803 1821 ? BuilderListQuizzesTemplate::render_quiz( $fresh_quiz_model )
1804 1822 : '';
1805 1823 }
@@ -1964,9 +1982,9 @@
1964 1982 try {
1965 1983 $data = self::check_valid_question();
1966 1984 $question_id = $data['question_id'] ?? 0;
1967 1985 $status = $data['status'] ?? 'trash';
1968 - $question_model = $data['question_model'] ?? [];
1986 + $question_model = QuestionPostModel::find( $question_id, false );
1969 1987
1970 1988 if ( ! $question_model ) {
1971 1989 throw new Exception( __( 'Question not found', 'learnpress' ) );
1972 1990 }
@@ -2030,9 +2048,9 @@
2030 2048 $response->data->status = $status;
2031 2049 $response->data->button_title = __( 'Publish', 'learnpress' );
2032 2050
2033 2051 if ( 'delete' !== $status ) {
2034 - $fresh_question_model = QuestionPostModel::find( $question_id, true );
2052 + $fresh_question_model = QuestionPostModel::find( $question_id, false );
2035 2053 $response->data->html = $fresh_question_model
2036 2054 ? BuilderListQuestionsTemplate::render_question( $fresh_question_model )
2037 2055 : '';
2038 2056 }