| 1 |
<?php |
| 2 |
|
| 3 |
use LearnPress\Helpers\Config; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class LP_Settings_Courses |
| 7 |
* |
| 8 |
* @author ThimPress <email@email.com> |
| 9 |
*/ |
| 10 |
class LP_Settings_Courses extends LP_Abstract_Settings_Page { |
| 11 |
/** |
| 12 |
* LP_Settings_Courses constructor. |
| 13 |
*/ |
| 14 |
public function __construct() { |
| 15 |
$this->id = 'courses'; |
| 16 |
$this->text = esc_html__( 'Courses', 'learnpress' ); |
| 17 |
|
| 18 |
parent::__construct(); |
| 19 |
} |
| 20 |
|
| 21 |
public function save() { |
| 22 |
// Check role publish course of user teacher |
| 23 |
if ( ! empty( $_POST ) && isset( $_GET['tab'] ) && $_GET['tab'] === 'courses' ) { |
| 24 |
$teacher = get_role( LP_TEACHER_ROLE ); |
| 25 |
if ( $teacher ) { |
| 26 |
$course_cap = LP_COURSE_CPT . 's'; |
| 27 |
$review_course_instructor = $_POST['learn_press_required_review'] ?? false; |
| 28 |
if ( $review_course_instructor ) { |
| 29 |
$teacher->remove_cap( 'publish_' . $course_cap ); |
| 30 |
} else { |
| 31 |
$teacher->add_cap( 'publish_' . $course_cap ); |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
// End check role publish course of user teacher |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Get config settings courses. |
| 40 |
* |
| 41 |
* @param string $section |
| 42 |
* @param string $tab |
| 43 |
* |
| 44 |
* @return array |
| 45 |
*/ |
| 46 |
public function get_settings( $section = null, $tab = null ): array { |
| 47 |
return Config::instance()->get( 'course', 'settings' ); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Get option enable load courses with ajax. |
| 52 |
* |
| 53 |
* @return bool |
| 54 |
*/ |
| 55 |
public static function is_ajax_load_courses(): bool { |
| 56 |
return LP_Settings::get_option( 'courses_load_ajax', 'yes' ) === 'yes'; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Get option enable courses archive ajax. |
| 61 |
* |
| 62 |
* @return bool |
| 63 |
*/ |
| 64 |
public static function is_no_load_ajax_first_courses(): bool { |
| 65 |
return LP_Settings::get_option( 'courses_first_no_ajax', 'no' ) === 'yes'; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Get option type Pagination. |
| 70 |
* |
| 71 |
* @return string |
| 72 |
*/ |
| 73 |
public static function get_type_pagination(): string { |
| 74 |
return LP_Settings::get_option( 'course_pagination_type', 'number' ); |
| 75 |
} |
| 76 |
} |
| 77 |
|