PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.1
4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 4.2.1 All 138 releases
learnpress / inc / Shortcodes / class-lp-shortcode-button-course.php

class-lp-shortcode-button-course.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.1, at inc/Shortcodes/class-lp-shortcode-button-course.php

126 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Button Course Shortcode.
4 *
5 * @author ThimPress
6 * @category Shortcodes
7 * @package Learnpress/Shortcodes
8 * @version 3.0.2
9 * @extends LP_Abstract_Shortcode
10 * @depreacted 4.3.0
11 */
12 use LearnPress\Models\CourseModel;
13 use LearnPress\Models\UserModel;
14 use LearnPress\TemplateHooks\Course\SingleCourseTemplate;
15
16 defined( 'ABSPATH' ) || exit();
17
18 if ( ! class_exists( 'LP_Shortcode_Button_Course' ) ) {
19
20 /**
21 * Class LP_Shortcode_Button_Course
22 *
23 * @since 3.0.0
24 */
25 class LP_Shortcode_Button_Course extends LP_Abstract_Shortcode {
26
27 /**
28 * LP_Shortcode_Button_Course constructor.
29 *
30 * @param mixed $atts
31 */
32 public function __construct( $atts = '' ) {
33 parent::__construct( $atts );
34 $this->_atts = shortcode_atts(
35 array(
36 'id' => 0,
37 ),
38 $this->_atts
39 );
40 }
41
42 /**
43 * Output button course.
44 *
45 * @return string
46 */
47 public function output() {
48 wp_enqueue_style( 'learnpress' );
49 ob_start();
50
51 $atts = $this->_atts;
52
53 if ( 'current' === $atts['id'] ) {
54 $course_id = learn_press_is_course() ? get_the_ID() : 0;
55 } else {
56 $course_id = $atts['id'];
57 }
58
59 try {
60 $singleCourseTemplate = SingleCourseTemplate::instance();
61 $courseModel = CourseModel::find( $course_id, true );
62 if ( ! $courseModel ) {
63 return '';
64 }
65
66 $userModel = UserModel::find( get_current_user_id(), true );
67
68 // Load js button course.
69 wp_enqueue_script( 'lp-single-course' );
70
71 if ( $courseModel->is_free() ) {
72 echo $singleCourseTemplate->html_btn_enroll_course( $courseModel, $userModel );
73 } elseif ( ! empty( $courseModel->get_external_link() ) ) {
74 echo $singleCourseTemplate->html_btn_external( $courseModel, $userModel );
75 } elseif ( $courseModel->has_no_enroll_requirement() ) {
76 printf( '<a href="%s">%s</a>', $courseModel->get_permalink(), __( 'Learn now', 'learnpress' ) );
77 } else {
78 echo $singleCourseTemplate->html_btn_purchase_course( $courseModel, $userModel );
79 }
80 } catch ( Throwable $e ) {
81 error_log( $e->getMessage() );
82 }
83
84 return ob_get_clean();
85 }
86
87 /**
88 * Label button purchase.
89 *
90 * @param string $text
91 *
92 * @return string
93 * @deprecated 4.2.7.5
94 */
95 public function button_text_purchase( string $text ): string {
96 if ( $this->_atts['purchase_text'] ) {
97 $text = $this->_atts['purchase_text'];
98 } elseif ( $this->_atts['btn_label'] ) {
99 $text = $this->_atts['btn_label'];
100 }
101
102 return $text;
103 }
104
105 /**
106 * Label button enroll.
107 *
108 * @param string $text
109 *
110 * @return string
111 * @deprecated 4.2.7.5
112 */
113 public function button_text_enroll( string $text ): string {
114 if ( $this->_atts['enroll_text'] ) {
115 $text = $this->_atts['enroll_text'];
116 } elseif ( $this->_atts['btn_label'] ) {
117 $text = $this->_atts['btn_label'];
118 }
119
120 return $text;
121 }
122 }
123 }
124
125 new LP_Shortcode_Button_Course();
126