| @@ -1,101 +1,101 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Recent Courses Widget. | |
| 5 | - * | |
| 6 | - * @author ThimPress <nhamdv> | |
| 7 | - * @category Widgets | |
| 8 | - * @package Learnpress/Widgets | |
| 9 | - * @version 4.0.0 | |
| 10 | - * @extends LP_Widget | |
| 11 | - */ | |
| 12 | - | |
| 13 | -defined( 'ABSPATH' ) || exit(); | |
| 14 | - | |
| 15 | -if ( ! class_exists( 'LP_Widget_Recent_Courses' ) ) { | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * Class LP_Widget_Recent_Courses | |
| 19 | - */ | |
| 20 | - class LP_Widget_Recent_Courses extends LP_Widget { | |
| 21 | - | |
| 22 | - public function __construct() { | |
| 23 | - $this->widget_cssclass = 'learnpress widget_course_recent'; | |
| 24 | - $this->widget_description = esc_html__( 'Display the Recent courses', 'learnpress' ); | |
| 25 | - $this->widget_id = 'learnpress_widget_course_recent'; | |
| 26 | - $this->widget_name = esc_html__( 'LearnPress - Recent Courses', 'learnpress' ); | |
| 27 | - $this->settings = array( | |
| 28 | - 'title' => array( | |
| 29 | - 'label' => __( 'Title', 'learnpress' ), | |
| 30 | - 'type' => 'text', | |
| 31 | - 'std' => __( 'Recent Courses', 'learnpress' ), | |
| 32 | - ), | |
| 33 | - 'show_teacher' => array( | |
| 34 | - 'label' => __( 'Show instructor', 'learnpress' ), | |
| 35 | - 'type' => 'checkbox', | |
| 36 | - 'std' => 1, | |
| 37 | - ), | |
| 38 | - 'show_thumbnail' => array( | |
| 39 | - 'label' => __( 'Show thumbnail', 'learnpress' ), | |
| 40 | - 'type' => 'checkbox', | |
| 41 | - 'std' => 1, | |
| 42 | - ), | |
| 43 | - 'limit' => array( | |
| 44 | - 'label' => __( 'Limit', 'learnpress' ), | |
| 45 | - 'type' => 'number', | |
| 46 | - 'min' => 1, | |
| 47 | - 'std' => 4, | |
| 48 | - ), | |
| 49 | - 'desc_length' => array( | |
| 50 | - 'label' => __( 'Description length', 'learnpress' ), | |
| 51 | - 'type' => 'number', | |
| 52 | - 'min' => 0, | |
| 53 | - 'std' => 10, | |
| 54 | - ), | |
| 55 | - 'show_price' => array( | |
| 56 | - 'label' => __( 'Show price', 'learnpress' ), | |
| 57 | - 'type' => 'checkbox', | |
| 58 | - 'std' => 1, | |
| 59 | - ), | |
| 60 | - 'css_class' => array( | |
| 61 | - 'label' => __( 'CSS class', 'learnpress' ), | |
| 62 | - 'type' => 'text', | |
| 63 | - 'std' => '', | |
| 64 | - ), | |
| 65 | - 'bottom_link_text' => array( | |
| 66 | - 'label' => __( 'Go to Courses', 'learnpress' ), | |
| 67 | - 'type' => 'text', | |
| 68 | - 'std' => 'Go to Courses', | |
| 69 | - ), | |
| 70 | - ); | |
| 71 | - | |
| 72 | - parent::__construct(); | |
| 73 | - } | |
| 74 | - | |
| 75 | - /** Send content for API */ | |
| 76 | - public function lp_rest_api_content( $instance, $params ) { | |
| 77 | - $instance['show_teacher'] = $instance['show_teacher'] ?? 1; | |
| 78 | - $instance['show_thumbnail'] = $instance['show_thumbnail'] ?? 1; | |
| 79 | - $instance['limit'] = $instance['limit'] ?? 4; | |
| 80 | - $instance['desc_length'] = $instance['desc_length'] ?? 10; | |
| 81 | - $instance['show_price'] = $instance['show_price'] ?? 1; | |
| 82 | - $instance['css_class'] = $instance['css_class'] ?? ''; | |
| 83 | - $instance['bottom_link_text'] = $instance['bottom_link_text'] ?? esc_html__( 'Go to Courses', 'learnpress' ); | |
| 84 | - | |
| 85 | - $filter = new LP_Course_Filter(); | |
| 86 | - $filter->limit = $instance['limit']; | |
| 87 | - | |
| 88 | - $courses = LP_Course_DB::getInstance()->get_recent_courses( $filter ); | |
| 89 | - | |
| 90 | - $data = learn_press_get_template_content( | |
| 91 | - 'widgets/recent-courses.php', | |
| 92 | - array( | |
| 93 | - 'courses' => $courses, | |
| 94 | - 'instance' => $instance, | |
| 95 | - ) | |
| 96 | - ); | |
| 97 | - | |
| 98 | - return $data; | |
| 99 | - } | |
| 100 | - } | |
| 101 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Recent Courses Widget. | |
| 5 | + * | |
| 6 | + * @author ThimPress <nhamdv> | |
| 7 | + * @category Widgets | |
| 8 | + * @package Learnpress/Widgets | |
| 9 | + * @version 4.0.0 | |
| 10 | + * @extends LP_Widget | |
| 11 | + */ | |
| 12 | + | |
| 13 | +defined( 'ABSPATH' ) || exit(); | |
| 14 | + | |
| 15 | +if ( ! class_exists( 'LP_Widget_Recent_Courses' ) ) { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Class LP_Widget_Recent_Courses | |
| 19 | + */ | |
| 20 | + class LP_Widget_Recent_Courses extends LP_Widget { | |
| 21 | + | |
| 22 | + public function __construct() { | |
| 23 | + $this->widget_cssclass = 'learnpress widget_course_recent'; | |
| 24 | + $this->widget_description = esc_html__( 'Display the Recent courses', 'learnpress' ); | |
| 25 | + $this->widget_id = 'learnpress_widget_course_recent'; | |
| 26 | + $this->widget_name = esc_html__( 'LearnPress - Recent Courses', 'learnpress' ); | |
| 27 | + $this->settings = array( | |
| 28 | + 'title' => array( | |
| 29 | + 'label' => __( 'Title', 'learnpress' ), | |
| 30 | + 'type' => 'text', | |
| 31 | + 'std' => __( 'Recent Courses', 'learnpress' ), | |
| 32 | + ), | |
| 33 | + 'show_teacher' => array( | |
| 34 | + 'label' => __( 'Show instructor', 'learnpress' ), | |
| 35 | + 'type' => 'checkbox', | |
| 36 | + 'std' => 1, | |
| 37 | + ), | |
| 38 | + 'show_thumbnail' => array( | |
| 39 | + 'label' => __( 'Show thumbnail', 'learnpress' ), | |
| 40 | + 'type' => 'checkbox', | |
| 41 | + 'std' => 1, | |
| 42 | + ), | |
| 43 | + 'limit' => array( | |
| 44 | + 'label' => __( 'Limit', 'learnpress' ), | |
| 45 | + 'type' => 'number', | |
| 46 | + 'min' => 1, | |
| 47 | + 'std' => 4, | |
| 48 | + ), | |
| 49 | + 'desc_length' => array( | |
| 50 | + 'label' => __( 'Description length', 'learnpress' ), | |
| 51 | + 'type' => 'number', | |
| 52 | + 'min' => 0, | |
| 53 | + 'std' => 10, | |
| 54 | + ), | |
| 55 | + 'show_price' => array( | |
| 56 | + 'label' => __( 'Show price', 'learnpress' ), | |
| 57 | + 'type' => 'checkbox', | |
| 58 | + 'std' => 1, | |
| 59 | + ), | |
| 60 | + 'css_class' => array( | |
| 61 | + 'label' => __( 'CSS class', 'learnpress' ), | |
| 62 | + 'type' => 'text', | |
| 63 | + 'std' => '', | |
| 64 | + ), | |
| 65 | + 'bottom_link_text' => array( | |
| 66 | + 'label' => __( 'Go to Courses', 'learnpress' ), | |
| 67 | + 'type' => 'text', | |
| 68 | + 'std' => 'Go to Courses', | |
| 69 | + ), | |
| 70 | + ); | |
| 71 | + | |
| 72 | + parent::__construct(); | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** Send content for API */ | |
| 76 | + public function lp_rest_api_content( $instance, $params ) { | |
| 77 | + $instance['show_teacher'] = $instance['show_teacher'] ?? 1; | |
| 78 | + $instance['show_thumbnail'] = $instance['show_thumbnail'] ?? 1; | |
| 79 | + $instance['limit'] = $instance['limit'] ?? 4; | |
| 80 | + $instance['desc_length'] = $instance['desc_length'] ?? 10; | |
| 81 | + $instance['show_price'] = $instance['show_price'] ?? 1; | |
| 82 | + $instance['css_class'] = $instance['css_class'] ?? ''; | |
| 83 | + $instance['bottom_link_text'] = $instance['bottom_link_text'] ?? esc_html__( 'Go to Courses', 'learnpress' ); | |
| 84 | + | |
| 85 | + $filter = new LP_Course_Filter(); | |
| 86 | + $filter->limit = $instance['limit']; | |
| 87 | + | |
| 88 | + $courses = LP_Course_DB::getInstance()->get_recent_courses( $filter ); | |
| 89 | + | |
| 90 | + $data = learn_press_get_template_content( | |
| 91 | + 'widgets/recent-courses.php', | |
| 92 | + array( | |
| 93 | + 'courses' => $courses, | |
| 94 | + 'instance' => $instance, | |
| 95 | + ) | |
| 96 | + ); | |
| 97 | + | |
| 98 | + return $data; | |
| 99 | + } | |
| 100 | + } | |
| 101 | +} | |