PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.1
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.1, at inc/TemplateHooks/Profile/ProfileStudentEnrolledTemplate.php

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