diff --git a/config/profile-tabs.php b/config/profile-tabs.php new file mode 100644 index 000000000..9bf7480ad --- /dev/null +++ b/config/profile-tabs.php @@ -0,0 +1,97 @@ + array( + 'title' => esc_html__( 'Courses', 'learnpress' ), + 'slug' => $settings->get( 'profile_endpoints.courses', 'courses' ), + 'callback' => array( LP_Template_Profile::class, 'tab_courses' ), + 'priority' => 1, + 'icon' => '', + ), + 'my-courses' => array( + 'title' => esc_html__( 'My Courses', 'learnpress' ), + 'slug' => $settings->get( 'profile_endpoints.my-courses', 'my-courses' ), + 'callback' => array( LP_Template_Profile::class, 'tab_my_courses' ), + 'priority' => 1, + 'icon' => '', + ), + 'quizzes' => array( + 'title' => esc_html__( 'Quizzes', 'learnpress' ), + 'slug' => $settings->get( 'profile_endpoints.quizzes', 'quizzes' ), + 'callback' => false, + 'priority' => 20, + 'icon' => '', + ), + 'orders' => array( + 'title' => esc_html__( 'Orders', 'learnpress' ), + 'slug' => $settings->get( 'profile_endpoints.orders', 'orders' ), + 'callback' => [ ProfileOrdersTemplate::class, 'tab_content' ], + 'priority' => 25, + 'icon' => '', + ), + 'order-details' => array( + 'title' => esc_html__( 'Order details', 'learnpress' ), + 'slug' => $settings->get( 'profile_endpoints.order-details', 'order-details' ), + 'hidden' => true, + 'callback' => [ ProfileOrderTemplate::class, 'content' ], + 'priority' => 30, + ), + 'settings' => array( + 'title' => esc_html__( 'Settings', 'learnpress' ), + 'slug' => $settings->get( 'profile_endpoints.settings', 'settings' ), + 'callback' => false, + 'sections' => array( + 'basic-information' => array( + 'title' => esc_html__( 'General', 'learnpress' ), + 'slug' => $settings->get( 'profile_endpoints.settings-basic-information', 'basic-information' ), + 'callback' => false, + 'priority' => 10, + 'icon' => '', + ), + 'avatar' => array( + 'title' => esc_html__( 'Avatar', 'learnpress' ), + 'callback' => false, + 'slug' => $settings->get( 'profile_endpoints.settings-avatar', 'avatar' ), + 'priority' => 20, + 'icon' => '', + ), + 'change-password' => array( + 'title' => esc_html__( 'Password', 'learnpress' ), + 'slug' => $settings->get( 'profile_endpoints.settings-change-password', 'change-password' ), + 'callback' => false, + 'priority' => 30, + 'icon' => '', + ), + ), + 'priority' => 90, + 'icon' => '', + ), + 'logout' => array( + 'title' => esc_html__( 'Logout', 'learnpress' ), + 'slug' => learn_press_profile_logout_slug(), + 'icon' => '', + 'priority' => 100, + ), +); + +if ( 'yes' === LP_Profile::get_option_publish_profile() ) { + $default_settings['settings']['sections']['privacy'] = array( + 'title' => esc_html__( 'Privacy', 'learnpress' ), + 'slug' => $settings->get( 'profile_endpoints.settings-privacy', 'privacy' ), + 'priority' => 40, + 'callback' => false, + 'icon' => '', + ); +} + +return apply_filters( 'learn-press/profile-tabs', $default_settings ); diff --git a/inc/ExternalPlugin/Polylang/class-lp-polylang.php b/inc/ExternalPlugin/Polylang/class-lp-polylang.php index 147b45843..fdfa89ad1 100644 --- a/inc/ExternalPlugin/Polylang/class-lp-polylang.php +++ b/inc/ExternalPlugin/Polylang/class-lp-polylang.php @@ -386,21 +386,20 @@ public function add_rewrite_rules_profile( &$rules, $lang_slug, $lang_get_option ]; // Rule view profile of user (self or another) with tab - $profile = learn_press_get_profile(); - $tabs = $profile->get_tabs()->get(); + $tabs = LP_Profile::get_tabs_arr(); if ( $tabs ) { /** * @var LP_Profile_Tab $args */ foreach ( $tabs as $tab_key => $args ) { - $tab_slug = $args->get( 'slug' ) ?? $tab_key; + $tab_slug = $args['slug'] ?? $tab_key; $rules['profile'][ $tab_key . '_' . $lang ] = [ "^{$lang_slug}{$page_profile_slug}/([^/]*)/({$tab_slug})/?([0-9]*)/?$" => 'index.php?page_id=' . $profile_page_id_lang . '&user=$matches[1]&view=$matches[2]&view_id=$matches[3]', ]; - if ( ! empty( $args->get( 'sections' ) ) ) { - foreach ( $args->get( 'sections' ) as $section_key => $section ) { + if ( ! empty( $args['sections'] ) ) { + foreach ( $args['sections'] as $section_key => $section ) { $section_slug = $section['slug'] ?? $section_key; $rules['profile'][ $section_key . '_' . $lang ] = [ "^{$lang_slug}{$page_profile_slug}/([^/]*)/({$tab_slug})/({$section_slug})/?([0-9]*)?$" => diff --git a/inc/Shortcodes/class-lp-shortcode-profile.php b/inc/Shortcodes/class-lp-shortcode-profile.php index d1bf513d0..90feffe28 100644 --- a/inc/Shortcodes/class-lp-shortcode-profile.php +++ b/inc/Shortcodes/class-lp-shortcode-profile.php @@ -68,7 +68,7 @@ public function can_view_profile() { * @return string */ public function output() { - $profile = LP_Global::profile(); + $profile = LP_Profile::instance(); $output = ''; wp_enqueue_style( 'learnpress' ); wp_enqueue_script( 'lp-profile' ); diff --git a/inc/TemplateHooks/Profile/ProfileOrderTemplate.php b/inc/TemplateHooks/Profile/ProfileOrderTemplate.php new file mode 100644 index 000000000..24b534521 --- /dev/null +++ b/inc/TemplateHooks/Profile/ProfileOrderTemplate.php @@ -0,0 +1,55 @@ +get_view_order(); + if ( false === $order ) { + return; + } + + $can_view = false; + if ( current_user_can( ADMIN_ROLE )) { + $can_view = true; + } elseif ( (int) $order->get_user_id() === get_current_user_id() ) { + $can_view = true; + } + + if ( ! $can_view ) { + return; + } + + learn_press_get_template( 'order/order-details.php', compact( 'order' ) ); + } +} diff --git a/inc/admin/class-lp-admin.php b/inc/admin/class-lp-admin.php index 1a70c3730..0556f90b3 100644 --- a/inc/admin/class-lp-admin.php +++ b/inc/admin/class-lp-admin.php @@ -498,7 +498,7 @@ public function filter_users( $action ) { } $nonce = LP_Request::get_param( 'nonce' ); - if ( wp_verify_nonce( $nonce, 'lp-action-permit-role-teacher' ) === false ) { + if ( ! wp_verify_nonce( $nonce, 'lp-action-permit-role-teacher' ) ) { return; } diff --git a/inc/class-lp-query.php b/inc/class-lp-query.php index c83326a5c..3c1f991c2 100644 --- a/inc/class-lp-query.php +++ b/inc/class-lp-query.php @@ -108,10 +108,10 @@ public function add_rewrite_endpoints() { * * link item course * link profile - * @since 3.0.0 - * @version 1.0.3 - * @modify 4.2.2 * @return array + * @version 1.0.4 + * @modify 4.2.2 + * @since 3.0.0 */ public function add_rewrite_rules(): array { $rules = array(); @@ -202,21 +202,17 @@ public function add_rewrite_rules_profile( &$rules ) { ]; // Rule view profile of user (self or another) with tab - $profile = learn_press_get_profile(); - $tabs = $profile->get_tabs()->get(); + $tabs = LP_Profile::get_tabs_arr(); if ( $tabs ) { - /** - * @var LP_Profile_Tab $args - */ foreach ( $tabs as $tab_key => $args ) { - $tab_slug = $args->get( 'slug' ) ?? $tab_key; + $tab_slug = $args['slug'] ?? $tab_key; $rules['profile'][ $tab_key ] = [ "^{$page_profile_slug}/([^/]*)/({$tab_slug})/?([0-9]*)/?$" => 'index.php?page_id=' . $profile_id . '&user=$matches[1]&view=$matches[2]&view_id=$matches[3]', ]; - if ( ! empty( $args->get( 'sections' ) ) ) { - foreach ( $args->get( 'sections' ) as $section_key => $section ) { + if ( ! empty( $args['sections'] ) ) { + foreach ( $args['sections'] as $section_key => $section ) { $section_slug = $section['slug'] ?? $section_key; $rules['profile'][ $section_key ] = [ "^{$page_profile_slug}/([^/]*)/({$tab_slug})/({$section_slug})/?([0-9]*)?$" => @@ -313,10 +309,10 @@ public function remove_query_tax() { * Fixed for case: addons Certificates (v4.0.5), FE(4.0.5), Live(4.0.2), Collections(4.0.2) not installed on site client. * Run only one time when reload page Frontend. * - * @see get_option() hook in this function. + * @return mixed|array * @since 4.2.2 * @version 1.0.1 - * @return mixed|array + * @see get_option() hook in this function. */ public function update_option_rewrite_rules( $wp_rules ) { if ( ! is_array( $wp_rules ) ) { diff --git a/inc/lp-core-functions.php b/inc/lp-core-functions.php index c66c93608..74c9db66e 100644 --- a/inc/lp-core-functions.php +++ b/inc/lp-core-functions.php @@ -2078,6 +2078,7 @@ function learn_press_get_current_version() { * * @return mixed|string * @deprecated 4.2.2 + * addon commission 4.0.2 still use this function */ function learn_press_get_current_profile_tab( $default = true ) { global $wp_query, $wp; diff --git a/inc/templates/class-lp-template-profile.php b/inc/templates/class-lp-template-profile.php index dd4d7d4cc..2bc001b7a 100644 --- a/inc/templates/class-lp-template-profile.php +++ b/inc/templates/class-lp-template-profile.php @@ -227,9 +227,7 @@ public function dashboard_latest_courses() { public function order_details() { $profile = LP_Profile::instance(); - $order = $profile->get_view_order(); - if ( false === $order ) { return; } @@ -260,13 +258,13 @@ public function order_message() { } public function dashboard_not_logged_in() { - $profile = LP_Global::profile(); - + $profile = LP_Profile::instance(); if ( ! $profile->get_user()->is_guest() ) { return; } - if ( 'yes' === LP_Settings::instance()->get( 'enable_login_profile' ) || 'yes' === LP_Settings::instance()->get( 'enable_register_profile' ) ) { + if ( 'yes' === LP_Settings::get_option( 'enable_login_profile' ) + || 'yes' === LP_Settings::get_option( 'enable_register_profile' ) ) { return; } @@ -274,13 +272,12 @@ public function dashboard_not_logged_in() { } public function login_form() { - $profile = LP_Global::profile(); - + $profile = LP_Profile::instance(); if ( ! $profile->get_user()->is_guest() ) { return; } - if ( 'yes' !== LP_Settings::instance()->get( 'enable_login_profile' ) ) { + if ( 'yes' !== LP_Settings::get_option( 'enable_login_profile', 'no' ) ) { return; } @@ -288,13 +285,12 @@ public function login_form() { } public function register_form() { - $profile = LP_Global::profile(); - + $profile = LP_Profile::instance(); if ( ! $profile->get_user()->is_guest() ) { return; } - if ( 'yes' !== LP_Settings::instance()->get( 'enable_register_profile' ) || ! get_option( 'users_can_register' ) ) { + if ( 'yes' !== LP_Settings::get_option( 'enable_register_profile' ) || ! get_option( 'users_can_register' ) ) { return; } @@ -303,8 +299,13 @@ public function register_form() { /** * @return bool|LP_User|mixed + * @deprecated 4.2.6.4 */ protected function get_user() { + _deprecated_function( __METHOD__, '4.2.6.4' ); + + return false; + return LP_Profile::instance()->get_user(); } } diff --git a/inc/user/class-lp-profile.php b/inc/user/class-lp-profile.php index 50ea0531c..301f4d899 100644 --- a/inc/user/class-lp-profile.php +++ b/inc/user/class-lp-profile.php @@ -1,5 +1,6 @@ get_user(); @@ -216,6 +218,7 @@ public function get_user_data( $field ) { */ public function tab_dashboard() { _deprecated_function( __METHOD__, '4.2.6.2' ); + return; learn_press_get_template( 'profile/dashboard.php', array( 'user' => $this->_user ) ); } @@ -224,6 +227,17 @@ public function get_login_url( $redirect = false ) { return learn_press_get_login_url( $redirect !== false ? $redirect : LP_Helper::getUrlCurrent() ); } + /** + * Get tabs. + * + * @return array + * @since 4.2.6.4 + * @version 1.0.0 + */ + public static function get_tabs_arr(): array { + return Config::instance()->get( 'profile-tabs' ); + } + /** * Get default tabs for profile. * Hide tabs if user is not Administrator/Instructor. @@ -232,105 +246,17 @@ public function get_login_url( $redirect = false ) { */ public function get_tabs() { $user_of_profile = $this->get_user(); - $settings = LP_Settings::instance(); - - $this->_default_settings = array( - 'courses' => array( - 'title' => esc_html__( 'Courses', 'learnpress' ), - 'slug' => $settings->get( 'profile_endpoints.courses', 'courses' ), - 'callback' => array( LP_Template_Profile::class, 'tab_courses' ), - 'priority' => 1, - 'icon' => '', - ), - 'my-courses' => array( - 'title' => esc_html__( 'My Courses', 'learnpress' ), - 'slug' => $settings->get( 'profile_endpoints.my-courses', 'my-courses' ), - 'callback' => array( LP_Template_Profile::class, 'tab_my_courses' ), - 'priority' => 1, - 'icon' => '', - ), - 'quizzes' => array( - 'title' => esc_html__( 'Quizzes', 'learnpress' ), - 'slug' => $settings->get( 'profile_endpoints.quizzes', 'quizzes' ), - 'callback' => array( $this, 'tab_quizzes' ), - 'priority' => 20, - 'icon' => '', - ), - 'orders' => array( - 'title' => esc_html__( 'Orders', 'learnpress' ), - 'slug' => $settings->get( 'profile_endpoints.orders', 'orders' ), - 'callback' => array( ProfileOrdersTemplate::class, 'tab_content' ), - 'priority' => 25, - 'icon' => '', - ), - 'order-details' => array( - 'title' => esc_html__( 'Order details', 'learnpress' ), - 'slug' => $settings->get( 'profile_endpoints.order-details', 'order-details' ), - 'hidden' => true, - 'callback' => array( $this, 'tab_order_details' ), - 'priority' => 30, - ), - 'settings' => array( - 'title' => esc_html__( 'Settings', 'learnpress' ), - 'slug' => $settings->get( 'profile_endpoints.settings', 'settings' ), - 'callback' => array( $this, 'tab_settings' ), - 'sections' => array( - 'basic-information' => array( - 'title' => esc_html__( 'General', 'learnpress' ), - 'slug' => $settings->get( 'profile_endpoints.settings-basic-information', 'basic-information' ), - 'callback' => array( $this, 'tab_order_details' ), - 'priority' => 10, - 'icon' => '', - ), - 'avatar' => array( - 'title' => esc_html__( 'Avatar', 'learnpress' ), - 'callback' => array( $this, 'tab_order_details' ), - 'slug' => $settings->get( 'profile_endpoints.settings-avatar', 'avatar' ), - 'priority' => 20, - 'icon' => '', - ), - 'change-password' => array( - 'title' => esc_html__( 'Password', 'learnpress' ), - 'slug' => $settings->get( 'profile_endpoints.settings-change-password', 'change-password' ), - 'callback' => array( $this, 'tab_order_details' ), - 'priority' => 30, - 'icon' => '', - ), - ), - 'priority' => 90, - 'icon' => '', - ), - 'logout' => array( - 'title' => esc_html__( 'Logout', 'learnpress' ), - 'slug' => learn_press_profile_logout_slug(), - 'icon' => '', - 'priority' => 100, - ), - ); + $tabs = self::get_tabs_arr(); /* * Check if user not Admin/Instructor, will be hide tab Courses. - * And not call from function add_rewrite_rules. - * And not set option publish profile to yes. */ - $method_called_to = debug_backtrace()[1]['function']; - if ( $user_of_profile instanceof LP_User && 'add_rewrite_rules_profile' !== $method_called_to - && ! in_array( $user_of_profile->get_data( 'role' ), [ ADMIN_ROLE, LP_TEACHER_ROLE ] ) ) { - unset( $this->_default_settings['courses'] ); - } - - if ( 'yes' === self::get_option_publish_profile() ) { - $this->_default_settings['settings']['sections']['privacy'] = array( - 'title' => esc_html__( 'Privacy', 'learnpress' ), - 'slug' => $settings->get( 'profile_endpoints.settings-privacy', 'privacy' ), - 'priority' => 40, - 'callback' => array( $this, 'tab_order_details' ), - 'icon' => '', - ); + if ( $user_of_profile instanceof LP_User + && ! in_array( $user_of_profile->get_data( 'role' ), [ ADMIN_ROLE, LP_TEACHER_ROLE ] ) ) { + unset( $tabs['courses'] ); } - $tabs = $this->_default_settings; - $tabs = apply_filters( 'learn-press/profile-tabs', $tabs ); + $tabs = apply_filters( 'learn-press/get-profile-tabs', $tabs ); $this->_tabs = new LP_Profile_Tabs( $tabs, $this ); return $this->_tabs; @@ -452,7 +378,9 @@ public function is_hidden( $tab_or_section ) { */ public function is_public() { _deprecated_function( __METHOD__, '4.2.6.2' ); + return false; + return $this->current_user_can( 'view-tab-dashboard' ) || is_super_admin(); } @@ -1075,20 +1003,16 @@ public function get_statistic_info(): array { * * @return LP_Profile mixed * @since 3.0.0 - * @version 1.0.3 + * @version 1.0.4 */ public static function instance( $user_id = 0 ) { - $is_page_profile = LP_Page_Controller::page_is( 'profile'); + $is_page_profile = LP_Page_Controller::page_is( 'profile' ); if ( $is_page_profile ) { - if ( 'add_rewrite_rules_profile' === debug_backtrace()[2]['function'] ) { - return new self( 0 ); - } - if ( empty( self::$_instance ) ) { $user_name = get_query_var( 'user' ); if ( ! empty( $user_name ) ) { - $user = get_user_by( 'login', urldecode( $user_name ) ); + $user = get_user_by( 'login', urldecode( $user_name ) ); $user_id = $user ? $user->ID : 0; } else { $user_id = get_current_user_id(); diff --git a/inc/user/lp-user-functions.php b/inc/user/lp-user-functions.php index 07aa0741a..ac851be64 100644 --- a/inc/user/lp-user-functions.php +++ b/inc/user/lp-user-functions.php @@ -913,7 +913,13 @@ function learn_press_profile_tab_edit_content( $current, $tab, $user ) { ); } +/** + * @deprecated 4.2.6.4 + */ function learn_press_get_profile_endpoints() { + _deprecated_function( __FUNCTION__, '4.2.6.4' ); + return []; + $endpoints = (array) LP_Settings::instance()->get( 'profile_endpoints' ); $tabs = LP_Profile::instance()->get_tabs(); if ( $tabs ) { diff --git a/templates/checkout/order-received.php b/templates/checkout/order-received.php index 0603cfc1f..bebcfc1e4 100644 --- a/templates/checkout/order-received.php +++ b/templates/checkout/order-received.php @@ -6,7 +6,7 @@ * * @author ThimPress * @package Learnpress/Templates - * @version 4.0.2 + * @version 4.0.3 */ defined( 'ABSPATH' ) || exit(); @@ -62,7 +62,7 @@ get_status(); - echo ucfirst( wp_kses_post( $status ) ); + echo ucfirst( $order_received::get_status_label( $status ) ); ?> diff --git a/templates/order/order-details.php b/templates/order/order-details.php index 9efb4b120..0eb6ec11e 100644 --- a/templates/order/order-details.php +++ b/templates/order/order-details.php @@ -11,6 +11,9 @@ defined( 'ABSPATH' ) || exit(); +/** + * @var LP_Order $order + */ if ( ! isset( $order ) ) { echo esc_html__( 'Invalid order', 'learnpress' ); return; diff --git a/templates/profile/tabs/order-details.php b/templates/profile/tabs/order-details.php index 0d340ba62..94643cfbf 100644 --- a/templates/profile/tabs/order-details.php +++ b/templates/profile/tabs/order-details.php @@ -7,7 +7,9 @@ * @author ThimPress * @package Learnpress/Templates * @version 3.0.0 + * @deprecated 4.2.6.4 */ +return; /** * Prevent loading this file directly diff --git a/templates/profile/tabs/orders/order-message.php b/templates/profile/tabs/orders/order-message.php index f3116db14..04781a423 100644 --- a/templates/profile/tabs/orders/order-message.php +++ b/templates/profile/tabs/orders/order-message.php @@ -3,7 +3,9 @@ * @author ThimPress * @package LearnPress/Templates * @version 4.0.0 + * @deprecated 4.2.6.4 */ +return; defined( 'ABSPATH' ) || exit();