From ceb2d38988e99ac62f70bf406d2551983015a812 Mon Sep 17 00:00:00 2001 From: nikitasinelnikov Date: Fri, 19 Jul 2019 15:41:10 +0300 Subject: [PATCH] - profile tabs changes; --- includes/admin/core/class-admin-settings.php | 2 +- includes/class-config.php | 6 + includes/core/class-profile.php | 66 +++++- includes/core/class-user.php | 1 - includes/core/um-actions-profile.php | 234 +++++++++---------- templates/profile.php | 104 +++++---- 6 files changed, 235 insertions(+), 178 deletions(-) diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 59009ddf..d6f6540b 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -137,7 +137,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { foreach ( $tabs as $id => $tab ) { - if ( isset( $tab['hidden'] ) ) { + if ( ! empty( $tab['hidden'] ) ) { continue; } diff --git a/includes/class-config.php b/includes/class-config.php index 7ff7c442..5059c977 100644 --- a/includes/class-config.php +++ b/includes/class-config.php @@ -546,7 +546,13 @@ if ( ! class_exists( 'um\Config' ) ) { add_filter( 'um_get_tabs_from_config', '__return_true' ); $tabs = UM()->profile()->tabs(); + foreach ( $tabs as $id => $tab ) { + + if ( ! empty( $tab['hidden'] ) ) { + continue; + } + $this->settings_defaults[ 'profile_tab_' . $id ] = 1; if ( ! isset( $tab['default_privacy'] ) ) { diff --git a/includes/core/class-profile.php b/includes/core/class-profile.php index ffe92c6d..29fe99d9 100644 --- a/includes/core/class-profile.php +++ b/includes/core/class-profile.php @@ -242,6 +242,31 @@ if ( ! class_exists( 'um\core\Profile' ) ) { } } + if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { + /** + * UM hook + * + * @type filter + * @title um_user_profile_tabs + * @description Extend profile tabs + * @input_vars + * [{"var":"$tabs","type":"array","desc":"Profile Tabs"}] + * @change_log + * ["Since: 2.0"] + * @usage + * + * @example + * + */ + $tabs = apply_filters( 'um_user_profile_tabs', $tabs ); + } + return $tabs; } @@ -253,10 +278,45 @@ if ( ! class_exists( 'um\core\Profile' ) ) { */ function active_tab() { - $this->active_tab = UM()->options()->get('profile_menu_default_tab'); + // get active tabs + $tabs = UM()->profile()->tabs_active(); - if ( get_query_var('profiletab') ) { - $this->active_tab = get_query_var('profiletab'); + if ( ! UM()->options()->get( 'profile_menu' ) ) { + + $query_arg = get_query_var( 'profiletab' ); + if ( ! empty( $query_arg ) && ! empty( $tabs[ $query_arg ]['hidden'] ) ) { + $this->active_tab = $query_arg; + } else { + if ( ! empty( $tabs ) ) { + foreach ( $tabs as $k => $tab ) { + if ( ! empty( $tab['hidden'] ) ) { + $this->active_tab = $k; + break; + } + } + } + } + + } else { + $query_arg = get_query_var( 'profiletab' ); + if ( ! empty( $query_arg ) && ! empty( $tabs[ $query_arg ] ) ) { + $this->active_tab = $query_arg; + } else { + $default_tab = UM()->options()->get( 'profile_menu_default_tab' ); + + if ( ! empty( $tabs[ $default_tab ] ) ) { + $this->active_tab = $default_tab; + } else { + if ( ! empty( $tabs ) ) { + foreach ( $tabs as $k => $tab ) { + if ( ! empty( $tab['hidden'] ) ) { + $this->active_tab = $k; + break; + } + } + } + } + } } /** diff --git a/includes/core/class-user.php b/includes/core/class-user.php index bc4c52c2..f073b562 100644 --- a/includes/core/class-user.php +++ b/includes/core/class-user.php @@ -25,7 +25,6 @@ if ( ! class_exists( 'um\core\User' ) ) { $this->data = null; $this->profile = null; $this->cannot_edit = null; - $this->tabs = null; $this->banned_keys = array( 'metabox','postbox','meta-box', diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index 592150ba..cb3336fd 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -1320,160 +1320,144 @@ function um_profile_menu( $args ) { // get active tabs $tabs = UM()->profile()->tabs_active(); - /** - * UM hook - * - * @type filter - * @title um_user_profile_tabs - * @description Extend profile tabs - * @input_vars - * [{"var":"$tabs","type":"array","desc":"Profile Tabs"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $tabs = apply_filters( 'um_user_profile_tabs', $tabs ); + $all_tabs = $tabs; - UM()->user()->tabs = $tabs; - - // need enough tabs to continue - if ( count( $tabs ) <= 1 ) { - return; - } - - $active_tab = UM()->profile()->active_tab(); - - if ( ! isset( $tabs[ $active_tab ] ) ) { - $active_tab = 'main'; - UM()->profile()->active_tab = $active_tab; - UM()->profile()->active_subnav = null; - } - - // Move default tab priority - $default_tab = UM()->options()->get( 'profile_menu_default_tab' ); - $dtab = ( isset( $tabs[ $default_tab ] ) ) ? $tabs[ $default_tab ] : 'main'; - if ( isset( $tabs[ $default_tab ] ) ) { - unset( $tabs[ $default_tab ] ); - $dtabs[ $default_tab ] = $dtab; - $tabs = $dtabs + $tabs; - } - - $tabs_in_nav = array_filter( $tabs, function( $item ) { + $tabs = array_filter( $tabs, function( $item ) { if ( ! empty( $item['hidden'] ) ) { return false; } return true; }); - if ( ! empty( $tabs_in_nav ) ) { ?> + $active_tab = UM()->profile()->active_tab(); + //check here tabs with hidden also, to make correct check of active tab + if ( ! isset( $all_tabs[ $active_tab ] ) ) { + $active_tab = 'main'; + UM()->profile()->active_tab = $active_tab; + UM()->profile()->active_subnav = null; + } -
+ $has_subnav = false; + if ( count( $tabs ) == 1 ) { + foreach ( $tabs as $tab ) { + if ( isset( $tab['subnav'] ) ) { + $has_subnav = true; + } + } + } - $tab ) { + // need enough tabs to continue + if ( count( $tabs ) <= 1 && ! $has_subnav && count( $all_tabs ) === count( $tabs ) ) { + return; + } - if ( isset( $tab['hidden'] ) ) { - continue; - } + if ( count( $tabs ) > 1 || count( $all_tabs ) > count( $tabs ) ) { + // Move default tab priority + $default_tab = UM()->options()->get( 'profile_menu_default_tab' ); + $dtab = ( isset( $tabs[ $default_tab ] ) ) ? $tabs[ $default_tab ] : 'main'; + if ( isset( $tabs[ $default_tab ] ) ) { + unset( $tabs[ $default_tab ] ); + $dtabs[ $default_tab ] = $dtab; + $tabs = $dtabs + $tabs; + } - $nav_link = UM()->permalinks()->get_current_url( get_option( 'permalink_structure' ) ); - $nav_link = remove_query_arg( 'um_action', $nav_link ); - $nav_link = remove_query_arg( 'subnav', $nav_link ); - $nav_link = add_query_arg( 'profiletab', $id, $nav_link ); + if ( ! empty( $tabs ) ) { ?> - /** - * UM hook - * - * @type filter - * @title um_profile_menu_link_{$id} - * @description Change profile menu link by tab $id - * @input_vars - * [{"var":"$nav_link","type":"string","desc":"Profile Tab Link"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * - */ - $nav_link = apply_filters( "um_profile_menu_link_{$id}", $nav_link ); +
- $profile_nav_class = ''; - if ( ! UM()->options()->get( 'profile_menu_icons' ) ) { - $profile_nav_class .= ' without-icon'; - } + $tab ) { - if ( $id == $active_tab ) { - $profile_nav_class .= ' active'; - } ?> + $nav_link = UM()->permalinks()->get_current_url( get_option( 'permalink_structure' ) ); + $nav_link = remove_query_arg( 'um_action', $nav_link ); + $nav_link = remove_query_arg( 'subnav', $nav_link ); + $nav_link = add_query_arg( 'profiletab', $id, $nav_link ); - + + + +
- + +
+ +
+ + $tab ) { diff --git a/templates/profile.php b/templates/profile.php index 2ef11bc4..8bffd8f0 100644 --- a/templates/profile.php +++ b/templates/profile.php @@ -142,59 +142,67 @@ */ do_action( 'um_profile_menu', $args ); - $nav = UM()->profile()->active_tab; - $subnav = ( get_query_var('subnav') ) ? get_query_var('subnav') : 'default'; ?> + $menu_enabled = UM()->options()->get( 'profile_menu' ); + $tabs = UM()->profile()->tabs_active(); -
+ $nav = UM()->profile()->active_tab(); + $subnav = UM()->profile()->active_subnav(); + $subnav = ! empty( $subnav ) ? $subnav : 'default'; - - */ - do_action("um_profile_content_{$nav}", $args); + if ( $menu_enabled || ! empty( $tabs[ $nav ]['hidden'] ) ) { ?> - /** - * UM hook - * - * @type action - * @title um_profile_content_{$nav}_{$subnav} - * @description Custom hook to display tabbed content - * @input_vars - * [{"var":"$args","type":"array","desc":"Profile form shortcode arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_profile_content_{$nav}_{$subnav}', 'function_name', 10, 1 ); - * @example - * - */ - do_action( "um_profile_content_{$nav}_{$subnav}", $args ); ?> +
-
-
+ + */ + do_action("um_profile_content_{$nav}", $args); - + /** + * UM hook + * + * @type action + * @title um_profile_content_{$nav}_{$subnav} + * @description Custom hook to display tabbed content + * @input_vars + * [{"var":"$args","type":"array","desc":"Profile form shortcode arguments"}] + * @change_log + * ["Since: 2.0"] + * @usage add_action( 'um_profile_content_{$nav}_{$subnav}', 'function_name', 10, 1 ); + * @example + * + */ + do_action( "um_profile_content_{$nav}_{$subnav}", $args ); ?> + +
+
+ +