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

103 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 Course 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_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 ),
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 do_action( 'learn-press/course-buttons' );
69 wp_reset_postdata();
70 LP_Global::reset();
71 }
72
73 return ob_get_clean();
74 }
75
76 /**
77 * @param string $text
78 *
79 * @return string
80 */
81 public function purchase_button_text( $text ) {
82 if ( $this->_atts['purchase_text'] ) {
83 $text = $this->_atts['purchase_text'];
84 }
85
86 return $text;
87 }
88
89 /**
90 * @param string $text
91 *
92 * @return string
93 */
94 public function enroll_button_text( $text ) {
95 if ( $this->_atts['enroll_text'] ) {
96 $text = $this->_atts['enroll_text'];
97 }
98
99 return $text;
100 }
101 }
102 }
103