function pc_pvt_redirect() { include_once PC_DIR . '/functions.php'; $orig_redirect_val = get_option('pg_redirect_page'); $redirect_url = pc_man_redirects('pg_redirect_page'); // only if redirect option is setted if (!empty($redirect_url)) { // get redirect page url $orig_redirect_val = get_option('pg_redirect_page'); $redirect_url = pc_man_redirects('pg_redirect_page'); ////////////////////////////////////////////////////////////// // complete website lock if (get_option('pg_complete_lock') && pc_user_check('all', '', true) !== 1) { global $post; $excluded_pages = filter_var($orig_redirect_val, FILTER_VALIDATE_INT) ? array($orig_redirect_val) : array(); // PC-FILTER - add page IDS to exclude from complete site lock - page IDs array $excluded_pages = apply_filters('pc_complete_lock_exceptions', $excluded_pages); // exceptions check foreach ((array) $excluded_pages as $pag_id) { if ($pag_id == $post->ID) { $exception_page = true; break; } elseif (pc_wpml_translated_pag_id($pag_id) == $post->ID) { $exception_page = true; break; } } if (!isset($exception_page)) { // last restricted page redirect system if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '') { $_SESSION['pc_last_restricted'] = pc_curr_url(); } header('location: ' . $redirect_url); die; } } ////////////////////////////////////////////////////////////// // single page/post redirect if (is_page() || is_single()) { global $post; $result = pc_redirect_check('page', $post); // custom unlogged redirect system $is_unl_custom_redir = isset($GLOBALS['pc_unlogged_custom_redirect']) ? true : false; if ($is_unl_custom_redir) { $redirect_url = $GLOBALS['pc_unlogged_custom_redirect']; // avoid redirect loops if ($redirect_url == pc_curr_url()) { return false; } } if (($post->ID != $orig_redirect_val || $is_unl_custom_redir) && !$result) { // last restricted page redirect system if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '' && !$is_unl_custom_redir) { $_SESSION['pc_last_restricted'] = pc_curr_url(); } header('location: ' . $redirect_url); die; } } ////////////////////////////////////////////////////////////// // if is category or archive if (is_category() || is_archive()) { $cat_id = get_query_var('cat'); // know which taxonomy is involved foreach (pc_affected_tax() as $tax) { $cat_data = get_term_by('id', $cat_id, $tax); if ($cat_data != false) { if (!pc_redirect_check('category', $cat_data, $tax)) { if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '') { $_SESSION['pc_last_restricted'] = pc_curr_url(); } header('location: ' . $redirect_url); die; } break; } } } ////////////////////////////////////////////////////////////// // WooCommerce category if (function_exists('is_product_category') && is_product_category()) { $cat_slug = get_query_var('product_cat'); $cat_data = get_term_by('slug', $cat_slug, 'product_cat'); if ($cat_data != false) { if (!pc_redirect_check('category', $cat_data, 'product_cat')) { if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '') { $_SESSION['pc_last_restricted'] = pc_curr_url(); } header('location: ' . $redirect_url); die; } } } ////////////////////////////////////////////////////////////// // if is a single post (check category restriction) if (is_single()) { global $post; include_once PC_DIR . '/functions.php'; // search post terms in every involved taxonomy foreach (pc_affected_tax() as $tax) { $terms = wp_get_post_terms($post->ID, $tax); if (is_array($terms)) { foreach ($terms as $term) { $cat_data = get_term_by('id', $term->term_id, $tax); if (!pc_redirect_check('category', $cat_data, $tax)) { if (get_option('pg_redirect_back_after_login') && pc_curr_url() != '') { $_SESSION['pc_last_restricted'] = pc_curr_url(); } header('location: ' . $redirect_url); die; } } } } } ////////////////////////////////////////////////////////////// // PC-FILTER custom restriction (URL based) - associative array('url' => array('allowed', 'blocked')) $restrictet_urls = apply_filters('pc_custom_restriction', array()); if (is_array($restrictet_urls) && count($restrictet_urls)) { $curr_url = pc_curr_url(); foreach ((array) $restrictet_urls as $url => $val) { if (isset($val['allowed']) && $curr_url == $url) { $blocked = isset($val['blocked']) ? $val['blocked'] : ''; if (pc_user_check($val['allowed'], $blocked, true) !== 1) { header('location: ' . $redirect_url); die; } } } } } }
function pc_avoid_pvtcontent_del() { include_once PC_DIR . '/functions.php'; $curr_url = pc_curr_url(); if (strpos($curr_url, 'users.php') !== false && strpos($curr_url, 'action=delete') !== false) { global $pc_wp_user; if (isset($_REQUEST['user'])) { $users = array($_REQUEST['user']); } elseif (isset($_REQUEST['users'])) { $users = $_REQUEST['users']; } foreach ($users as $user_id) { $user_data = get_userdata($user_id); if (isset($user_data->caps['pvtcontent'])) { ob_start(); ob_clean(); header('location: ' . admin_url('users.php')); break; } } } }