PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.7
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 / class-lp-shortcodes.php

class-lp-shortcodes.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.7, at inc/class-lp-shortcodes.php

279 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Base class of LearnPress shortcodes and helper functions.
4 *
5 * @author ThimPress
6 * @category Shortcode
7 * @package Learnpress/Shortcodes
8 * @version 3.0.0
9 */
10
11 defined( 'ABSPATH' ) || exit();
12
13 if ( ! class_exists( 'LP_Shortcodes' ) ) {
14 /**
15 * LP_Shortcodes class
16 */
17 class LP_Shortcodes {
18 /**
19 * Init shortcodes
20 */
21 public static function init() {
22 $shortcodes = array(
23 'confirm_order' => __CLASS__ . '::confirm_order',
24 'profile' => __CLASS__ . '::profile',
25 'become_teacher_form' => __CLASS__ . '::become_teacher_form',
26 'login_form' => __CLASS__ . '::login_form',
27 'register_form' => __CLASS__ . '::register_form',
28 'checkout' => __CLASS__ . '::checkout',
29 'recent_courses' => __CLASS__ . '::recent_courses',
30 'featured_courses' => __CLASS__ . '::featured_courses',
31 'popular_courses' => __CLASS__ . '::popular_courses',
32 //'button_enroll' => __CLASS__ . '::button_enroll',
33 //'button_purchase' => __CLASS__ . '::button_purchase',
34 //'button_course' => __CLASS__ . '::button_course',
35 'course_curriculum' => __CLASS__ . '::course_curriculum',
36 );
37
38 foreach ( $shortcodes as $shortcode => $function ) {
39 $shortcode = "learn_press_{$shortcode}";
40 add_shortcode( apply_filters( "learn-press/shortcode/{$shortcode}/tag", $shortcode ), $function );
41 }
42
43 add_action( 'template_include', array( __CLASS__, 'auto_shortcode' ), - 10, 2 );
44 }
45
46 /**
47 * Auto add shortcode into some default pages.
48 *
49 * @param $template
50 *
51 * @return mixed
52 */
53 public static function auto_shortcode( $template ) {
54 global $post;
55
56 if ( ! $post ) {
57 return $template;
58 }
59
60 // Option enable auto add shortcode. @since 4.2.3
61 $enable = apply_filters( 'learn-press/auto-shortcode', true, $post );
62 if ( ! $enable ) {
63 return $template;
64 }
65
66 if ( LP_Page_Controller::is_page_checkout() ) {
67 if ( ! preg_match( '/\[learn_press_checkout\s?(.*)/', $post->post_content ) ) {
68 $post->post_content .= '[learn_press_checkout]';
69 }
70 } elseif ( $post->ID == learn_press_get_page_id( 'become_a_teacher' ) ) {
71 if ( ! preg_match( '/\[learn_press_become_teacher_form\s?(.*)/', $post->post_content ) ) {
72 $post->post_content .= '[learn_press_become_teacher_form]';
73 }
74 } elseif ( LP_Page_Controller::is_page_profile() ) {
75 if ( ! preg_match( '/\[learn_press_profile\s?(.*)/', $post->post_content ) ) {
76 $post->post_content .= '[learn_press_profile]';
77 }
78 } elseif ( LP_Page_Controller::is_page_instructor() ) {
79 if ( ! preg_match( '/\[learn_press_single_instructor\s?(.*)/', $post->post_content ) ) {
80 // $post->post_content .= '[learn_press_single_instructor]';
81 }
82 } elseif ( LP_Page_Controller::is_page_instructors() ) {
83 if ( ! preg_match( '/\[learn_press_instructors\s?(.*)/', $post->post_content ) ) {
84 $post->post_content .= '[learn_press_instructors]';
85 }
86 }
87
88 return $template;
89 }
90
91 /**
92 * Wrap content of a shortcode into wrapper element.
93 *
94 * @param string $content
95 *
96 * @return string
97 */
98 public static function wrapper_shortcode( $content ) {
99 ob_start();
100 learn_press_print_messages();
101 $html = ob_get_clean();
102
103 try {
104 $html .= $content->output();
105 } catch ( Exception $ex ) {
106 $html .= $ex->getMessage();
107 }
108
109 return '<div class="learnpress">' . $html . '</div>';
110 }
111
112 /**
113 * Displaying recently courses added.
114 *
115 * @param mixed $atts
116 *
117 * @return string
118 */
119 public static function recent_courses( $atts ) {
120 return self::wrapper_shortcode( new LP_Shortcode_Recent_Courses( $atts ) );
121 }
122
123 /**
124 * Displaying courses are set as featured.
125 *
126 * @param array $atts
127 *
128 * @return string
129 */
130 public static function featured_courses( $atts ) {
131 return self::wrapper_shortcode( new LP_Shortcode_Featured_Courses( $atts ) );
132 }
133
134 /**
135 * Displaying popular courses.
136 *
137 * @param array $atts
138 *
139 * @return string
140 */
141 public static function popular_courses( $atts ) {
142 return self::wrapper_shortcode( new LP_Shortcode_Popular_Courses( $atts ) );
143 }
144
145 /**
146 * Displaying checkout form.
147 *
148 * @param mixed $atts
149 *
150 * @return string
151 */
152 public static function checkout( $atts ) {
153 return self::wrapper_shortcode( new LP_Shortcode_Checkout( $atts ) );
154 }
155
156 /**
157 * Display content of user profile.
158 *
159 * @param mixed $atts
160 *
161 * @return string
162 */
163 public static function profile( $atts ) {
164 return self::wrapper_shortcode( new LP_Shortcode_Profile( $atts ) );
165 }
166
167 /**
168 * Display a form let the user can be join as a teacher.
169 *
170 * @param array|null
171 *
172 * @return string
173 */
174 public static function become_teacher_form( $atts ) {
175 return self::wrapper_shortcode( new LP_Shortcode_Become_A_Teacher( $atts ) );
176 }
177
178 /**
179 * Display a register user form.
180 *
181 * @param array|null
182 *
183 * @return string
184 */
185 public static function register_form( $atts ) {
186 return self::wrapper_shortcode( new LP_Shortcode_Register_Form( $atts ) );
187 }
188
189 /**
190 * Shortcode content for "Confirm Order" page
191 *
192 * @param array $atts
193 *
194 * @return string
195 */
196 public static function confirm_order( $atts = null ) {
197 $atts = shortcode_atts(
198 array(
199 'order_id' => ! empty( $_REQUEST['order_id'] ) ? intval( $_REQUEST['order_id'] ) : 0,
200 ),
201 $atts
202 );
203
204 $order_id = null;
205
206 extract( $atts ); // phpcs:ignore
207
208 ob_start();
209
210 $order = learn_press_get_order( $order_id );
211
212 if ( $order ) {
213 learn_press_get_template( 'order/confirm.php', array( 'order' => $order ) );
214 }
215
216 return self::wrapper_shortcode( ob_get_clean() );
217 }
218
219 public static function login_form( $atts, $content = '' ) {
220 $atts = shortcode_atts(
221 array(
222 'redirect' => '',
223 ),
224 $atts
225 );
226 add_filter( 'login_form_bottom', array( __CLASS__, 'login_form_bottom' ), 10, 2 );
227
228 return self::wrapper_shortcode( new LP_Shortcode_Login_Form( $atts ) );
229 }
230
231
232 public static function login_form_bottom( $html, $args ) {
233 ob_start();
234 ?>
235 <p>
236 <a href="<?php echo wp_lostpassword_url(); ?>"><?php esc_html_e( 'Forgot password?', 'learnpress' ); ?></a>
237 &nbsp;|&nbsp;
238 <a href="<?php echo wp_registration_url(); ?>"><?php esc_html_e( 'Create a new account', 'learnpress' ); ?></a>
239 </p>
240 <?php
241 $html .= ob_get_clean();
242
243 return $html;
244 }
245
246 /**
247 * @param $atts
248 * @param string $content
249 *
250 * @return LP_Shortcode_Button_Purchase
251 */
252 /*public static function button_purchase( $atts, $content = '' ) {
253 return new LP_Shortcode_Button_Purchase( $atts );
254 }*/
255
256 /**
257 * @param $atts
258 * @param string $content
259 *
260 * @return LP_Shortcode_Button_Course
261 */
262 /*public static function button_course( $atts, $content = '' ) {
263 return new LP_Shortcode_Button_Course( $atts );
264 }*/
265
266 /**
267 * @param array $atts
268 * @param string $content
269 *
270 * @return LP_Shortcode_Course_Curriculum
271 */
272 public static function course_curriculum( $atts, $content = '' ) {
273 return new LP_Shortcode_Course_Curriculum( $atts );
274 }
275 }
276 }
277
278 add_action( 'init', array( 'LP_Shortcodes', 'init' ) );
279