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