mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-13 11:46:27 +09:00
Content Restriction
This commit is contained in:
@@ -20,8 +20,6 @@
|
||||
-moz-osx-font-smoothing: grayscale !important;
|
||||
}
|
||||
|
||||
#um-admin-access-control * {vertical-align: middle}
|
||||
|
||||
#um-admin-access-control p {font-size: 13px}
|
||||
|
||||
#um-admin-access-control input[type=text] {font-size: 13px}
|
||||
|
||||
@@ -107,8 +107,10 @@ class UM_Admin_Metabox {
|
||||
***/
|
||||
function ui_on_off( $id, $default=0, $is_conditional=false, $cond1='', $cond1_show='', $cond1_hide='' ) {
|
||||
|
||||
if (isset($this->postmeta[$id][0])) {
|
||||
$active = $this->postmeta[$id][0];
|
||||
$meta = get_post_meta( get_the_ID(), $id, true );
|
||||
|
||||
if (isset($this->postmeta[$id][0]) || $meta ) {
|
||||
$active = ( isset( $this->postmeta[$id][0] ) ) ? $this->postmeta[$id][0] : $meta;
|
||||
} else {
|
||||
$active = $default;
|
||||
}
|
||||
|
||||
@@ -1,51 +1,62 @@
|
||||
<h4><?php _e('Content Availability','ultimatemember'); ?> <?php $this->tooltip( __('Who can access this content?','ultimatemember'), 'e'); ?></h4>
|
||||
<h4><?php _e('Apply custom access settings?','ultimatemember'); ?> <?php $this->tooltip( __('Switch to yes to override global access settings','ultimatemember'), 'e'); ?></h4>
|
||||
|
||||
<p class="um-conditional-radio-group description" data-cond1="2" data-cond1-show="um-admin-access-roles" data-cond2="1" data-cond2-show="um-admin-access-loggedout">
|
||||
|
||||
<?php $value = get_post_meta($post->ID, '_um_accessible', true); ?>
|
||||
|
||||
<label><input type="radio" name="_um_accessible" value="0" <?php if (!isset($value) || $value == 0 ) echo 'checked="checked"'; ?> /> <?php _e('Content accessible to Everyone','ultimatemember'); ?></label><br />
|
||||
<label><input type="radio" name="_um_accessible" value="1" <?php if (isset($value)) checked(1, $value); ?> /> <?php _e('Content accessible to Logged Out Users','ultimatemember'); ?></label><br />
|
||||
<label><input type="radio" name="_um_accessible" value="2" <?php if (isset($value)) checked(2, $value); ?> /> <?php _e('Content accessible to Logged In Users','ultimatemember'); ?></label>
|
||||
|
||||
<p>
|
||||
<?php $metabox = new UM_Admin_Metabox(); ?>
|
||||
<span><?php $metabox->ui_on_off('_um_custom_access_settings', 0, true, 1, '_um_custom_access_settings', 'xxx'); ?> </span>
|
||||
</p>
|
||||
|
||||
<div class="um-admin-access-loggedout">
|
||||
<div class="_um_custom_access_settings">
|
||||
|
||||
<h4><label for="_um_access_redirect2"><?php _e('Redirect URL','ultimatemember'); ?></label> <?php $this->tooltip( __('This is the URL that user is redirected to If he is not permitted to view this content','ultimatemember'), 'e'); ?></h4>
|
||||
<h4><?php _e('Content Availability','ultimatemember'); ?> <?php $this->tooltip( __('Who can access this content?','ultimatemember'), 'e'); ?></h4>
|
||||
|
||||
<p class="description">
|
||||
<p class="um-conditional-radio-group description" data-cond1="2" data-cond1-show="um-admin-access-roles" data-cond2="1" data-cond2-show="um-admin-access-loggedout">
|
||||
|
||||
<?php $value = get_post_meta($post->ID, '_um_access_redirect2', true); ?>
|
||||
|
||||
<input type="text" name="_um_access_redirect2" id="_um_access_redirect2" value="<?php if ( isset( $value ) ) echo $value; ?>" class="widefat" />
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="um-admin-access-roles">
|
||||
|
||||
<h4><?php _e('Select the member roles that can see this content?','ultimatemember'); ?> <?php $this->tooltip( __('If you do not select any role, all members wil be able to view this content','ultimatemember'), 'e'); ?></h4>
|
||||
|
||||
<p class="description">
|
||||
|
||||
<?php $value = get_post_meta($post->ID, '_um_access_roles', true); ?>
|
||||
<?php $value = get_post_meta($post->ID, '_um_accessible', true); ?>
|
||||
|
||||
<?php foreach($ultimatemember->query->get_roles() as $role_id => $role) { ?>
|
||||
<label><input type="checkbox" name="_um_access_roles[]" value="<?php echo $role_id; ?>" <?php if ( ( isset( $value ) && is_array( $value ) && in_array($role_id, $value ) ) || ( isset( $value ) && $role_id == $value ) ) echo 'checked="checked"'; ?> /> <?php echo $role; ?></label><br />
|
||||
<?php } ?>
|
||||
|
||||
</p>
|
||||
|
||||
<h4><label for="_um_access_redirect"><?php _e('Redirect URL','ultimatemember'); ?></label> <?php $this->tooltip( __('This is the URL that user is redirected to If he is not permitted to view this content','ultimatemember'), 'e'); ?></h4>
|
||||
|
||||
<p class="description">
|
||||
|
||||
<?php $value = get_post_meta($post->ID, '_um_access_redirect', true); ?>
|
||||
<label><input type="radio" name="_um_accessible" value="0" <?php if (!isset($value) || $value == 0 ) echo 'checked="checked"'; ?> /> <?php _e('Content accessible to Everyone','ultimatemember'); ?></label><br />
|
||||
<label><input type="radio" name="_um_accessible" value="1" <?php if (isset($value)) checked(1, $value); ?> /> <?php _e('Content accessible to Logged Out Users','ultimatemember'); ?></label><br />
|
||||
<label><input type="radio" name="_um_accessible" value="2" <?php if (isset($value)) checked(2, $value); ?> /> <?php _e('Content accessible to Logged In Users','ultimatemember'); ?></label>
|
||||
|
||||
<input type="text" name="_um_access_redirect" id="_um_access_redirect" value="<?php if ( isset( $value ) ) echo $value; ?>" class="widefat" />
|
||||
|
||||
</p>
|
||||
|
||||
<div class="um-admin-access-loggedout">
|
||||
|
||||
<h4><label for="_um_access_redirect2"><?php _e('Redirect URL','ultimatemember'); ?></label> <?php $this->tooltip( __('This is the URL that user is redirected to If he is not permitted to view this content','ultimatemember'), 'e'); ?></h4>
|
||||
|
||||
<p class="description">
|
||||
|
||||
<?php $value = get_post_meta($post->ID, '_um_access_redirect2', true); ?>
|
||||
|
||||
<input type="text" name="_um_access_redirect2" id="_um_access_redirect2" value="<?php if ( isset( $value ) ) echo $value; ?>" class="widefat" />
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="um-admin-access-roles">
|
||||
|
||||
<h4><?php _e('Select the member roles that can see this content?','ultimatemember'); ?> <?php $this->tooltip( __('If you do not select any role, all members wil be able to view this content','ultimatemember'), 'e'); ?></h4>
|
||||
|
||||
<p class="description">
|
||||
|
||||
<?php $value = get_post_meta($post->ID, '_um_access_roles', true); ?>
|
||||
|
||||
<?php foreach($ultimatemember->query->get_roles() as $role_id => $role) { ?>
|
||||
<label><input type="checkbox" name="_um_access_roles[]" value="<?php echo $role_id; ?>" <?php if ( ( isset( $value ) && is_array( $value ) && in_array($role_id, $value ) ) || ( isset( $value ) && $role_id == $value ) ) echo 'checked="checked"'; ?> /> <?php echo $role; ?></label><br />
|
||||
<?php } ?>
|
||||
|
||||
</p>
|
||||
|
||||
<h4><label for="_um_access_redirect"><?php _e('Redirect URL','ultimatemember'); ?></label> <?php $this->tooltip( __('This is the URL that user is redirected to If he is not permitted to view this content','ultimatemember'), 'e'); ?></h4>
|
||||
|
||||
<p class="description">
|
||||
|
||||
<?php $value = get_post_meta($post->ID, '_um_access_redirect', true); ?>
|
||||
|
||||
<input type="text" name="_um_access_redirect" id="_um_access_redirect" value="<?php if ( isset( $value ) ) echo $value; ?>" class="widefat" />
|
||||
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -65,9 +65,9 @@
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.um-account-meta img {
|
||||
border-radius: 999px;
|
||||
}
|
||||
.um-account-meta.radius-1 img { border-radius: 999px }
|
||||
.um-account-meta.radius-2 img { border-radius: 4px }
|
||||
.um-account-meta.radius-3 img { border-radius: 0 }
|
||||
|
||||
.um-account-name a {
|
||||
font-weight: bold;
|
||||
|
||||
@@ -170,7 +170,6 @@
|
||||
|
||||
.um-member-photo img {
|
||||
display: inline !important;
|
||||
border-radius: 999px !important;
|
||||
border: 5px solid #fff;
|
||||
background: #fff;
|
||||
width: 140px;
|
||||
@@ -186,6 +185,10 @@
|
||||
margin-bottom: -45px !important;
|
||||
}
|
||||
|
||||
.um-member-photo.radius-1 img { border-radius: 999px !important }
|
||||
.um-member-photo.radius-2 img { border-radius: 4px !important }
|
||||
.um-member-photo.radius-3 img { border-radius: 0 !important }
|
||||
|
||||
/*
|
||||
- Member name
|
||||
*/
|
||||
|
||||
+19
-65
@@ -4,11 +4,26 @@ class UM_Access {
|
||||
|
||||
function __construct() {
|
||||
|
||||
// hook into template redirects [home]
|
||||
add_action('template_redirect', array(&$this, 'custom_homepage_per_role'), 1000);
|
||||
$this->redirect_handler = false;
|
||||
$this->allow_access = false;
|
||||
|
||||
// hook into template redirects
|
||||
add_action('template_redirect', array(&$this, 'post_page_access_control'), 999);
|
||||
add_action('template_redirect', array(&$this, 'template_redirect'), 1000 );
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*** @do actions based on priority
|
||||
***/
|
||||
function template_redirect() {
|
||||
|
||||
do_action('um_access_homepage_per_role');
|
||||
|
||||
do_action('um_access_global_settings');
|
||||
|
||||
do_action('um_access_post_settings');
|
||||
|
||||
if ( $this->redirect_handler && !$this->allow_access )
|
||||
exit( wp_redirect( $this->redirect_handler ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -30,66 +45,5 @@ class UM_Access {
|
||||
else
|
||||
return array('');
|
||||
}
|
||||
|
||||
/***
|
||||
*** @custom homepage per role
|
||||
***/
|
||||
function custom_homepage_per_role(){
|
||||
|
||||
if ( !is_user_logged_in() ) return;
|
||||
if ( is_admin() ) return;
|
||||
if ( um_user('default_homepage') ) return;
|
||||
if ( !um_user('redirect_homepage') ) return;
|
||||
|
||||
if( is_home() || is_front_page() )
|
||||
exit( wp_redirect( um_user('redirect_homepage') ) );
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*** @the main restrict function
|
||||
***/
|
||||
function post_page_access_control(){
|
||||
global $post;
|
||||
|
||||
if ( !get_post_type() || !isset($post->ID) ) return;
|
||||
|
||||
$args = $this->get_meta();
|
||||
extract($args);
|
||||
|
||||
$redirect_to = null;
|
||||
|
||||
if ( !isset( $accessible ) ) return;
|
||||
|
||||
switch( $accessible ) {
|
||||
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
if ( is_user_logged_in() )
|
||||
$redirect_to = $access_redirect2;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
if ( !is_user_logged_in() )
|
||||
$redirect_to = $access_redirect;
|
||||
|
||||
if ( isset( $access_roles ) && !empty( $access_roles ) )
|
||||
if ( !in_array( um_user('role'), unserialize( $access_roles ) ) )
|
||||
$redirect_to = $access_redirect;
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( $redirect_to ) {
|
||||
wp_redirect( $redirect_to );
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/***
|
||||
*** @
|
||||
***/
|
||||
add_action('um_access_homepage_per_role','um_access_homepage_per_role');
|
||||
function um_access_homepage_per_role() {
|
||||
global $ultimatemember;
|
||||
|
||||
if ( !is_user_logged_in() ) return;
|
||||
if ( is_admin() ) return;
|
||||
if ( um_user('default_homepage') ) return;
|
||||
if ( !um_user('redirect_homepage') ) return;
|
||||
|
||||
if( is_home() || is_front_page() )
|
||||
$ultimatemember->access->redirect_handler = um_user('redirect_homepage');
|
||||
}
|
||||
|
||||
/***
|
||||
*** @
|
||||
***/
|
||||
add_action('um_access_global_settings','um_access_global_settings');
|
||||
function um_access_global_settings() {
|
||||
global $post, $ultimatemember;
|
||||
|
||||
$access = um_get_option('accessible');
|
||||
|
||||
if ( $access == 2 && !is_user_logged_in() ) {
|
||||
|
||||
$redirect = um_get_option('access_redirect');
|
||||
|
||||
$redirects[] = trailingslashit( um_get_core_page('login') );
|
||||
$redirects[] = trailingslashit( um_get_option('access_redirect') );
|
||||
|
||||
$exclude_uris = um_get_option('access_exclude_uris');
|
||||
|
||||
if ( $exclude_uris ) {
|
||||
$redirects = array_merge( $redirects, $exclude_uris );
|
||||
}
|
||||
|
||||
$current_url = trailingslashit( $ultimatemember->permalinks->get_current_url(true) );
|
||||
|
||||
if ( isset( $post->ID ) && in_array( $current_url, $redirects ) ) {
|
||||
// allow
|
||||
} else {
|
||||
$ultimatemember->access->redirect_handler = $redirect;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*** @
|
||||
***/
|
||||
add_action('um_access_post_settings','um_access_post_settings');
|
||||
function um_access_post_settings() {
|
||||
global $post, $ultimatemember;
|
||||
|
||||
if ( !get_post_type() || !isset($post->ID) ) return;
|
||||
|
||||
$args = $ultimatemember->access->get_meta();
|
||||
extract($args);
|
||||
|
||||
if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) return;
|
||||
|
||||
$redirect_to = null;
|
||||
|
||||
if ( !isset( $accessible ) ) return;
|
||||
|
||||
switch( $accessible ) {
|
||||
|
||||
case 0:
|
||||
$ultimatemember->access->allow_access = true;
|
||||
$ultimatemember->access->redirect_handler = false; // open to everyone
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
if ( is_user_logged_in() )
|
||||
$redirect_to = $access_redirect2;
|
||||
|
||||
if ( !is_user_logged_in() )
|
||||
$ultimatemember->access->allow_access = true;
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
if ( !is_user_logged_in() ){
|
||||
if ( !$access_redirect ) $access_redirect = home_url();
|
||||
$redirect_to = $access_redirect;
|
||||
}
|
||||
|
||||
if ( is_user_logged_in() && isset( $access_roles ) && !empty( $access_roles ) ){
|
||||
if ( !in_array( um_user('role'), unserialize( $access_roles ) ) ) {
|
||||
$redirect_to = $access_redirect;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( $redirect_to ) {
|
||||
$ultimatemember->access->redirect_handler = $redirect_to;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -243,7 +243,7 @@
|
||||
|
||||
?>
|
||||
|
||||
<div class="um-account-meta">
|
||||
<div class="um-account-meta radius-<?php echo um_get_option('profile_photocorner'); ?>">
|
||||
|
||||
<div class="um-account-meta-img uimob800-hide"><a href="<?php echo um_user_profile_url(); ?>"><?php echo um_user('profile_photo', 120); ?></a></div>
|
||||
|
||||
|
||||
@@ -219,8 +219,11 @@
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($profile_photo) { $default_size = str_replace( 'px', '', um_get_option('profile_photosize') ); ?>
|
||||
<div class="um-member-photo"><a href="<?php echo um_user_profile_url(); ?>"><?php echo um_user('profile_photo', $default_size ); ?></a></div>
|
||||
<?php if ($profile_photo) {
|
||||
$default_size = str_replace( 'px', '', um_get_option('profile_photosize') );
|
||||
$corner = um_get_option('profile_photocorner');
|
||||
?>
|
||||
<div class="um-member-photo radius-<?php echo $corner; ?>"><a href="<?php echo um_user_profile_url(); ?>"><?php echo um_user('profile_photo', $default_size ); ?></a></div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="um-member-card <?php if (!$profile_photo) { echo 'no-photo'; } ?>">
|
||||
|
||||
@@ -223,6 +223,16 @@ $this->sections[] = array(
|
||||
'desc' => 'A logged out user will be redirected to this url If he is not permitted to access the site',
|
||||
'required' => array( 'accessible', '=', 2 ),
|
||||
),
|
||||
|
||||
array(
|
||||
'id' => 'access_exclude_uris',
|
||||
'type' => 'multi_text',
|
||||
'default' => array(),
|
||||
'title' => __( 'Exclude the following URLs' ),
|
||||
'desc' => __( 'Here you can exclude URLs beside the redirect URI to be accessible to everyone' ),
|
||||
'add_text' => __('Add New URL'),
|
||||
'required' => array( 'accessible', '=', 2 ),
|
||||
),
|
||||
|
||||
)
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ class UM_API {
|
||||
require_once um_path . 'core/lib/mobiledetect/Mobile_Detect.php';
|
||||
|
||||
require_once um_path . 'core/um-actions-form.php';
|
||||
require_once um_path . 'core/um-actions-access.php';
|
||||
require_once um_path . 'core/um-actions-wpadmin.php';
|
||||
require_once um_path . 'core/um-actions-core.php';
|
||||
require_once um_path . 'core/um-actions-ajax.php';
|
||||
|
||||
Reference in New Issue
Block a user