mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-20 15:13:55 +09:00
Content Restriction
This commit is contained in:
+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'; } ?>">
|
||||
|
||||
Reference in New Issue
Block a user