Merge pull request #92 from jonfalcon/master

Fix empty access roles
This commit is contained in:
Champ Camba
2016-02-22 19:38:30 +08:00
+55 -52
View File
@@ -6,57 +6,57 @@
add_action('um_access_homepage_per_role','um_access_homepage_per_role'); add_action('um_access_homepage_per_role','um_access_homepage_per_role');
function um_access_homepage_per_role() { function um_access_homepage_per_role() {
global $ultimatemember; global $ultimatemember;
if ( !is_user_logged_in() ) return; if ( !is_user_logged_in() ) return;
if ( is_admin() ) return; if ( is_admin() ) return;
if ( um_user('default_homepage') ) return; if ( um_user('default_homepage') ) return;
if ( !um_user('redirect_homepage') ) return; if ( !um_user('redirect_homepage') ) return;
if( is_front_page() ) { if( is_front_page() ) {
$ultimatemember->access->redirect_handler = um_user('redirect_homepage'); $ultimatemember->access->redirect_handler = um_user('redirect_homepage');
} }
} }
/*** /***
*** @ *** @
***/ ***/
add_action('um_access_global_settings','um_access_global_settings'); add_action('um_access_global_settings','um_access_global_settings');
function um_access_global_settings() { function um_access_global_settings() {
global $post, $ultimatemember; global $post, $ultimatemember;
$access = um_get_option('accessible'); $access = um_get_option('accessible');
if ( $access == 2 && !is_user_logged_in() ) { if ( $access == 2 && !is_user_logged_in() ) {
$redirect = um_get_option('access_redirect'); $redirect = um_get_option('access_redirect');
if ( !$redirect ) if ( !$redirect )
$redirect = um_get_core_page('login'); $redirect = um_get_core_page('login');
$redirects[] = untrailingslashit( um_get_core_page('login') ); $redirects[] = untrailingslashit( um_get_core_page('login') );
$redirects[] = untrailingslashit( um_get_option('access_redirect') ); $redirects[] = untrailingslashit( um_get_option('access_redirect') );
$exclude_uris = um_get_option('access_exclude_uris'); $exclude_uris = um_get_option('access_exclude_uris');
if ( $exclude_uris ) { if ( $exclude_uris ) {
$redirects = array_merge( $redirects, $exclude_uris ); $redirects = array_merge( $redirects, $exclude_uris );
} }
$redirects = array_unique( $redirects ); $redirects = array_unique( $redirects );
$current_url = $ultimatemember->permalinks->get_current_url( get_option('permalink_structure') ); $current_url = $ultimatemember->permalinks->get_current_url( get_option('permalink_structure') );
$current_url = untrailingslashit( $current_url ); $current_url = untrailingslashit( $current_url );
$current_url_slash = trailingslashit( $current_url ); $current_url_slash = trailingslashit( $current_url );
if ( ( isset( $post->ID ) || is_home() ) && ( in_array( $current_url, $redirects ) || in_array( $current_url_slash, $redirects ) ) ) { if ( ( isset( $post->ID ) || is_home() ) && ( in_array( $current_url, $redirects ) || in_array( $current_url_slash, $redirects ) ) ) {
// allow // allow
} else { } else {
$ultimatemember->access->redirect_handler = $redirect; $ultimatemember->access->redirect_handler = $redirect;
} }
} }
} }
/*** /***
*** @ *** @
***/ ***/
@@ -69,11 +69,11 @@
} }
if ( is_single() || get_post_taxonomies( $post ) ) { if ( is_single() || get_post_taxonomies( $post ) ) {
$taxonomies = get_post_taxonomies( $post ); $taxonomies = get_post_taxonomies( $post );
$categories_ids = array(); $categories_ids = array();
foreach ($taxonomies as $key => $value) { foreach ($taxonomies as $key => $value) {
$term_list = wp_get_post_terms($post->ID, $value, array("fields" => "ids")); $term_list = wp_get_post_terms($post->ID, $value, array("fields" => "ids"));
foreach( $term_list as $term_id ){ foreach( $term_list as $term_id ){
@@ -83,43 +83,43 @@
foreach( $categories_ids as $term => $term_id ) { foreach( $categories_ids as $term => $term_id ) {
$opt = get_option("category_$term_id"); $opt = get_option("category_$term_id");
if ( isset( $opt['_um_accessible'] ) ) { if ( isset( $opt['_um_accessible'] ) ) {
switch( $opt['_um_accessible'] ) { switch( $opt['_um_accessible'] ) {
case 0: case 0:
$ultimatemember->access->allow_access = true; $ultimatemember->access->allow_access = true;
$ultimatemember->access->redirect_handler = false; // open to everyone $ultimatemember->access->redirect_handler = false; // open to everyone
break; break;
case 1: case 1:
if ( is_user_logged_in() ) if ( is_user_logged_in() )
$ultimatemember->access->redirect_handler = ( isset( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); $ultimatemember->access->redirect_handler = ( isset( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url();
if ( !is_user_logged_in() ) if ( !is_user_logged_in() )
$ultimatemember->access->allow_access = true; $ultimatemember->access->allow_access = true;
break; break;
case 2: case 2:
if ( ! is_user_logged_in() ) if ( ! is_user_logged_in() )
$ultimatemember->access->redirect_handler = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : um_get_core_page('login'); $ultimatemember->access->redirect_handler = ( isset( $opt['_um_redirect'] ) && ! empty( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : um_get_core_page('login');
if ( is_user_logged_in() && isset( $opt['_um_roles'] ) && !empty( $opt['_um_roles'] ) ){ if ( is_user_logged_in() && isset( $opt['_um_roles'] ) && !empty( $opt['_um_roles'] ) ){
if ( !in_array( um_user('role'), $opt['_um_roles'] ) ) { if ( !in_array( um_user('role'), $opt['_um_roles'] ) ) {
if ( is_user_logged_in() ) if ( is_user_logged_in() )
$ultimatemember->access->redirect_handler = ( isset( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url(); $ultimatemember->access->redirect_handler = ( isset( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url();
if ( !is_user_logged_in() ) if ( !is_user_logged_in() )
$ultimatemember->access->redirect_handler = um_get_core_page('login'); $ultimatemember->access->redirect_handler = um_get_core_page('login');
} }
} }
} }
} }
@@ -130,7 +130,7 @@
} }
} }
} }
/*** /***
*** @ *** @
***/ ***/
@@ -140,39 +140,39 @@
// woo commerce shop ID // woo commerce shop ID
if( function_exists('is_shop') && is_shop() ) { if( function_exists('is_shop') && is_shop() ) {
$post_id = get_option('woocommerce_shop_page_id'); $post_id = get_option('woocommerce_shop_page_id');
} else if ( is_archive() || is_front_page() || is_home() || is_search() || in_the_loop() ) { } else if ( is_archive() || is_front_page() || is_home() || is_search() || in_the_loop() ) {
return; return;
} else { } else {
if ( !get_post_type() || !isset($post->ID) ) return; if ( !get_post_type() || !isset($post->ID) ) return;
} }
if ( !isset( $post_id ) ) if ( !isset( $post_id ) )
$post_id = $post->ID; $post_id = $post->ID;
$args = $ultimatemember->access->get_meta( $post_id ); $args = $ultimatemember->access->get_meta( $post_id );
extract($args); extract($args);
if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) {
$post_id = apply_filters('um_access_control_for_parent_posts', $post_id ); $post_id = apply_filters('um_access_control_for_parent_posts', $post_id );
$args = $ultimatemember->access->get_meta( $post_id ); $args = $ultimatemember->access->get_meta( $post_id );
extract($args); extract($args);
if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) { if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) {
return; return;
} }
} }
$redirect_to = null; $redirect_to = null;
@@ -180,32 +180,35 @@
if ( !isset( $accessible ) ) return; if ( !isset( $accessible ) ) return;
switch( $accessible ) { switch( $accessible ) {
case 0: case 0:
$ultimatemember->access->allow_access = true; $ultimatemember->access->allow_access = true;
$ultimatemember->access->redirect_handler = false; // open to everyone $ultimatemember->access->redirect_handler = false; // open to everyone
break; break;
case 1: case 1:
if ( is_user_logged_in() ) if ( is_user_logged_in() )
$redirect_to = $access_redirect2; $redirect_to = $access_redirect2;
if ( !is_user_logged_in() ) if ( !is_user_logged_in() )
$ultimatemember->access->allow_access = true; $ultimatemember->access->allow_access = true;
break; break;
case 2: case 2:
if ( !is_user_logged_in() ){ if ( !is_user_logged_in() ){
if ( !$access_redirect ) $access_redirect = um_get_core_page('login'); if ( !$access_redirect ) $access_redirect = um_get_core_page('login');
$redirect_to = $access_redirect; $redirect_to = $access_redirect;
} }
if ( is_user_logged_in() && isset( $access_roles ) && !empty( $access_roles ) ){ if ( is_user_logged_in() && isset( $access_roles ) && !empty( $access_roles ) ){
if ( !in_array( um_user('role'), unserialize( $access_roles ) ) ) { $access_roles = unserialize( $access_roles );
$access_roles = array_filter($access_roles);
if ( !empty( $access_roles ) && !in_array( um_user('role'), $access_roles ) ) {
if ( !$access_redirect ) { if ( !$access_redirect ) {
if ( is_user_logged_in() ) { if ( is_user_logged_in() ) {
$access_redirect = site_url(); $access_redirect = site_url();
@@ -216,11 +219,11 @@
$redirect_to = $access_redirect; $redirect_to = $access_redirect;
} }
} }
break; break;
} }
if ( $redirect_to ) { if ( $redirect_to ) {
if ( is_feed() ) { if ( is_feed() ) {
@@ -230,4 +233,4 @@
} }
} }
} }