Privacy options for profile menu tabs

This commit is contained in:
jonfalcon
2016-03-15 16:29:43 -07:00
parent d38c9b1caa
commit ba5aa3b625
2 changed files with 113 additions and 22 deletions
+89 -22
View File
@@ -3,19 +3,30 @@
class UM_Profile {
function __construct() {
add_action('template_redirect', array(&$this, 'active_tab'), 10002);
add_action('template_redirect', array(&$this, 'active_subnav'), 10002);
}
/***
*** @all tab data
***/
function tabs(){
return apply_filters('um_profile_tabs', $tabs = array() );
$tabs = apply_filters('um_profile_tabs', $tabs = array() );
// disable private tabs
if( !is_admin() ) {
foreach( $tabs as $id => $tab ) {
if( !$this->can_view_tab( $id ) ) {
unset( $tabs[$id] );
}
}
}
return $tabs;
}
/***
*** @tabs that are active
***/
@@ -27,7 +38,7 @@ class UM_Profile {
}
return $tabs;
}
/***
*** @primary tabs only
***/
@@ -40,7 +51,7 @@ class UM_Profile {
}
return $primary;
}
/***
*** @Activated tabs in backend
***/
@@ -55,7 +66,63 @@ class UM_Profile {
}
return ( isset( $primary ) ) ? $primary : '';
}
/***
*** @Privacy options
***/
function tabs_privacy() {
$privacy = array(
0 => 'Anyone',
1 => 'Guests only',
2 => 'Members only',
3 => 'Only the owner',
4 => 'Specific roles'
);
return $privacy;
}
/***
*** @Check if the user can view the current tab
***/
function can_view_tab( $tab ) {
global $ultimatemember;
$privacy = intval( um_get_option( 'profile_tab_' . $tab . '_privacy' ) );
$can_view = false;
switch( $privacy ) {
case 1:
$can_view = is_user_logged_in() ? false : true;
break;
case 2:
$can_view = is_user_logged_in() ? true : false;
break;
case 3:
$can_view = get_current_user_id() == um_user( 'ID' ) ? true : false;
break;
case 4:
$can_view = false;
if( is_user_logged_in() ) {
$roles = um_get_option( 'profile_tab_' . $tab . '_roles' );
if( is_array( $roles )
&& in_array( $ultimatemember->user->get_role(), $roles ) ) {
$can_view = true;
}
}
break;
default:
$can_view = true;
break;
}
return $can_view;
}
/***
*** @Get active_tab
***/
@@ -66,53 +133,53 @@ class UM_Profile {
if ( get_query_var('profiletab') ) {
$this->active_tab = get_query_var('profiletab');
}
$this->active_tab = apply_filters( 'um_profile_active_tab', $this->active_tab );
return $this->active_tab;
}
/***
*** @Get active active_subnav
***/
function active_subnav() {
$this->active_subnav = null;
if ( get_query_var('subnav') ) {
$this->active_subnav = get_query_var('subnav');
}
return $this->active_subnav;
}
/***
*** @Show meta in profile
***/
function show_meta( $array ) {
global $ultimatemember;
$output = '';
foreach( $array as $key ) {
$data = '';
if ( $key && um_filtered_value( $key ) ) {
if ( isset( $ultimatemember->builtin->all_user_fields[$key]['icon'] ) ) {
$icon = $ultimatemember->builtin->all_user_fields[$key]['icon'];
} else {
$icon = '';
}
$icon = ( isset( $icon ) && !empty( $icon ) ) ? '<i class="'.$icon.'"></i>' : '';
if ( !um_get_option('profile_show_metaicon') )
$icon = '';
$value = um_filtered_value( $key );
$items[] = '<span>' . $icon . $value . '</span>';
$items[] = '<span class="b">&bull;</span>';
}
}
@@ -126,4 +193,4 @@ class UM_Profile {
return $output;
}
}
}
+24
View File
@@ -1594,6 +1594,30 @@ foreach( $tabs as $id => $tab ) {
'off' => __('Off','ultimatemember'),
);
$tab_options[] = array(
'id' => 'profile_tab_' . $id . '_privacy',
'type' => 'select',
'select2' => array( 'allowClear' => 0, 'minimumResultsForSearch' => -1 ),
'title' => sprintf( __( 'Who can see %s Tab?','ultimatemember' ), $tab ),
'desc' => __( 'Select which users can view this tab.','ultimatemember' ),
'default' => 0,
'options' => $ultimatemember->profile->tabs_privacy(),
'required' => array( 'profile_tab_' . $id, '=', 1 ),
);
$tab_options[] = array(
'id' => 'profile_tab_' . $id . '_roles',
'type' => 'select',
'multi' => true,
'select2' => array( 'allowClear' => 1, 'minimumResultsForSearch' => -1 ),
'title' => __( 'Allowed roles','ultimatemember' ),
'desc' => __( 'Select the the user roles allowed to view this tab.','ultimatemember' ),
'default' => '',
'options' => $ultimatemember->query->get_roles(),
'placeholder' => __( 'Choose user roles...','ultimatemember' ),
'required' => array( 'profile_tab_' . $id . '_privacy', '=', 4 ),
);
}
$tab_options[] = array(