| @@ -1396,10 +1396,13 @@ | ||
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | 1398 | /** |
| 1399 | 1399 | * Save Lesson Settings |
| 1400 | + * @throws Exception | |
| 1400 | 1401 | */ |
| 1401 | 1402 | protected function save_lesson_settings_to_model( LessonPostModel $lessonModel, array $data ) { |
| 1403 | + $must_save = 0; | |
| 1404 | + | |
| 1402 | 1405 | if ( isset( $data['_lp_duration'] ) ) { |
| 1403 | 1406 | $duration = ! empty( $data['_lp_duration'] ) ? str_replace( ',', ' ', $data['_lp_duration'] ) : '0 minute'; |
| 1404 | 1407 | $explode = explode( ' ', $duration ); |
| 1405 | 1408 | $number = (float) $explode[0] < 0 ? 0 : absint( $explode[0] ); |
| @@ -1404,14 +1407,20 @@ | ||
| 1404 | 1407 | $explode = explode( ' ', $duration ); |
| 1405 | 1408 | $number = (float) $explode[0] < 0 ? 0 : absint( $explode[0] ); |
| 1406 | 1409 | $unit = $explode[1] ?? 'minute'; |
| 1407 | 1410 | |
| 1408 | - $lessonModel->save_meta_value_by_key( '_lp_duration', $number . ' ' . $unit ); | |
| 1411 | + $lessonModel->set_meta_value_by_key( $lessonModel::META_KEY_DURATION, $number . ' ' . $unit ); | |
| 1412 | + $must_save = 1; | |
| 1409 | 1413 | } |
| 1410 | 1414 | |
| 1411 | 1415 | if ( isset( $data['_lp_preview'] ) ) { |
| 1412 | 1416 | $enable = $data['_lp_preview'] === 'yes'; |
| 1413 | 1417 | $lessonModel->set_preview( $enable ); |
| 1418 | + $must_save = 1; | |
| 1419 | + } | |
| 1420 | + | |
| 1421 | + if ( $must_save ) { | |
| 1422 | + $lessonModel->save(); | |
| 1414 | 1423 | } |
| 1415 | 1424 | |
| 1416 | 1425 | /** |
| 1417 | 1426 | * Allow addons to persist their own lesson settings fields added to the |