| 1 |
<?php |
| 2 |
/** |
| 3 |
* Button Purchase 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_Purchase' ) ) { |
| 18 |
|
| 19 |
/** |
| 20 |
* Class LP_Shortcode_Button_Purchase |
| 21 |
* |
| 22 |
* @since 3.0.0 |
| 23 |
*/ |
| 24 |
class LP_Shortcode_Button_Purchase extends LP_Abstract_Shortcode { |
| 25 |
/** |
| 26 |
* LP_Shortcode_Button_Purchase constructor. |
| 27 |
* |
| 28 |
* @param mixed $atts |
| 29 |
*/ |
| 30 |
public function __construct( $atts = '' ) { |
| 31 |
parent::__construct( $atts ); |
| 32 |
|
| 33 |
$this->_atts = shortcode_atts( |
| 34 |
array( |
| 35 |
'id' => 0, |
| 36 |
'text' => '', |
| 37 |
), |
| 38 |
$this->_atts |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Output form. |
| 44 |
* |
| 45 |
* @return string |
| 46 |
*/ |
| 47 |
public function output() { |
| 48 |
ob_start(); |
| 49 |
|
| 50 |
$atts = $this->_atts; |
| 51 |
if ( 'current' === $atts['id'] ) { |
| 52 |
$course_id = learn_press_is_course() ? get_the_ID() : 0; |
| 53 |
} else { |
| 54 |
$course_id = $atts['id']; |
| 55 |
} |
| 56 |
|
| 57 |
$course = learn_press_get_course( $course_id ); |
| 58 |
if ( ! $course ) { |
| 59 |
return ''; |
| 60 |
} |
| 61 |
|
| 62 |
if ( ! $course->is_free() ) { |
| 63 |
wp_enqueue_script( 'lp-single-course' ); |
| 64 |
add_filter( 'learn-press/purchase-course-button-text', array( $this, 'button_text' ) ); |
| 65 |
do_action( 'learn-press/course-buttons', $course ); |
| 66 |
} |
| 67 |
|
| 68 |
return ob_get_clean(); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* @param string $text |
| 73 |
* |
| 74 |
* @return string |
| 75 |
*/ |
| 76 |
public function button_text( $text ) { |
| 77 |
if ( $this->_atts['text'] ) { |
| 78 |
$text = $this->_atts['text']; |
| 79 |
} |
| 80 |
|
| 81 |
return $text; |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|