2015-01-07 08:37:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
*** @
|
|
|
|
|
***/
|
|
|
|
|
add_action('um_access_homepage_per_role','um_access_homepage_per_role');
|
|
|
|
|
function um_access_homepage_per_role() {
|
|
|
|
|
global $ultimatemember;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
if ( !is_user_logged_in() ) return;
|
|
|
|
|
if ( is_admin() ) return;
|
|
|
|
|
if ( um_user('default_homepage') ) return;
|
|
|
|
|
if ( !um_user('redirect_homepage') ) return;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-04-07 20:10:23 +02:00
|
|
|
if( is_front_page() ) {
|
2015-01-07 08:37:25 +02:00
|
|
|
$ultimatemember->access->redirect_handler = um_user('redirect_homepage');
|
2015-04-07 20:10:23 +02:00
|
|
|
}
|
2015-01-07 08:37:25 +02:00
|
|
|
}
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
/***
|
|
|
|
|
*** @
|
|
|
|
|
***/
|
|
|
|
|
add_action('um_access_global_settings','um_access_global_settings');
|
|
|
|
|
function um_access_global_settings() {
|
|
|
|
|
global $post, $ultimatemember;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
$access = um_get_option('accessible');
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
if ( $access == 2 && !is_user_logged_in() ) {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
$redirect = um_get_option('access_redirect');
|
2016-02-20 18:10:09 -08:00
|
|
|
if ( !$redirect )
|
2015-04-07 20:10:23 +02:00
|
|
|
$redirect = um_get_core_page('login');
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-02-11 00:50:38 +02:00
|
|
|
$redirects[] = untrailingslashit( um_get_core_page('login') );
|
|
|
|
|
$redirects[] = untrailingslashit( um_get_option('access_redirect') );
|
|
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
$exclude_uris = um_get_option('access_exclude_uris');
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
if ( $exclude_uris ) {
|
|
|
|
|
$redirects = array_merge( $redirects, $exclude_uris );
|
|
|
|
|
}
|
2015-04-07 20:10:23 +02:00
|
|
|
|
2015-02-24 18:30:11 +02:00
|
|
|
$redirects = array_unique( $redirects );
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-28 17:16:04 +02:00
|
|
|
$current_url = $ultimatemember->permalinks->get_current_url( get_option('permalink_structure') );
|
2015-02-11 00:50:38 +02:00
|
|
|
$current_url = untrailingslashit( $current_url );
|
2015-02-24 18:30:11 +02:00
|
|
|
$current_url_slash = trailingslashit( $current_url );
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-02-24 18:30:11 +02:00
|
|
|
if ( ( isset( $post->ID ) || is_home() ) && ( in_array( $current_url, $redirects ) || in_array( $current_url_slash, $redirects ) ) ) {
|
|
|
|
|
// allow
|
2015-01-07 08:37:25 +02:00
|
|
|
} else {
|
|
|
|
|
$ultimatemember->access->redirect_handler = $redirect;
|
|
|
|
|
}
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
/***
|
|
|
|
|
*** @
|
|
|
|
|
***/
|
|
|
|
|
add_action('um_access_category_settings','um_access_category_settings');
|
|
|
|
|
function um_access_category_settings() {
|
|
|
|
|
global $post, $wp_query, $ultimatemember;
|
2015-12-16 16:37:27 +08:00
|
|
|
|
2016-03-09 22:13:24 +08:00
|
|
|
if( is_front_page() || is_home() || is_feed() ){
|
2015-12-16 16:37:27 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2016-01-07 10:41:49 +08:00
|
|
|
|
|
|
|
|
if ( is_single() || get_post_taxonomies( $post ) ) {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-25 20:37:42 +08:00
|
|
|
|
2016-01-07 10:41:49 +08:00
|
|
|
$taxonomies = get_post_taxonomies( $post );
|
|
|
|
|
$categories_ids = array();
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2016-01-07 10:41:49 +08:00
|
|
|
foreach ($taxonomies as $key => $value) {
|
|
|
|
|
$term_list = wp_get_post_terms($post->ID, $value, array("fields" => "ids"));
|
|
|
|
|
foreach( $term_list as $term_id ){
|
|
|
|
|
array_push( $categories_ids , $term_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach( $categories_ids as $term => $term_id ) {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
$opt = get_option("category_$term_id");
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
if ( isset( $opt['_um_accessible'] ) ) {
|
|
|
|
|
switch( $opt['_um_accessible'] ) {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
|
|
|
|
case 0:
|
2015-11-05 19:51:31 +08:00
|
|
|
$ultimatemember->access->allow_access = true;
|
|
|
|
|
$ultimatemember->access->redirect_handler = false; // open to everyone
|
|
|
|
|
break;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
case 1:
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
if ( is_user_logged_in() )
|
2015-12-22 17:45:12 +08:00
|
|
|
$ultimatemember->access->redirect_handler = ( isset( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url();
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
if ( !is_user_logged_in() )
|
|
|
|
|
$ultimatemember->access->allow_access = true;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
break;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
case 2:
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-25 20:37:42 +08:00
|
|
|
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');
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
if ( is_user_logged_in() && isset( $opt['_um_roles'] ) && !empty( $opt['_um_roles'] ) ){
|
|
|
|
|
if ( !in_array( um_user('role'), $opt['_um_roles'] ) ) {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
if ( is_user_logged_in() )
|
2015-12-22 17:45:12 +08:00
|
|
|
$ultimatemember->access->redirect_handler = ( isset( $opt['_um_redirect'] ) ) ? $opt['_um_redirect'] : site_url();
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
if ( !is_user_logged_in() )
|
|
|
|
|
$ultimatemember->access->redirect_handler = um_get_core_page('login');
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-11-05 19:51:31 +08:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-16 18:15:40 +08:00
|
|
|
|
|
|
|
|
if( is_archive() ){
|
|
|
|
|
$ultimatemember->access->allow_access = true;
|
|
|
|
|
$ultimatemember->access->redirect_handler = false; // open to everyone
|
|
|
|
|
}
|
2015-11-05 19:51:31 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
/***
|
|
|
|
|
*** @
|
|
|
|
|
***/
|
|
|
|
|
add_action('um_access_post_settings','um_access_post_settings');
|
|
|
|
|
function um_access_post_settings() {
|
|
|
|
|
global $post, $ultimatemember;
|
2016-01-07 10:41:49 +08:00
|
|
|
|
2015-01-24 23:39:43 +02:00
|
|
|
// woo commerce shop ID
|
|
|
|
|
if( function_exists('is_shop') && is_shop() ) {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-24 23:39:43 +02:00
|
|
|
$post_id = get_option('woocommerce_shop_page_id');
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2016-03-09 22:13:24 +08:00
|
|
|
} else if ( is_archive() || is_front_page() || is_home() || is_search() || in_the_loop() || is_feed() ) {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-26 16:58:31 +02:00
|
|
|
return;
|
|
|
|
|
|
2015-01-24 23:39:43 +02:00
|
|
|
} else {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-24 23:39:43 +02:00
|
|
|
if ( !get_post_type() || !isset($post->ID) ) return;
|
|
|
|
|
|
|
|
|
|
}
|
2015-01-26 16:58:31 +02:00
|
|
|
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2016-01-07 10:41:49 +08:00
|
|
|
|
2015-01-24 23:39:43 +02:00
|
|
|
if ( !isset( $post_id ) )
|
|
|
|
|
$post_id = $post->ID;
|
|
|
|
|
|
|
|
|
|
$args = $ultimatemember->access->get_meta( $post_id );
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
extract($args);
|
2015-01-24 23:39:43 +02:00
|
|
|
|
2015-01-26 16:58:31 +02:00
|
|
|
if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-26 16:58:31 +02:00
|
|
|
$post_id = apply_filters('um_access_control_for_parent_posts', $post_id );
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-26 16:58:31 +02:00
|
|
|
$args = $ultimatemember->access->get_meta( $post_id );
|
|
|
|
|
extract($args);
|
|
|
|
|
|
|
|
|
|
if ( !isset( $args['custom_access_settings'] ) || $args['custom_access_settings'] == 0 ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-26 16:58:31 +02:00
|
|
|
}
|
2015-01-07 08:37:25 +02:00
|
|
|
|
|
|
|
|
$redirect_to = null;
|
|
|
|
|
|
|
|
|
|
if ( !isset( $accessible ) ) return;
|
|
|
|
|
|
|
|
|
|
switch( $accessible ) {
|
2016-02-20 18:10:09 -08:00
|
|
|
|
|
|
|
|
case 0:
|
2015-01-07 08:37:25 +02:00
|
|
|
$ultimatemember->access->allow_access = true;
|
|
|
|
|
$ultimatemember->access->redirect_handler = false; // open to everyone
|
2016-01-07 10:41:49 +08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
break;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
case 1:
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
if ( is_user_logged_in() )
|
|
|
|
|
$redirect_to = $access_redirect2;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
if ( !is_user_logged_in() )
|
|
|
|
|
$ultimatemember->access->allow_access = true;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
break;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
case 2:
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
if ( !is_user_logged_in() ){
|
2015-02-10 02:05:27 +02:00
|
|
|
if ( !$access_redirect ) $access_redirect = um_get_core_page('login');
|
2015-01-07 08:37:25 +02:00
|
|
|
$redirect_to = $access_redirect;
|
|
|
|
|
}
|
2015-02-21 01:39:02 +02:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
if ( is_user_logged_in() && isset( $access_roles ) && !empty( $access_roles ) ){
|
2016-02-20 18:10:09 -08:00
|
|
|
$access_roles = unserialize( $access_roles );
|
|
|
|
|
$access_roles = array_filter($access_roles);
|
|
|
|
|
|
|
|
|
|
if ( !empty( $access_roles ) && !in_array( um_user('role'), $access_roles ) ) {
|
2015-11-05 19:51:31 +08:00
|
|
|
if ( !$access_redirect ) {
|
|
|
|
|
if ( is_user_logged_in() ) {
|
2015-12-22 17:45:12 +08:00
|
|
|
$access_redirect = site_url();
|
2015-11-05 19:51:31 +08:00
|
|
|
} else {
|
|
|
|
|
$access_redirect = um_get_core_page('login');
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-07 08:37:25 +02:00
|
|
|
$redirect_to = $access_redirect;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
break;
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
}
|
2016-02-20 18:10:09 -08:00
|
|
|
|
2015-01-07 08:37:25 +02:00
|
|
|
if ( $redirect_to ) {
|
2015-11-05 19:51:31 +08:00
|
|
|
if ( is_feed() ) {
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
$ultimatemember->access->allow_access = false;
|
|
|
|
|
$ultimatemember->access->redirect_handler = $redirect_to;
|
|
|
|
|
}
|
2015-01-07 08:37:25 +02:00
|
|
|
}
|
2016-01-07 10:41:49 +08:00
|
|
|
|
2016-02-20 18:10:09 -08:00
|
|
|
}
|