| @@ -1,102 +1,102 @@ | ||
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Profile Page Shortcode. | |
| 4 | - * | |
| 5 | - * @author ThimPress | |
| 6 | - * @category Shortcodes | |
| 7 | - * @package Learnpress/Shortcodes | |
| 8 | - * @version 4.0.1 | |
| 9 | - * @extends LP_Abstract_Shortcode | |
| 10 | - */ | |
| 11 | - | |
| 12 | -use LearnPress\Helpers\Template; | |
| 13 | -use LearnPress\Models\UserModel; | |
| 14 | - | |
| 15 | -defined( 'ABSPATH' ) || exit(); | |
| 16 | - | |
| 17 | -if ( ! class_exists( 'LP_Shortcode_Profile' ) ) { | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * Class LP_Shortcode_Profile | |
| 21 | - */ | |
| 22 | - class LP_Shortcode_Profile extends LP_Abstract_Shortcode { | |
| 23 | - /** | |
| 24 | - * LP_Shortcode_Profile constructor. | |
| 25 | - * | |
| 26 | - * @param mixed $atts | |
| 27 | - */ | |
| 28 | - public function __construct( $atts = '' ) { | |
| 29 | - parent::__construct( $atts ); | |
| 30 | - } | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * @return bool|LP_User|LP_User_Guest|WP_Error | |
| 34 | - */ | |
| 35 | - /*public function can_view_profile() { | |
| 36 | - global $wp; | |
| 37 | - | |
| 38 | - $current_user = learn_press_get_current_user(); | |
| 39 | - $viewing_user = true; | |
| 40 | - | |
| 41 | - if ( ! current_user_can( ADMIN_ROLE ) ) { | |
| 42 | - if ( empty( $wp->query_vars['user'] ) ) { | |
| 43 | - $viewing_user = $current_user; | |
| 44 | - } else { | |
| 45 | - $request_user = urldecode( (string) $wp->query_vars['user'] ); | |
| 46 | - $user_model = new UserModel(); | |
| 47 | - $wp_user = $user_model->resolve_user_by_public_identifier( $request_user ); | |
| 48 | - | |
| 49 | - if ( $wp_user ) { | |
| 50 | - $viewing_user = learn_press_get_user( $wp_user->ID ); | |
| 51 | - | |
| 52 | - if ( $viewing_user->is_guest() ) { | |
| 53 | - $viewing_user = false; | |
| 54 | - } | |
| 55 | - } | |
| 56 | - } | |
| 57 | - } | |
| 58 | - | |
| 59 | - $viewing_user = apply_filters( 'learn-press/profile/can-view-user', $viewing_user ); | |
| 60 | - | |
| 61 | - if ( ! $viewing_user ) { | |
| 62 | - return new WP_Error( 'cannot-view-profile', esc_html__( 'You can\'t view the user profile', 'learnpress' ) ); | |
| 63 | - } | |
| 64 | - | |
| 65 | - return $viewing_user; | |
| 66 | - }*/ | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * Shortcode content. | |
| 70 | - * | |
| 71 | - * @return string | |
| 72 | - */ | |
| 73 | - public function output() { | |
| 74 | - wp_enqueue_style( 'learnpress' ); | |
| 75 | - wp_enqueue_script( 'lp-profile' ); | |
| 76 | - ob_start(); | |
| 77 | - | |
| 78 | - try { | |
| 79 | - $profile = LP_Profile::instance(); | |
| 80 | - if ( ! LP_Page_Controller::is_page_profile() ) { | |
| 81 | - throw new Exception( | |
| 82 | - sprintf( | |
| 83 | - __( 'This shortcode LP Profile only use on the page <a href="%1$s">%2$s</a>', 'learnpress' ), | |
| 84 | - admin_url( 'admin.php?page=learn-press-settings' ), | |
| 85 | - '<strong>' . esc_html__( 'Profile', 'learnpress' ) . '</strong>' | |
| 86 | - ) | |
| 87 | - ); | |
| 88 | - } | |
| 89 | - | |
| 90 | - learn_press_show_message(); | |
| 91 | - Template::instance()->get_frontend_template( | |
| 92 | - 'pages/profile.php', | |
| 93 | - compact( 'profile' ) | |
| 94 | - ); | |
| 95 | - } catch ( Throwable $e ) { | |
| 96 | - Template::print_message( $e->getMessage(), 'error' ); | |
| 97 | - } | |
| 98 | - | |
| 99 | - return ob_get_clean(); | |
| 100 | - } | |
| 101 | - } | |
| 102 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Profile Page Shortcode. | |
| 4 | + * | |
| 5 | + * @author ThimPress | |
| 6 | + * @category Shortcodes | |
| 7 | + * @package Learnpress/Shortcodes | |
| 8 | + * @version 4.0.1 | |
| 9 | + * @extends LP_Abstract_Shortcode | |
| 10 | + */ | |
| 11 | + | |
| 12 | +use LearnPress\Helpers\Template; | |
| 13 | +use LearnPress\Models\UserModel; | |
| 14 | + | |
| 15 | +defined( 'ABSPATH' ) || exit(); | |
| 16 | + | |
| 17 | +if ( ! class_exists( 'LP_Shortcode_Profile' ) ) { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * Class LP_Shortcode_Profile | |
| 21 | + */ | |
| 22 | + class LP_Shortcode_Profile extends LP_Abstract_Shortcode { | |
| 23 | + /** | |
| 24 | + * LP_Shortcode_Profile constructor. | |
| 25 | + * | |
| 26 | + * @param mixed $atts | |
| 27 | + */ | |
| 28 | + public function __construct( $atts = '' ) { | |
| 29 | + parent::__construct( $atts ); | |
| 30 | + } | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * @return bool|LP_User|LP_User_Guest|WP_Error | |
| 34 | + */ | |
| 35 | + /*public function can_view_profile() { | |
| 36 | + global $wp; | |
| 37 | + | |
| 38 | + $current_user = learn_press_get_current_user(); | |
| 39 | + $viewing_user = true; | |
| 40 | + | |
| 41 | + if ( ! current_user_can( ADMIN_ROLE ) ) { | |
| 42 | + if ( empty( $wp->query_vars['user'] ) ) { | |
| 43 | + $viewing_user = $current_user; | |
| 44 | + } else { | |
| 45 | + $request_user = urldecode( (string) $wp->query_vars['user'] ); | |
| 46 | + $user_model = new UserModel(); | |
| 47 | + $wp_user = $user_model->resolve_user_by_public_identifier( $request_user ); | |
| 48 | + | |
| 49 | + if ( $wp_user ) { | |
| 50 | + $viewing_user = learn_press_get_user( $wp_user->ID ); | |
| 51 | + | |
| 52 | + if ( $viewing_user->is_guest() ) { | |
| 53 | + $viewing_user = false; | |
| 54 | + } | |
| 55 | + } | |
| 56 | + } | |
| 57 | + } | |
| 58 | + | |
| 59 | + $viewing_user = apply_filters( 'learn-press/profile/can-view-user', $viewing_user ); | |
| 60 | + | |
| 61 | + if ( ! $viewing_user ) { | |
| 62 | + return new WP_Error( 'cannot-view-profile', esc_html__( 'You can\'t view the user profile', 'learnpress' ) ); | |
| 63 | + } | |
| 64 | + | |
| 65 | + return $viewing_user; | |
| 66 | + }*/ | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Shortcode content. | |
| 70 | + * | |
| 71 | + * @return string | |
| 72 | + */ | |
| 73 | + public function output() { | |
| 74 | + wp_enqueue_style( 'learnpress' ); | |
| 75 | + wp_enqueue_script( 'lp-profile' ); | |
| 76 | + ob_start(); | |
| 77 | + | |
| 78 | + try { | |
| 79 | + $profile = LP_Profile::instance(); | |
| 80 | + if ( ! LP_Page_Controller::is_page_profile() ) { | |
| 81 | + throw new Exception( | |
| 82 | + sprintf( | |
| 83 | + __( 'This shortcode LP Profile only use on the page <a href="%1$s">%2$s</a>', 'learnpress' ), | |
| 84 | + admin_url( 'admin.php?page=learn-press-settings' ), | |
| 85 | + '<strong>' . esc_html__( 'Profile', 'learnpress' ) . '</strong>' | |
| 86 | + ) | |
| 87 | + ); | |
| 88 | + } | |
| 89 | + | |
| 90 | + learn_press_show_message(); | |
| 91 | + Template::instance()->get_frontend_template( | |
| 92 | + 'pages/profile.php', | |
| 93 | + compact( 'profile' ) | |
| 94 | + ); | |
| 95 | + } catch ( Throwable $e ) { | |
| 96 | + Template::print_message( $e->getMessage(), 'error' ); | |
| 97 | + } | |
| 98 | + | |
| 99 | + return ob_get_clean(); | |
| 100 | + } | |
| 101 | + } | |
| 102 | +} | |