PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.6.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.6.9
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-enroll.php

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

97 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Button Enroll Shortcode.
4 *
5 * @author ThimPress
6 * @category Shortcodes
7 * @package Learnpress/Shortcodes
8 * @version 3.0.0
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_Enroll' ) ) {
18
19 /**
20 * Class LP_Shortcode_Button_Enroll
21 *
22 * @since 3.0.0
23 */
24 class LP_Shortcode_Button_Enroll extends LP_Abstract_Shortcode {
25
26 /**
27 * LP_Shortcode_Button_Enroll constructor.
28 *
29 * @param mixed $atts
30 */
31 public function __construct( $atts = '' ) {
32 parent::__construct( $atts );
33
34 $this->_atts = shortcode_atts(
35 array(
36 'id' => 0,
37 'text' => '',
38 ),
39 $this->_atts
40 );
41 }
42
43 /**
44 * Output form.
45 *
46 * @return string
47 */
48 public function output() {
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 $course = learn_press_get_course( $course_id );
60
61 if ( $course_id && $course ) {
62 LP_Global::set_course( $course );
63 global $post;
64
65 $post = get_post( $course_id );
66
67 setup_postdata( $post );
68 add_filter( 'learn-press/enroll-course-button-text', array( $this, 'button_text' ) );
69
70 learn_press_get_template( 'single-course/buttons/enroll.php', array( 'course' => $course ) );
71
72 remove_filter( 'learn-press/enroll-course-button-text', array( $this, 'button_text' ) );
73 wp_reset_postdata();
74 LP_Global::reset();
75
76 } else {
77
78 }
79
80 return ob_get_clean();
81 }
82
83 /**
84 * @param string $text
85 *
86 * @return string
87 */
88 public function button_text( $text ) {
89 if ( $this->_atts['text'] ) {
90 $text = $this->_atts['text'];
91 }
92
93 return $text;
94 }
95 }
96 }
97