PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / trunk
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses vtrunk
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 / CourseButtonShortcode.php

CourseButtonShortcode.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses trunk, at inc/Shortcodes/CourseButtonShortcode.php

62 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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