| 1 |
<?php |
| 2 |
namespace LearnPress\Shortcodes; |
| 3 |
|
| 4 |
use LearnPress\Helpers\Singleton; |
| 5 |
use LearnPress\Models\CourseModel; |
| 6 |
use LearnPress\Models\UserModel; |
| 7 |
use LearnPress\TemplateHooks\Course\SingleCourseModernLayout; |
| 8 |
use Throwable; |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || exit(); |
| 11 |
|
| 12 |
|
| 13 |
/** |
| 14 |
* Class CourseButtonShortcode |
| 15 |
* |
| 16 |
* Refactor from LP_Shortcode_Button_Course |
| 17 |
* |
| 18 |
* @since 4.3.0 |
| 19 |
* @version 1.0.0 |
| 20 |
*/ |
| 21 |
class CourseButtonShortcode extends AbstractShortcode { |
| 22 |
use singleton; |
| 23 |
|
| 24 |
protected $shortcode_name = 'button_course'; |
| 25 |
|
| 26 |
/** |
| 27 |
* Output button course. |
| 28 |
* |
| 29 |
* @param $atts |
| 30 |
* |
| 31 |
* @return string |
| 32 |
*/ |
| 33 |
public function render( $atts ): string { |
| 34 |
$html = ''; |
| 35 |
wp_enqueue_style( 'learnpress' ); |
| 36 |
|
| 37 |
$course_id = $atts['id'] ?? 0; |
| 38 |
if ( 'current' === $course_id ) { |
| 39 |
$course_id = get_the_ID(); |
| 40 |
} |
| 41 |
|
| 42 |
try { |
| 43 |
$singleCourseModernLayout = SingleCourseModernLayout::instance(); |
| 44 |
$courseModel = CourseModel::find( $course_id, true ); |
| 45 |
if ( ! $courseModel ) { |
| 46 |
return ''; |
| 47 |
} |
| 48 |
|
| 49 |
$userModel = UserModel::find( get_current_user_id(), true ); |
| 50 |
|
| 51 |
// Load js button course. |
| 52 |
wp_enqueue_script( 'lp-single-course' ); |
| 53 |
|
| 54 |
$html = $singleCourseModernLayout->html_buttons( $courseModel, $userModel ); |
| 55 |
} catch ( Throwable $e ) { |
| 56 |
error_log( $e->getMessage() ); |
| 57 |
} |
| 58 |
|
| 59 |
return $html; |
| 60 |
} |
| 61 |
} |
| 62 |
|