| @@ -1,72 +1,72 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -/** | |
| 4 | - * Course Info Widget. | |
| 5 | - * | |
| 6 | - * @author ThimPress | |
| 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_Course_Info' ) ) { | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * Class LP_Widget_Course_Info | |
| 19 | - */ | |
| 20 | - class LP_Widget_Course_Info extends LP_Widget { | |
| 21 | - | |
| 22 | - /** | |
| 23 | - * LP_Widget_Course_Info constructor. | |
| 24 | - */ | |
| 25 | - public function __construct() { | |
| 26 | - $this->widget_cssclass = 'learnpress widget_course_info'; | |
| 27 | - $this->widget_description = esc_html__( 'Display the Course Infomation', 'learnpress' ); | |
| 28 | - $this->widget_id = 'learnpress_widget_course_info'; | |
| 29 | - $this->widget_name = esc_html__( 'LearnPress - Course Info', 'learnpress' ); | |
| 30 | - $this->settings = array( | |
| 31 | - 'title' => array( | |
| 32 | - 'label' => esc_html__( 'Title', 'learnpress' ), | |
| 33 | - 'type' => 'text', | |
| 34 | - 'std' => esc_html__( 'Course Info', 'learnpress' ), | |
| 35 | - ), | |
| 36 | - 'course_id' => array( | |
| 37 | - 'label' => esc_html__( 'Select Course', 'learnpress' ), | |
| 38 | - 'type' => 'autocomplete', | |
| 39 | - 'post_type' => LP_COURSE_CPT, | |
| 40 | - 'std' => '', | |
| 41 | - ), | |
| 42 | - 'css_class' => array( | |
| 43 | - 'label' => esc_html__( 'CSS Class', 'learnpress' ), | |
| 44 | - 'type' => 'text', | |
| 45 | - 'std' => '', | |
| 46 | - ), | |
| 47 | - ); | |
| 48 | - | |
| 49 | - parent::__construct(); | |
| 50 | - } | |
| 51 | - | |
| 52 | - public function lp_rest_api_content( $instance, $params ) { | |
| 53 | - $instance['css_class'] = $instance['css_class'] ?? ''; | |
| 54 | - | |
| 55 | - if ( ! empty( $instance['course_id'] ) ) { | |
| 56 | - $course = learn_press_get_course( $instance['course_id'] ); | |
| 57 | - | |
| 58 | - if ( $course ) { | |
| 59 | - return learn_press_get_template_content( | |
| 60 | - 'widgets/course-info.php', | |
| 61 | - array( | |
| 62 | - 'course' => $course, | |
| 63 | - 'instance' => $instance, | |
| 64 | - ) | |
| 65 | - ); | |
| 66 | - } | |
| 67 | - } | |
| 68 | - | |
| 69 | - return new WP_Error( 'no_params', esc_html__( 'Error: Please select a Course.', 'learnpress' ) ); | |
| 70 | - } | |
| 71 | - } | |
| 72 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Course Info Widget. | |
| 5 | + * | |
| 6 | + * @author ThimPress | |
| 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_Course_Info' ) ) { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Class LP_Widget_Course_Info | |
| 19 | + */ | |
| 20 | + class LP_Widget_Course_Info extends LP_Widget { | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * LP_Widget_Course_Info constructor. | |
| 24 | + */ | |
| 25 | + public function __construct() { | |
| 26 | + $this->widget_cssclass = 'learnpress widget_course_info'; | |
| 27 | + $this->widget_description = esc_html__( 'Display the Course Infomation', 'learnpress' ); | |
| 28 | + $this->widget_id = 'learnpress_widget_course_info'; | |
| 29 | + $this->widget_name = esc_html__( 'LearnPress - Course Info', 'learnpress' ); | |
| 30 | + $this->settings = array( | |
| 31 | + 'title' => array( | |
| 32 | + 'label' => esc_html__( 'Title', 'learnpress' ), | |
| 33 | + 'type' => 'text', | |
| 34 | + 'std' => esc_html__( 'Course Info', 'learnpress' ), | |
| 35 | + ), | |
| 36 | + 'course_id' => array( | |
| 37 | + 'label' => esc_html__( 'Select Course', 'learnpress' ), | |
| 38 | + 'type' => 'autocomplete', | |
| 39 | + 'post_type' => LP_COURSE_CPT, | |
| 40 | + 'std' => '', | |
| 41 | + ), | |
| 42 | + 'css_class' => array( | |
| 43 | + 'label' => esc_html__( 'CSS Class', 'learnpress' ), | |
| 44 | + 'type' => 'text', | |
| 45 | + 'std' => '', | |
| 46 | + ), | |
| 47 | + ); | |
| 48 | + | |
| 49 | + parent::__construct(); | |
| 50 | + } | |
| 51 | + | |
| 52 | + public function lp_rest_api_content( $instance, $params ) { | |
| 53 | + $instance['css_class'] = $instance['css_class'] ?? ''; | |
| 54 | + | |
| 55 | + if ( ! empty( $instance['course_id'] ) ) { | |
| 56 | + $course = learn_press_get_course( $instance['course_id'] ); | |
| 57 | + | |
| 58 | + if ( $course ) { | |
| 59 | + return learn_press_get_template_content( | |
| 60 | + 'widgets/course-info.php', | |
| 61 | + array( | |
| 62 | + 'course' => $course, | |
| 63 | + 'instance' => $instance, | |
| 64 | + ) | |
| 65 | + ); | |
| 66 | + } | |
| 67 | + } | |
| 68 | + | |
| 69 | + return new WP_Error( 'no_params', esc_html__( 'Error: Please select a Course.', 'learnpress' ) ); | |
| 70 | + } | |
| 71 | + } | |
| 72 | +} | |