PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 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 All 140 releases
← All changes | inc/TemplateHooks/Profile/ProfileStudentEnrolledTemplate.php +97 -96 4.3.9 → 4.4.9 View file →
@@ -1,96 +1,97 @@
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 -}
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 +}