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

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

261 lines 6.3 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 if ( $post->ID == learn_press_get_page_id( 'checkout' ) ) {
61 if ( ! preg_match( '/\[learn_press_checkout\s?(.*)\]/', $post->post_content ) ) {
62 $post->post_content .= '[learn_press_checkout]';
63 }
64 } elseif ( $post->ID == learn_press_get_page_id( 'become_a_teacher' ) ) {
65 if ( ! preg_match( '/\[learn_press_become_teacher_form\s?(.*)\]/', $post->post_content ) ) {
66 $post->post_content .= '[learn_press_become_teacher_form]';
67 }
68 }
69
70 return $template;
71 }
72
73 /**
74 * Wrap content of a shortcode into wrapper element.
75 *
76 * @param string $content
77 *
78 * @return string
79 */
80 public static function wrapper_shortcode( $content ) {
81 ob_start();
82 learn_press_print_messages();
83 $html = ob_get_clean();
84
85 try {
86 $html .= $content->output();
87 } catch ( Exception $ex ) {
88 $html .= $ex->getMessage();
89 }
90
91 return '<div class="learnpress">' . $html . '</div>';
92 }
93
94 /**
95 * Displaying recently courses added.
96 *
97 * @param mixed $atts
98 *
99 * @return string
100 */
101 public static function recent_courses( $atts ) {
102 return self::wrapper_shortcode( new LP_Shortcode_Recent_Courses( $atts ) );
103 }
104
105 /**
106 * Displaying courses are set as featured.
107 *
108 * @param array $atts
109 *
110 * @return string
111 */
112 public static function featured_courses( $atts ) {
113 return self::wrapper_shortcode( new LP_Shortcode_Featured_Courses( $atts ) );
114 }
115
116 /**
117 * Displaying popular courses.
118 *
119 * @param array $atts
120 *
121 * @return string
122 */
123 public static function popular_courses( $atts ) {
124 return self::wrapper_shortcode( new LP_Shortcode_Popular_Courses( $atts ) );
125 }
126
127 /**
128 * Displaying checkout form.
129 *
130 * @param mixed $atts
131 *
132 * @return string
133 */
134 public static function checkout( $atts ) {
135 return self::wrapper_shortcode( new LP_Shortcode_Checkout( $atts ) );
136 }
137
138 /**
139 * Display content of user profile.
140 *
141 * @param mixed $atts
142 *
143 * @return string
144 */
145 public static function profile( $atts ) {
146 return self::wrapper_shortcode( new LP_Shortcode_Profile( $atts ) );
147 }
148
149 /**
150 * Display a form let the user can be join as a teacher.
151 *
152 * @param array|null
153 *
154 * @return string
155 */
156 public static function become_teacher_form( $atts ) {
157 return self::wrapper_shortcode( new LP_Shortcode_Become_A_Teacher( $atts ) );
158 }
159
160 /**
161 * Display a register user form.
162 *
163 * @param array|null
164 *
165 * @return string
166 */
167 public static function register_form( $atts ) {
168 return self::wrapper_shortcode( new LP_Shortcode_Register_Form( $atts ) );
169 }
170
171 /**
172 * Shortcode content for "Confirm Order" page
173 *
174 * @param array $atts
175 *
176 * @return string
177 */
178 public static function confirm_order( $atts = null ) {
179 $atts = shortcode_atts(
180 array(
181 'order_id' => ! empty( $_REQUEST['order_id'] ) ? intval( $_REQUEST['order_id'] ) : 0,
182 ),
183 $atts
184 );
185
186 $order_id = null;
187
188 extract( $atts ); // phpcs:ignore
189
190 ob_start();
191
192 $order = learn_press_get_order( $order_id );
193
194 if ( $order ) {
195 learn_press_get_template( 'order/confirm.php', array( 'order' => $order ) );
196 }
197
198 return self::wrapper_shortcode( ob_get_clean() );
199 }
200
201 public static function login_form( $atts, $content = '' ) {
202 $atts = shortcode_atts(
203 array(
204 'redirect' => '',
205 ),
206 $atts
207 );
208 add_filter( 'login_form_bottom', array( __CLASS__, 'login_form_bottom' ), 10, 2 );
209
210 return self::wrapper_shortcode( new LP_Shortcode_Login_Form( $atts ) );
211 }
212
213
214 public static function login_form_bottom( $html, $args ) {
215 ob_start();
216 ?>
217 <p>
218 <a href="<?php echo wp_lostpassword_url(); ?>"><?php esc_html_e( 'Forgot password?', 'learnpress' ); ?></a>
219 &nbsp;|&nbsp;
220 <a href="<?php echo wp_registration_url(); ?>"><?php esc_html_e( 'Create a new account', 'learnpress' ); ?></a>
221 </p>
222 <?php
223 $html .= ob_get_clean();
224
225 return $html;
226 }
227
228 /**
229 * @param $atts
230 * @param string $content
231 *
232 * @return LP_Shortcode_Button_Purchase
233 */
234 public static function button_purchase( $atts, $content = '' ) {
235 return new LP_Shortcode_Button_Purchase( $atts );
236 }
237
238 /**
239 * @param $atts
240 * @param string $content
241 *
242 * @return LP_Shortcode_Button_Course
243 */
244 public static function button_course( $atts, $content = '' ) {
245 return new LP_Shortcode_Button_Course( $atts );
246 }
247
248 /**
249 * @param array $atts
250 * @param string $content
251 *
252 * @return LP_Shortcode_Course_Curriculum
253 */
254 public static function course_curriculum( $atts, $content = '' ) {
255 return new LP_Shortcode_Course_Curriculum( $atts );
256 }
257 }
258 }
259
260 add_action( 'init', array( 'LP_Shortcodes', 'init' ) );
261