| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Course Progress 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_Extra' ) ) { |
| 16 |
class LP_Widget_Course_Extra extends LP_Widget { |
| 17 |
|
| 18 |
public function __construct() { |
| 19 |
$this->widget_cssclass = 'learnpress widget_course_extra'; |
| 20 |
$this->widget_description = esc_html__( 'Display the Extra information in Course settings', 'learnpress' ); |
| 21 |
$this->widget_id = 'learnpress_widget_course_extra'; |
| 22 |
$this->widget_name = esc_html__( 'LearnPress - Course Extra', 'learnpress' ); |
| 23 |
$this->settings = array( |
| 24 |
'title' => array( |
| 25 |
'label' => esc_html__( 'Title', 'learnpress' ), |
| 26 |
'type' => 'text', |
| 27 |
'std' => esc_html__( 'Course Extra', 'learnpress' ), |
| 28 |
), |
| 29 |
'type' => array( |
| 30 |
'label' => esc_html__( 'Type', 'learnpress' ), |
| 31 |
'type' => 'select', |
| 32 |
'options' => array( |
| 33 |
'key_features' => esc_html__( 'Key features', 'learnpress' ), |
| 34 |
'target_audience' => esc_html__( 'Target audience', 'learnpress' ), |
| 35 |
'requirements' => esc_html__( 'Requirements', 'learnpress' ), |
| 36 |
), |
| 37 |
'std' => 'key_features', |
| 38 |
), |
| 39 |
'course_id' => array( |
| 40 |
'label' => esc_html__( 'Select Course', 'learnpress' ), |
| 41 |
'type' => 'autocomplete', |
| 42 |
'post_type' => LP_COURSE_CPT, |
| 43 |
'std' => '', |
| 44 |
), |
| 45 |
'css_class' => array( |
| 46 |
'label' => esc_html__( 'CSS Class', 'learnpress' ), |
| 47 |
'type' => 'text', |
| 48 |
'std' => '', |
| 49 |
), |
| 50 |
); |
| 51 |
|
| 52 |
parent::__construct(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Show widget in frontend. |
| 57 |
*/ |
| 58 |
public function lp_rest_api_content( $instance, $params ) { |
| 59 |
if ( empty( $instance['course_id'] ) ) { |
| 60 |
return new WP_Error( 'no_params', esc_html__( 'Error: Please select a Course.', 'learnpress' ) ); |
| 61 |
} |
| 62 |
|
| 63 |
$classes = array( 'lp-widget-course-extra' ); |
| 64 |
|
| 65 |
$instance['css_class'] = $instance['css_class'] ?? ''; |
| 66 |
$classes[] = $instance['css_class']; |
| 67 |
|
| 68 |
$course_id = absint( $instance['course_id'] ); |
| 69 |
$course = learn_press_get_course( $course_id ); |
| 70 |
|
| 71 |
if ( ! $course ) { |
| 72 |
return new WP_Error( 'no_course', esc_html__( 'No Course found!', 'learnpress' ) ); |
| 73 |
} |
| 74 |
|
| 75 |
ob_start(); |
| 76 |
?> |
| 77 |
|
| 78 |
<div class="<?php echo implode( ' ', $classes ); ?>"> |
| 79 |
<h3><?php echo wp_kses_post( $course->get_title() ); ?></h3> |
| 80 |
|
| 81 |
<div class="lp-widget-course-extra__content"> |
| 82 |
<?php |
| 83 |
switch ( $instance['type'] ) { |
| 84 |
case 'key_features': |
| 85 |
LP()->template( 'course' )->course_extra_key_features( $course_id ); |
| 86 |
break; |
| 87 |
case 'target_audience': |
| 88 |
LP()->template( 'course' )->course_extra_target_audiences( $course_id ); |
| 89 |
break; |
| 90 |
case 'requirements': |
| 91 |
LP()->template( 'course' )->course_extra_requirements( $course_id ); |
| 92 |
break; |
| 93 |
} |
| 94 |
?> |
| 95 |
</div> |
| 96 |
</div> |
| 97 |
|
| 98 |
<?php |
| 99 |
return ob_get_clean(); |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|