PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7.3.2
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7.3.2
4.4.8 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 All 139 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.1.7.3.2, at inc/shortcodes/class-lp-shortcode-button-course.php

124 lines 2.6 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.1
9 * @extends LP_Abstract_Shortcode
10 */
11
12 /**
13 * Prevent loading this file directly
14 */
15 defined( 'ABSPATH' ) || exit();
16
17 if ( ! class_exists( 'LP_Shortcode_Button_Course' ) ) {
18
19 /**
20 * Class LP_Shortcode_Button_Course
21 *
22 * @since 3.0.0
23 */
24 class LP_Shortcode_Button_Course extends LP_Abstract_Shortcode {
25
26 /**
27 * LP_Shortcode_Button_Course constructor.
28 *
29 * @param mixed $atts
30 */
31 public function __construct( $atts = '' ) {
32 parent::__construct( $atts );
33 $this->_atts = shortcode_atts(
34 array(
35 'id' => 0,
36 'enroll_text' => '',
37 'purchase_text' => '',
38 'btn_label' => '',
39 ),
40 $this->_atts
41 );
42 }
43
44 /**
45 * Output button course.
46 *
47 * @return string
48 */
49 public function output() {
50 ob_start();
51
52 $atts = $this->_atts;
53
54 if ( 'current' === $atts['id'] ) {
55 $course_id = learn_press_is_course() ? get_the_ID() : 0;
56 } else {
57 $course_id = $atts['id'];
58 }
59
60 try {
61 $course = learn_press_get_course( $course_id );
62 if ( ! $course ) {
63 return '';
64 }
65
66 // Load js button course.
67 wp_enqueue_script( 'lp-single-course' );
68
69 if ( $course->is_free() ) {
70 add_filter( 'learn-press/purchase-course-button-text', array( $this, 'button_text_enroll' ) );
71 } elseif ( $course->get_external_link() ) {
72 add_filter( 'learn-press/purchase-course-button-text', array( $this, 'button_text_external_link' ) );
73 } elseif ( $course->is_no_required_enroll() ) {
74
75 } else {
76 add_filter( 'learn-press/purchase-course-button-text', array( $this, 'button_text_purchase' ) );
77 }
78
79 do_action( 'learn-press/course-buttons', $course );
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 */
94 public function button_text_purchase( string $text ): string {
95 if ( $this->_atts['purchase_text'] ) {
96 $text = $this->_atts['purchase_text'];
97 } elseif ( $this->_atts['btn_label'] ) {
98 $text = $this->_atts['btn_label'];
99 }
100
101 return $text;
102 }
103
104 /**
105 * Label button enroll.
106 *
107 * @param string $text
108 *
109 * @return string
110 */
111 public function button_text_enroll( string $text ): string {
112 if ( $this->_atts['enroll_text'] ) {
113 $text = $this->_atts['enroll_text'];
114 } elseif ( $this->_atts['btn_label'] ) {
115 $text = $this->_atts['btn_label'];
116 }
117
118 return $text;
119 }
120 }
121 }
122
123 new LP_Shortcode_Button_Course();
124