mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
- WP Native menu restriction settings;
This commit is contained in:
@@ -173,4 +173,14 @@ a.um-delete{ color: #a00; }
|
||||
|
||||
.um_tooltip:hover:before {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
|
||||
.wp-admin p.um-nav-roles label input[type=checkbox] {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
.wp-admin p.um-nav-roles label {
|
||||
margin-top: 2px !important;
|
||||
margin-bottom: 2px !important;
|
||||
}
|
||||
@@ -187,29 +187,33 @@ jQuery(document).ready(function() {
|
||||
|
||||
});jQuery('.um-conditional-radio-group input[type=radio]:checked').each(function(){jQuery(this).trigger('click');});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Conditional fields for
|
||||
nav-menu editor options
|
||||
**/
|
||||
|
||||
jQuery('.um-nav-mode').each(function(){
|
||||
|
||||
if ( jQuery(this).find('input[type=radio]:checked').val() ) {
|
||||
if ( jQuery(this).find('input[type=radio]:checked').val() == 2 ) {
|
||||
jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').show();
|
||||
} else {
|
||||
jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').hide();
|
||||
}
|
||||
}
|
||||
|
||||
jQuery('.um-nav-mode').each( function() {
|
||||
if ( jQuery(this).find('select').val() == 2 ) {
|
||||
jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').show();
|
||||
} else {
|
||||
jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').hide();
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '.um-nav-mode input[type=radio]', function(){
|
||||
if ( jQuery(this).val() == 2 ) {
|
||||
jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').show();
|
||||
} else {
|
||||
jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').hide();
|
||||
}
|
||||
|
||||
|
||||
jQuery(document).on('change', '.um-nav-mode select', function(){
|
||||
if ( jQuery(this).val() == 2 ) {
|
||||
jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').show();
|
||||
} else {
|
||||
jQuery(this).parents('.um-nav-edit').find('.um-nav-roles').hide();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
@@ -574,88 +574,84 @@ if ( ! class_exists( 'Admin_Metabox' ) ) {
|
||||
*** @add role metabox
|
||||
***/
|
||||
function add_metabox_role() {
|
||||
add_meta_box(
|
||||
'um-admin-form-admin',
|
||||
__( 'Administrative Permissions', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'normal',
|
||||
'default'
|
||||
$callback = array( &$this, 'load_metabox_role' );
|
||||
|
||||
$roles_metaboxes = array(
|
||||
array(
|
||||
'id' => 'um-admin-form-admin',
|
||||
'title' => __( 'Administrative Permissions', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'normal',
|
||||
'priority' => 'default'
|
||||
),
|
||||
array(
|
||||
'id' => 'um-admin-form-general',
|
||||
'title' => __( 'General Permissions', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'normal',
|
||||
'priority' => 'default'
|
||||
),
|
||||
array(
|
||||
'id' => 'um-admin-form-profile',
|
||||
'title' => __( 'Profile Access', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'normal',
|
||||
'priority' => 'default'
|
||||
),
|
||||
array(
|
||||
'id' => 'um-admin-form-home',
|
||||
'title' => __( 'Homepage Options', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'normal',
|
||||
'priority' => 'default'
|
||||
),
|
||||
array(
|
||||
'id' => 'um-admin-form-register',
|
||||
'title' => __( 'Registration Options', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'normal',
|
||||
'priority' => 'default'
|
||||
),
|
||||
array(
|
||||
'id' => 'um-admin-form-login',
|
||||
'title' => __( 'Login Options', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'normal',
|
||||
'priority' => 'default'
|
||||
),
|
||||
array(
|
||||
'id' => 'um-admin-form-logout',
|
||||
'title' => __( 'Logout Options', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'normal',
|
||||
'priority' => 'default'
|
||||
),
|
||||
array(
|
||||
'id' => 'um-admin-form-delete',
|
||||
'title' => __( 'Delete Options', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'normal',
|
||||
'priority' => 'default'
|
||||
),
|
||||
array(
|
||||
'id' => 'um-admin-form-publish',
|
||||
'title' => __( 'Publish', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'side',
|
||||
'priority' => 'default'
|
||||
)
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'um-admin-form-general',
|
||||
__( 'General Permissions', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'normal',
|
||||
'default'
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'um-admin-form-profile',
|
||||
__( 'Profile Access', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'normal',
|
||||
'default'
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'um-admin-form-home',
|
||||
__( 'Homepage Options', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'normal',
|
||||
'default'
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'um-admin-form-register',
|
||||
__( 'Registration Options', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'normal',
|
||||
'default'
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'um-admin-form-login',
|
||||
__( 'Login Options', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'normal',
|
||||
'default'
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'um-admin-form-logout',
|
||||
__( 'Logout Options', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'normal',
|
||||
'default'
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'um-admin-form-delete',
|
||||
__( 'Delete Options', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'normal',
|
||||
'default'
|
||||
);
|
||||
|
||||
add_meta_box(
|
||||
'um-admin-form-publish',
|
||||
__( 'Publish', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'side',
|
||||
'default'
|
||||
);
|
||||
|
||||
do_action( 'um_admin_custom_role_metaboxes' );
|
||||
$roles_metaboxes = apply_filters( 'um_admin_role_metaboxes', $roles_metaboxes );
|
||||
|
||||
$wp_caps_metabox = false;
|
||||
if ( ! empty( $_GET['id'] ) ) {
|
||||
@@ -663,15 +659,26 @@ if ( ! class_exists( 'Admin_Metabox' ) ) {
|
||||
if ( ! empty( $data['_um_is_custom'] ) )
|
||||
$wp_caps_metabox = true;
|
||||
}
|
||||
|
||||
if ( 'add' == $_GET['tab'] || $wp_caps_metabox ) {
|
||||
$roles_metaboxes[] = array(
|
||||
'id' => 'um-admin-form-wp-capabilities',
|
||||
'title' => __( 'WP Capabilities', 'ultimate-member' ),
|
||||
'callback' => $callback,
|
||||
'screen' => 'um_role_meta',
|
||||
'context' => 'normal',
|
||||
'priority' => 'default'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
foreach ( $roles_metaboxes as $metabox ) {
|
||||
add_meta_box(
|
||||
'um-admin-form-wp-capabilities',
|
||||
__( 'WP Capabilities', 'ultimate-member' ),
|
||||
array( &$this, 'load_metabox_role' ),
|
||||
'um_role_meta',
|
||||
'normal',
|
||||
'default'
|
||||
$metabox['id'],
|
||||
$metabox['title'],
|
||||
$metabox['callback'],
|
||||
$metabox['screen'],
|
||||
$metabox['context'],
|
||||
$metabox['priority']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
'type' => 'checkbox',
|
||||
'name' => '_um_custom_access_settings',
|
||||
'label' => __( 'Restrict access to this content?', 'ultimate-member' ),
|
||||
'description' => __( 'Activate content restriction for this post', 'ultimate-member' ),
|
||||
'tooltip' => __( 'Activate content restriction for this post', 'ultimate-member' ),
|
||||
'value' => ! empty( $data['_um_custom_access_settings'] ) ? $data['_um_custom_access_settings'] : 0,
|
||||
),
|
||||
array(
|
||||
@@ -32,7 +32,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
'type' => 'select',
|
||||
'name' => '_um_accessible',
|
||||
'label' => __( 'Who can access this content?', 'ultimate-member' ),
|
||||
'description' => __( 'Activate content restriction for this post', 'ultimate-member' ),
|
||||
'tooltip' => __( 'Activate content restriction for this post', 'ultimate-member' ),
|
||||
'value' => ! empty( $data['_um_accessible'] ) ? $data['_um_accessible'] : 0,
|
||||
'options' => array(
|
||||
'0' => __( 'Everyone', 'ultimate-member' ),
|
||||
@@ -46,7 +46,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
'type' => 'multi_checkbox',
|
||||
'name' => '_um_access_roles',
|
||||
'label' => __( 'Select which roles can access this content', 'ultimate-member' ),
|
||||
'description' => __( 'Activate content restriction for this post', 'ultimate-member' ),
|
||||
'tooltip' => __( 'Activate content restriction for this post', 'ultimate-member' ),
|
||||
'value' => $_um_access_roles_value,
|
||||
'options' => UM()->roles()->get_roles( false, array( 'administrator' ) ),
|
||||
'columns' => 3,
|
||||
@@ -57,7 +57,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
'type' => 'select',
|
||||
'name' => '_um_noaccess_action',
|
||||
'label' => __( 'What happens when users without access tries to view the content?', 'ultimate-member' ),
|
||||
'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ),
|
||||
'tooltip' => __( 'Action when users without access tries to view the content', 'ultimate-member' ),
|
||||
'value' => ! empty( $data['_um_noaccess_action'] ) ? $data['_um_noaccess_action'] : 0,
|
||||
'options' => array(
|
||||
'0' => __( 'Show access restricted message', 'ultimate-member' ),
|
||||
@@ -70,7 +70,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
'type' => 'select',
|
||||
'name' => '_um_restrict_by_custom_message',
|
||||
'label' => __( 'Would you like to use the global default message or apply a custom message to this content?', 'ultimate-member' ),
|
||||
'description' => __( 'Action when users without access tries to view the content', 'ultimate-member' ),
|
||||
'tooltip' => __( 'Action when users without access tries to view the content', 'ultimate-member' ),
|
||||
'value' => ! empty( $data['_um_restrict_by_custom_message'] ) ? $data['_um_restrict_by_custom_message'] : '0',
|
||||
'options' => array(
|
||||
'0' => __( 'Global default message (default)', 'ultimate-member' ),
|
||||
@@ -83,7 +83,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
'type' => 'wp_editor',
|
||||
'name' => '_um_restrict_custom_message',
|
||||
'label' => __( 'Custom Restrict Content message', 'ultimate-member' ),
|
||||
'description' => __( 'Changed global restrict message', 'ultimate-member' ),
|
||||
'tooltip' => __( 'Changed global restrict message', 'ultimate-member' ),
|
||||
'value' => ! empty( $data['_um_restrict_custom_message'] ) ? $data['_um_restrict_custom_message'] : '',
|
||||
'conditional' => array( '_um_restrict_by_custom_message', '=', '1' )
|
||||
),
|
||||
@@ -92,7 +92,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
'type' => 'select',
|
||||
'name' => '_um_access_redirect',
|
||||
'label' => __( 'Where should users be redirected to?', 'ultimate-member' ),
|
||||
'description' => __( 'Select redirect to page when user hasn\'t access to content', 'ultimate-member' ),
|
||||
'tooltip' => __( 'Select redirect to page when user hasn\'t access to content', 'ultimate-member' ),
|
||||
'value' => ! empty( $data['_um_access_redirect'] ) ? $data['_um_access_redirect'] : '0',
|
||||
'conditional' => array( '_um_noaccess_action', '=', '1' ),
|
||||
'options' => array(
|
||||
@@ -105,7 +105,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
'type' => 'text',
|
||||
'name' => '_um_access_redirect_url',
|
||||
'label' => __( 'Redirect URL', 'ultimate-member' ),
|
||||
'description' => __( 'Changed global restrict message', 'ultimate-member' ),
|
||||
'tooltip' => __( 'Changed global restrict message', 'ultimate-member' ),
|
||||
'value' => ! empty( $data['_um_access_redirect_url'] ) ? $data['_um_access_redirect_url'] : '',
|
||||
'conditional' => array( '_um_access_redirect', '=', '1' )
|
||||
),
|
||||
@@ -114,7 +114,7 @@ if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
'type' => 'checkbox',
|
||||
'name' => '_um_access_hide_from_queries',
|
||||
'label' => __( 'Hide from queries', 'ultimate-member' ),
|
||||
'description' => __( 'Hide this content from archives, RSS feeds etc for users who do not have permission to view this content', 'ultimate-member' ),
|
||||
'tooltip' => __( 'Hide this content from archives, RSS feeds etc for users who do not have permission to view this content', 'ultimate-member' ),
|
||||
'value' => ! empty( $data['_um_access_hide_from_queries'] ) ? $data['_um_access_hide_from_queries'] : '',
|
||||
'conditional' => array( '_um_accessible', '!=', '0' )
|
||||
)
|
||||
|
||||
@@ -26,30 +26,26 @@
|
||||
|
||||
$hide_children_of = array();
|
||||
|
||||
foreach($items as $key => $item){
|
||||
foreach( $items as $key => $item ) {
|
||||
|
||||
$mode = get_post_meta($item->ID, 'menu-item-um_nav_public', true);
|
||||
$roles = get_post_meta($item->ID, 'menu-item-um_nav_roles', true);
|
||||
$mode = get_post_meta( $item->ID, 'menu-item-um_nav_public', true );
|
||||
$roles = get_post_meta( $item->ID, 'menu-item-um_nav_roles', true );
|
||||
|
||||
$visible = true;
|
||||
|
||||
// hide any item that is the child of a hidden item
|
||||
if( in_array( $item->menu_item_parent, $hide_children_of ) ){
|
||||
if ( in_array( $item->menu_item_parent, $hide_children_of ) ) {
|
||||
$visible = false;
|
||||
$hide_children_of[] = $item->ID; // for nested menus
|
||||
}
|
||||
|
||||
if ( isset( $mode ) && $visible ){
|
||||
if ( isset( $mode ) && $visible ) {
|
||||
|
||||
switch( $mode ) {
|
||||
|
||||
case 2:
|
||||
if ( is_user_logged_in() && isset($roles) && !empty($roles)) {
|
||||
if ( in_array( um_user('role'), (array)$roles) ) {
|
||||
$visible = true;
|
||||
} else {
|
||||
$visible = false;
|
||||
}
|
||||
if ( is_user_logged_in() && ! empty( $roles ) ) {
|
||||
$visible = in_array( um_user('role'), (array)$roles ) ? true : false;
|
||||
} else {
|
||||
$visible = is_user_logged_in() ? true : false;
|
||||
}
|
||||
|
||||
@@ -73,59 +73,70 @@ class UM_Menu_Item_Custom_Fields_Editor {
|
||||
|
||||
<div class="clear"></div>
|
||||
|
||||
<div class="um-nav-edit-h2">UltimateMember Menu Settings</div>
|
||||
<div class="um-nav-edit-h2"><?php _e( "UltimateMember Menu Settings", 'ultimate-member' ) ?></div>
|
||||
|
||||
<?php
|
||||
foreach ( self::$fields as $_key => $label ) :
|
||||
$key = sprintf( 'menu-item-%s', $_key );
|
||||
$id = sprintf( 'edit-%s-%s', $key, $item->ID );
|
||||
$name = sprintf( '%s[%s]', $key, $item->ID );
|
||||
$value = get_post_meta( $item->ID, $key, true );
|
||||
$role_name = sprintf( '%s[%s][]', $key, $item->ID );
|
||||
$class = sprintf( 'field-%s', $_key );
|
||||
?>
|
||||
|
||||
<?php if ( $_key == 'um_nav_public' ) { ?>
|
||||
|
||||
<div class="description-wide um-nav-mode">
|
||||
|
||||
<span class="description"><?php _e( "Who can see this menu link?"); ?></span><br />
|
||||
|
||||
<p class="description">
|
||||
|
||||
<label><input type="radio" name="<?php echo $name; ?>" value="0" <?php if (!isset($value) || $value == '') echo 'checked="checked"'; ?> /> Everyone</label>
|
||||
|
||||
<label><input type="radio" name="<?php echo $name; ?>" value="1" <?php checked(1, $value); ?> /> Logged Out Users</label>
|
||||
|
||||
<label><input type="radio" name="<?php echo $name; ?>" value="2" <?php checked(2, $value); ?> /> Logged In Users</label>
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php if ( $_key == 'um_nav_roles' ) { ?>
|
||||
<?php $role_value = get_post_meta( $item->ID, $_key , true ); ?>
|
||||
<div class="description-wide um-nav-roles">
|
||||
|
||||
<span class="description"><?php _e( "Select the member roles that can see this link"); ?></span><br />
|
||||
|
||||
<p class="description">
|
||||
|
||||
<?php foreach( UM()->roles()->get_roles() as $role_id => $role) { ?>
|
||||
<label><input type="checkbox" name="<?php echo $role_name; ?>" value="<?php echo $role_id; ?>" <?php if ( ( is_array($value) && in_array($role_id, $value ) ) || ( isset($value) && $role_id == $value ) ) echo 'checked="checked"'; ?> /> <?php echo $role; ?></label>
|
||||
<?php } ?>
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
<?php foreach ( self::$fields as $_key => $label ) {
|
||||
$key = sprintf('menu-item-%s', $_key);
|
||||
$id = sprintf('edit-%s-%s', $key, $item->ID);
|
||||
$name = sprintf('%s[%s]', $key, $item->ID);
|
||||
$value = get_post_meta($item->ID, $key, true);
|
||||
$role_name = sprintf('%s[%s][]', $key, $item->ID);
|
||||
$class = sprintf('field-%s', $_key); ?>
|
||||
|
||||
<?php if ( $_key == 'um_nav_public' ) { ?>
|
||||
|
||||
<p class="description description-wide um-nav-mode">
|
||||
<label for="<?php echo $id ?>">
|
||||
<?php _e( "Who can see this menu link?", 'ultimate-member' ); ?><br/>
|
||||
<select id="<?php echo $id ?>" name="<?php echo $name ?>" style="width:100%;">
|
||||
<option value="0" <?php selected(!isset($value) || $value == ''); ?>>
|
||||
<?php _e( 'Everyone', 'ultimate-member' ) ?>
|
||||
</option>
|
||||
<option value="1" <?php selected(1, $value); ?>>
|
||||
<?php _e( 'Logged Out Users', 'ultimate-member' ) ?>
|
||||
</option>
|
||||
<option value="2" <?php selected(2, $value); ?>>
|
||||
<?php _e( 'Logged In Users', 'ultimate-member' ) ?>
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<?php }
|
||||
|
||||
if ( $_key == 'um_nav_roles' ) { ?>
|
||||
|
||||
<p class="description description-wide um-nav-roles">
|
||||
<?php _e( "Select the member roles that can see this link", 'ultimate-member' ) ?><br />
|
||||
|
||||
<?php $options = UM()->roles()->get_roles();
|
||||
$i = 0;
|
||||
$html = '';
|
||||
$columns = 2;
|
||||
while ( $i < $columns ) {
|
||||
$per_page = ceil( count( $options ) / $columns );
|
||||
$section_fields_per_page = array_slice( $options, $i*$per_page, $per_page );
|
||||
$html .= '<span class="um-form-fields-section" style="width:' . floor( 100 / $columns ) . '% !important;">';
|
||||
|
||||
foreach ( $section_fields_per_page as $k => $title ) {
|
||||
$id_attr = ' id="' . $id . '_' . $k . '" ';
|
||||
$for_attr = ' for="' . $id . '_' . $k . '" ';
|
||||
$name_attr = ' name="' . $role_name . '" ';
|
||||
|
||||
$html .= "<label $for_attr>
|
||||
<input type=\"checkbox\" " . checked( ( is_array( $value ) && in_array( $k, $value ) ) || ( isset( $value ) && $k == $value ), true, false ) . "$id_attr $name_attr value=\"" . $k . "\">
|
||||
<span>$title</span>
|
||||
</label>";
|
||||
}
|
||||
|
||||
$html .= '</span>';
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo $html; ?>
|
||||
</p>
|
||||
<?php }
|
||||
} ?>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user