PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.1.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.1.7
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 / class-lp-shortcode-profile.php

class-lp-shortcode-profile.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.1.7, at inc/shortcodes/class-lp-shortcode-profile.php

90 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Profile Page Shortcode.
4 *
5 * @author ThimPress
6 * @category Shortcodes
7 * @package Learnpress/Shortcodes
8 * @version 4.0.0
9 * @extends LP_Abstract_Shortcode
10 */
11
12 defined( 'ABSPATH' ) || exit();
13
14 if ( ! class_exists( 'LP_Shortcode_Profile' ) ) {
15
16 /**
17 * Class LP_Shortcode_Profile
18 */
19 class LP_Shortcode_Profile extends LP_Abstract_Shortcode {
20 /**
21 * LP_Shortcode_Profile constructor.
22 *
23 * @param mixed $atts
24 */
25 public function __construct( $atts = '' ) {
26 parent::__construct( $atts );
27 }
28
29
30 public function can_view_profile() {
31 global $wp;
32
33 $current_user = learn_press_get_current_user();
34 $viewing_user = true;
35
36 if ( current_user_can( ADMIN_ROLE ) ) {
37 $viewing_user = true;
38 } elseif ( empty( $wp->query_vars['user'] ) ) {
39 $viewing_user = $current_user;
40 } else {
41 $wp_user = get_user_by( 'login', urldecode( $wp->query_vars['user'] ) );
42
43 if ( $wp_user ) {
44 $viewing_user = learn_press_get_user( $wp_user->ID );
45
46 if ( $viewing_user->is_guest() ) {
47 $viewing_user = false;
48 }
49 }
50 }
51
52 if ( ! $viewing_user ) {
53 return new WP_Error( 'cannot-view-profile', esc_html__( 'You can\'t viewing user profile', 'learnpress' ) );
54 }
55 }
56
57 /**
58 * Shortcode content.
59 *
60 * @return string
61 */
62 public function output() {
63 $profile = LP_Global::profile();
64
65 wp_enqueue_style( 'learnpress' );
66
67 ob_start();
68
69 if ( is_wp_error( $this->can_view_profile() ) ) {
70 $messages = array(
71 'error' => array(
72 'content' => ! empty( $this->can_view_profile()->get_error_message() ) ? $this->can_view_profile()->get_error_message() : 'LearnPress Profile: Error',
73 ),
74 );
75
76 echo '<div class="lp-content-area">';
77 learn_press_get_template( 'global/message.php', array( 'messages' => $messages ) );
78 echo '</div>';
79 } else {
80 learn_press_print_messages();
81 learn_press_get_template( 'pages/profile.php', array( 'profile' => $profile ) );
82 }
83
84 $output = ob_get_clean();
85
86 return $output;
87 }
88 }
89 }
90