From 9015b6c34df0b2b738ed775d8def1da438769932 Mon Sep 17 00:00:00 2001 From: nikitasinelnikov Date: Fri, 5 Jul 2019 16:08:09 +0300 Subject: [PATCH] - profile tabs privacy; - fixed issue with added wpautop for UM pages; (remove wpautop) --- includes/admin/core/class-admin-settings.php | 16 +++- includes/class-config.php | 12 +-- includes/core/class-profile.php | 96 +++++++++----------- includes/core/class-shortcodes.php | 2 - 4 files changed, 62 insertions(+), 64 deletions(-) diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index a9897792..924532e6 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -137,6 +137,10 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { foreach ( $tabs as $id => $tab ) { + if ( isset( $tab['hidden'] ) ) { + continue; + } + if ( isset( $tab['default_privacy'] ) ) { $fields = array( array( @@ -181,13 +185,23 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { $appearances_profile_menu_fields = array_merge( $appearances_profile_menu_fields, $fields ); } + $active_tabs = array(); + $tabs = UM()->profile()->tabs_active(); + if ( ! empty( $tabs ) ) { + foreach ( $tabs as $id => $info ) { + if ( isset( $info['name'] ) ) { + $active_tabs[ $id ] = $info['name']; + } + } + } + $appearances_profile_menu_fields = array_merge( $appearances_profile_menu_fields, array( array( 'id' => 'profile_menu_default_tab', 'type' => 'select', 'label' => __( 'Profile menu default tab', 'ultimate-member' ), 'tooltip' => __( 'This will be the default tab on user profile page', 'ultimate-member' ), - 'options' => UM()->profile()->tabs_enabled(), + 'options' => $active_tabs, 'conditional' => array( 'profile_menu', '=', 1 ), 'size' => 'small' ), diff --git a/includes/class-config.php b/includes/class-config.php index b0389db7..24190728 100644 --- a/includes/class-config.php +++ b/includes/class-config.php @@ -545,18 +545,18 @@ if ( ! class_exists( 'um\Config' ) ) { $tabs = UM()->profile()->tabs(); foreach ( $tabs as $id => $tab ) { - $this->settings_defaults['profile_tab_' . $id] = 1; + $this->settings_defaults[ 'profile_tab_' . $id ] = 1; if ( ! isset( $tab['default_privacy'] ) ) { - $this->settings_defaults['profile_tab_' . $id . '_privacy'] = 0; - $this->settings_defaults['profile_tab_' . $id . '_roles'] = ''; + $this->settings_defaults[ 'profile_tab_' . $id . '_privacy' ] = 0; + $this->settings_defaults[ 'profile_tab_' . $id . '_roles' ] = ''; } } foreach ( $this->email_notifications as $key => $notification ) { - $this->settings_defaults[$key . '_on'] = ! empty( $notification['default_active'] ); - $this->settings_defaults[$key . '_sub'] = $notification['subject']; - $this->settings_defaults[$key] = $notification['body']; + $this->settings_defaults[ $key . '_on' ] = ! empty( $notification['default_active'] ); + $this->settings_defaults[ $key . '_sub' ] = $notification['subject']; + $this->settings_defaults[ $key ] = $notification['body']; } foreach ( $this->core_pages as $page_s => $page ) { diff --git a/includes/core/class-profile.php b/includes/core/class-profile.php index eb5e6540..ffe92c6d 100644 --- a/includes/core/class-profile.php +++ b/includes/core/class-profile.php @@ -77,6 +77,24 @@ if ( ! class_exists( 'um\core\Profile' ) ) { } + /** + * Pre-defined privacy options + * + * @return array + */ + function tabs_privacy() { + $privacy = array( + 0 => __( 'Anyone', 'ultimate-member' ), + 1 => __( 'Guests only', 'ultimate-member' ), + 2 => __( 'Members only', 'ultimate-member' ), + 3 => __( 'Only the owner', 'ultimate-member' ), + 4 => __( 'Specific roles', 'ultimate-member' ), + ); + + return $privacy; + } + + /** * All tab data * @@ -123,7 +141,7 @@ if ( ! class_exists( 'um\core\Profile' ) ) { // disable private tabs if ( ! is_admin() ) { if ( is_user_logged_in() ) { - $user_id = um_user('ID'); + $user_id = um_user( 'ID' ); um_fetch_user( get_current_user_id() ); } @@ -142,60 +160,6 @@ if ( ! class_exists( 'um\core\Profile' ) ) { } - /** - * Tabs that are active - * - * @return array - */ - function tabs_active() { - $tabs = $this->tabs(); - - foreach ( $tabs as $id => $info ) { - if ( ! UM()->options()->get( 'profile_tab_' . $id ) ) { - unset( $tabs[ $id ] ); - } - } - - return $tabs; - } - - - /** - * Activated tabs in backend - * - * @return string - */ - function tabs_enabled() { - $tabs = $this->tabs_active(); - - foreach ( $tabs as $id => $info ) { - if ( isset( $info['name'] ) ) { - $primary[ $id ] = $info['name']; - } - } - - return isset( $primary ) ? $primary : ''; - } - - - /** - * Privacy options - * - * @return array - */ - function tabs_privacy() { - $privacy = array( - 0 => __( 'Anyone', 'ultimate-member' ), - 1 => __( 'Guests only', 'ultimate-member' ), - 2 => __( 'Members only', 'ultimate-member' ), - 3 => __( 'Only the owner', 'ultimate-member' ), - 4 => __( 'Specific roles', 'ultimate-member' ), - ); - - return $privacy; - } - - /** * Check if the user can view the current tab * @@ -260,6 +224,28 @@ if ( ! class_exists( 'um\core\Profile' ) ) { } + /** + * Tabs that are active + * + * @return array + */ + function tabs_active() { + $tabs = $this->tabs(); + + foreach ( $tabs as $id => $info ) { + if ( ! empty( $info['hidden'] ) ) { + continue; + } + + if ( ! UM()->options()->get( 'profile_tab_' . $id ) ) { + unset( $tabs[ $id ] ); + } + } + + return $tabs; + } + + /** * Get active_tab * diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index 1ba5b897..3c619d93 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -36,9 +36,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { add_shortcode( 'um_show_content', array( &$this, 'um_shortcode_show_content_for_role' ) ); add_shortcode( 'ultimatemember_searchform', array( &$this, 'ultimatemember_searchform' ) ); - add_filter( 'body_class', array( &$this, 'body_class' ), 0 ); - add_action( 'template_redirect', array( &$this, 'is_um_page' ) ); add_filter( 'um_shortcode_args_filter', array( &$this, 'display_logout_form' ), 99 ); add_filter( 'um_shortcode_args_filter', array( &$this, 'parse_shortcode_args' ), 99 );