Skip to content

Commit

Permalink
= 4.2.6.4 =
Browse files Browse the repository at this point in the history
~ Added: ProfileOrderTemplate class.
~ Added: get_tabs_arr method on LP_Profile class.
~ Deprecated: learn_press_get_profile_endpoints function.
~ Security: check permission view order detail on Profile.
  • Loading branch information
tungnxt89 committed Mar 6, 2024
1 parent 5284f0c commit d6d380c
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 133 deletions.
97 changes: 97 additions & 0 deletions config/profile-tabs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* Profile tabs
*
* @since 4.2.6.4
* @version 1.0.0
*/

use LearnPress\TemplateHooks\Profile\ProfileOrdersTemplate;
use LearnPress\TemplateHooks\Profile\ProfileOrderTemplate;

$settings = LP_Settings::instance();
$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' => '<i class="fas fa-book-open"></i>',
),
'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' => '<i class="fas fa-bars"></i>',
),
'quizzes' => array(
'title' => esc_html__( 'Quizzes', 'learnpress' ),
'slug' => $settings->get( 'profile_endpoints.quizzes', 'quizzes' ),
'callback' => false,
'priority' => 20,
'icon' => '<i class="fas fa-puzzle-piece"></i>',
),
'orders' => array(
'title' => esc_html__( 'Orders', 'learnpress' ),
'slug' => $settings->get( 'profile_endpoints.orders', 'orders' ),
'callback' => [ ProfileOrdersTemplate::class, 'tab_content' ],
'priority' => 25,
'icon' => '<i class="fas fa-shopping-cart"></i>',
),
'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' => '<i class="fas fa-home"></i>',
),
'avatar' => array(
'title' => esc_html__( 'Avatar', 'learnpress' ),
'callback' => false,
'slug' => $settings->get( 'profile_endpoints.settings-avatar', 'avatar' ),
'priority' => 20,
'icon' => '<i class="fas fa-user-circle"></i>',
),
'change-password' => array(
'title' => esc_html__( 'Password', 'learnpress' ),
'slug' => $settings->get( 'profile_endpoints.settings-change-password', 'change-password' ),
'callback' => false,
'priority' => 30,
'icon' => '<i class="fas fa-key"></i>',
),
),
'priority' => 90,
'icon' => '<i class="fas fa-cog"></i>',
),
'logout' => array(
'title' => esc_html__( 'Logout', 'learnpress' ),
'slug' => learn_press_profile_logout_slug(),
'icon' => '<i class="fas fa-sign-out-alt"></i>',
'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' => '<i class="fas fa-user-secret"></i>',
);
}

return apply_filters( 'learn-press/profile-tabs', $default_settings );
9 changes: 4 additions & 5 deletions inc/ExternalPlugin/Polylang/class-lp-polylang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]*)?$" =>
Expand Down
2 changes: 1 addition & 1 deletion inc/Shortcodes/class-lp-shortcode-profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
55 changes: 55 additions & 0 deletions inc/TemplateHooks/Profile/ProfileOrderTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Class ProfileOrdersTemplate.
*
* @since 4.2.6.4
* @version 1.0.0
*/
namespace LearnPress\TemplateHooks\Profile;

use LP_Profile;

class ProfileOrderTemplate {
public static function instance() {
static $instance = null;

if ( is_null( $instance ) ) {
$instance = new self();
}

return $instance;
}

public static function content() {
do_action( 'learn-press/profile/layout/order-detail' );
}

protected function __construct() {
add_action( 'learn-press/profile/layout/order-detail', [ $this, 'sections' ] );
}

public static function init() {
self::instance();
}

public function sections() {
$profile = LP_Profile::instance();
$order = $profile->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' ) );
}
}
2 changes: 1 addition & 1 deletion inc/admin/class-lp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 9 additions & 13 deletions inc/class-lp-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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]*)?$" =>
Expand Down Expand Up @@ -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 ) ) {
Expand Down
1 change: 1 addition & 0 deletions inc/lp-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 12 additions & 11 deletions inc/templates/class-lp-template-profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -260,41 +258,39 @@ 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;
}

learn_press_get_template( 'profile/not-logged-in.php' );
}

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;
}

learn_press_get_template( 'global/form-login.php' );
}

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;
}

Expand All @@ -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();
}
}
Expand Down
Loading

0 comments on commit d6d380c

Please sign in to comment.