PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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 / TemplateHooks / Profile / ProfileStudentEnrolledTemplate.php

ProfileStudentEnrolledTemplate.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.8, at inc/TemplateHooks/Profile/ProfileStudentEnrolledTemplate.php

98 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class ProfileStudentEnrolledTemplate.
4 *
5 * @since 4.3.3
6 * @version 1.0.1
7 */
8
9 namespace LearnPress\TemplateHooks\Profile;
10
11 use LearnPress\Helpers\Singleton;
12 use LearnPress\TemplateHooks\Admin\AdminListStudentsEnrolled;
13 use LP_Profile;
14
15 class ProfileStudentEnrolledTemplate {
16 use Singleton;
17
18 public function init(): void {
19 add_filter( 'learn-press/get-profile-tabs', array( $this, 'display_profile_tab' ), 10, 3 );
20 }
21
22 /**
23 * Show tab for instructor viewing own profile only.
24 *
25 * @param array $tabs
26 * @param mixed $user_of_profile
27 * @param mixed $user_current
28 *
29 * @return array
30 */
31 public function display_profile_tab( array $tabs, $user_of_profile, $user_current ): array {
32 if ( ! isset( $tabs['enrolled-students'] ) ) {
33 return $tabs;
34 }
35
36 // Force callback to bound instance method to ensure call_user_func_array() can execute.
37 $tabs['enrolled-students']['callback'] = array( $this, 'tab_content' );
38
39 if ( ! is_object( $user_of_profile ) || ! method_exists( $user_of_profile, 'is_instructor' ) ||
40 ! method_exists( $user_of_profile, 'get_id' ) ) {
41 unset( $tabs['enrolled-students'] );
42 return $tabs;
43 }
44
45 if ( ! is_object( $user_current ) || ! method_exists( $user_current, 'get_id' ) ) {
46 unset( $tabs['enrolled-students'] );
47 return $tabs;
48 }
49
50 if ( ! $user_of_profile->can_create_course() ) {
51 unset( $tabs['enrolled-students'] );
52 return $tabs;
53 }
54
55 // Show tab for instructor viewing own profile only.
56 if ( (int) $user_of_profile->get_id() !== (int) $user_current->get_id() ) {
57 unset( $tabs['enrolled-students'] );
58 return $tabs;
59 }
60
61 return $tabs;
62 }
63
64 /**
65 * Render content of profile tab "Enrolled Students".
66 *
67 * @param string $tab_key
68 * @param mixed $profile_tab
69 * @param mixed $user
70 *
71 * @return string
72 */
73 public function tab_content( $tab_key = '', $profile_tab = null, $user = null ): string {
74 $profile = LP_Profile::instance();
75 $user = is_object( $user ) ? $user : $profile->get_user();
76 $user_current = $profile->get_user_current();
77
78 if ( ! is_object( $user ) || ! method_exists( $user, 'can_create_course' ) || ! method_exists( $user, 'get_id' ) ) {
79 return '';
80 }
81
82 if ( ! is_object( $user_current ) || ! method_exists( $user_current, 'get_id' ) ) {
83 return '';
84 }
85
86 if ( ! $user->can_create_course() || (int) $user->get_id() !== (int) $user_current->get_id() ) {
87 return '';
88 }
89
90 ob_start();
91 echo '<div class="lp-enrolled-students">';
92 AdminListStudentsEnrolled::instance()->enrolled_students_layout( (int) $user->get_id() );
93 echo '</div>';
94
95 return ob_get_clean();
96 }
97 }
98