/** * optimizeMember's Security Gate ( protects WordPress content ). * * @package optimizeMember\Security * @since 3.5 * * @attaches-to ``add_action("wp");`` * * @return null May redirect a browser *(exiting script execution)*, when/if content is NOT available to the current User/Member. */ public static function security_gate() { do_action("ws_plugin__optimizemember_before_security_gate", get_defined_vars()); /**/ if (is_category()) { /* Categories & other inclusives. */ c_ws_plugin__optimizemember_catgs::check_catg_level_access(); } else { if (is_tag()) { /* Post/Page Tags & other inclusives. */ c_ws_plugin__optimizemember_ptags::check_ptag_level_access(); } else { if (is_single()) { /* All Posts & other inclusives. */ c_ws_plugin__optimizemember_posts::check_post_level_access(); } else { if (is_page()) { /* All Pages & other inclusives. */ c_ws_plugin__optimizemember_pages::check_page_level_access(); } else { /* Else, we simply look at URIs & other inclusives. */ c_ws_plugin__optimizemember_ruris::check_ruri_level_access(); } } } } /**/ do_action("ws_plugin__optimizemember_after_security_gate", get_defined_vars()); /**/ return; /* Return for uniformity. */ }
/** * Handles Category Level Access *( for current page )*. * * @package optimizeMember\Categories * @since 3.5 * * @return null Or exits script execution after redirection. */ public static function check_catg_level_access() { global $post; /* ``get_the_ID()`` is NOT available outside The Loop. */ /**/ do_action("ws_plugin__optimizemember_before_check_catg_level_access", get_defined_vars()); /**/ $excluded = apply_filters("ws_plugin__optimizemember_check_catg_level_access_excluded", false, get_defined_vars()); /**/ if (!$excluded && is_category() && ($cat_id = get_query_var("cat")) && ($cat_id = (int) $cat_id) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"]) { if (!c_ws_plugin__optimizemember_systematics::is_wp_systematic_use_page()) { $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) ? $user : false; /* Current User's object. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["login_redirection_override"] && ($login_redirection_uri = c_ws_plugin__optimizemember_login_redirects::login_redirection_uri($user, "root-returns-false")) && preg_match("/^" . preg_quote($login_redirection_uri, "/") . "\$/", $_SERVER["REQUEST_URI"]) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level0"))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", 0, $_SERVER["REQUEST_URI"], "sys") . exit; } else { if (!c_ws_plugin__optimizemember_systematics::is_systematic_use_page()) { for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"] === "all" && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", $n, $_SERVER["REQUEST_URI"]) . exit; } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"] && in_array($cat_id, $catgs = preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"])) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", $n, $_SERVER["REQUEST_URI"]) . exit; } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"]) { /* Check Category ancestry. */ foreach (preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"]) as $catg) { if ($catg && cat_is_ancestor_of($catg, $cat_id) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", $n, $_SERVER["REQUEST_URI"]) . exit; } } } } } } /**/ for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"]) { /* URIs configured at this Level? */ /**/ foreach (preg_split("/[\r\n\t]+/", c_ws_plugin__optimizemember_ruris::fill_ruri_level_access_rc_vars($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"], $user)) as $str) { if ($str && preg_match("/" . preg_quote($str, "/") . "/", $_SERVER["REQUEST_URI"]) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("catg", $cat_id, "level", $n, $_SERVER["REQUEST_URI"], "ruri") . exit; } } } } } } /**/ do_action("ws_plugin__optimizemember_during_check_catg_level_access", get_defined_vars()); } } /**/ do_action("ws_plugin__optimizemember_after_check_catg_level_access", get_defined_vars()); /**/ return; /* For uniformity. */ }
/** * Handles Category Level Access *( for specific Categories )*. * * @package optimizeMember\Categories * @since 3.5 * * @param int|str $cat_id Numeric Category ID. * @param bool $check_user Test permissions against the current User? Defaults to true. * @return null|array Non-empty array ( with details ) if access is denied, else null if access is allowed. */ public static function check_specific_catg_level_access($cat_id = FALSE, $check_user = TRUE) { do_action("ws_plugin__optimizemember_before_check_specific_catg_level_access", get_defined_vars()); /**/ $excluded = apply_filters("ws_plugin__optimizemember_check_specific_catg_level_access_excluded", false, get_defined_vars()); /**/ if (!$excluded && is_numeric($cat_id) && ($cat_id = (int) $cat_id) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"]) { $cat_uri = c_ws_plugin__optimizemember_utils_urls::parse_uri(get_category_link($cat_id)); /* Get a full valid URI for this Category. */ /**/ if (!c_ws_plugin__optimizemember_systematics_sp::is_wp_systematic_use_specific_page(null, $cat_uri)) { $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) ? $user : false; /* Current User's object. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["login_redirection_override"] && ($login_redirection_uri = c_ws_plugin__optimizemember_login_redirects::login_redirection_uri($user, "root-returns-false")) && preg_match("/^" . preg_quote($login_redirection_uri, "/") . "\$/", $cat_uri) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level0"))) { return apply_filters("ws_plugin__optimizemember_check_specific_catg_level_access", array("optimizemember_level_req" => 0), get_defined_vars()); } else { if (!c_ws_plugin__optimizemember_systematics_sp::is_systematic_use_specific_page(null, $cat_uri)) { for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"] === "all" && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_catg_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"] && in_array($cat_id, $catgs = preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"])) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_catg_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"]) { /* Check Category ancestry. */ foreach (preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"]) as $catg) { if ($catg && cat_is_ancestor_of($catg, $cat_id) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_catg_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } } } } } } /**/ for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"]) { /* URIs configured at this Level? */ /**/ foreach (preg_split("/[\r\n\t]+/", c_ws_plugin__optimizemember_ruris::fill_ruri_level_access_rc_vars($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"], $user)) as $str) { if ($str && preg_match("/" . preg_quote($str, "/") . "/", $cat_uri) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_catg_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } } } } } } /**/ do_action("ws_plugin__optimizemember_during_check_specific_catg_level_access", get_defined_vars()); } } /**/ return apply_filters("ws_plugin__optimizemember_check_specific_catg_level_access", null, get_defined_vars()); }
/** * Handles Page Level Access *( for specific Pages )*. * * @package optimizeMember\Pages * @since 3.5 * * @param int|str $page_id Numeric Page ID. * @param bool $check_user Test permissions against the current User? Defaults to true. * @return null|array Non-empty array ( with details ) if access is denied, else null if access is allowed. * * @todo Provide more information in the return array ( like MOP Vars ). */ public static function check_specific_page_level_access($page_id = FALSE, $check_user = TRUE) { do_action("ws_plugin__optimizemember_before_check_specific_page_level_access", get_defined_vars()); /**/ $excluded = apply_filters("ws_plugin__optimizemember_check_specific_page_level_access_excluded", false, get_defined_vars()); /**/ if (!$excluded && is_numeric($page_id) && ($page_id = (int) $page_id) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"]) { $page_uri = c_ws_plugin__optimizemember_utils_urls::parse_uri(get_page_link($page_id)); /* Get a full valid URI for this Page now. */ /**/ if (!c_ws_plugin__optimizemember_systematics_sp::is_wp_systematic_use_specific_page($page_id, $page_uri)) { $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) ? $user : false; /* Current User's object. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["login_welcome_page"] && $page_id === (int) $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["login_welcome_page"] && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level0")) && $page_id !== (int) $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"]) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_level_req" => 0), get_defined_vars()); } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["login_redirection_override"] && ($login_redirection_uri = c_ws_plugin__optimizemember_login_redirects::login_redirection_uri($user, "root-returns-false")) && preg_match("/^" . preg_quote($login_redirection_uri, "/") . "\$/", $page_uri) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level0")) && $page_id !== (int) $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"]) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_level_req" => 0), get_defined_vars()); } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["file_download_limit_exceeded_page"] && $page_id === (int) $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["file_download_limit_exceeded_page"] && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level0")) && $page_id !== (int) $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"]) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_level_req" => 0), get_defined_vars()); } else { if (!c_ws_plugin__optimizemember_systematics_sp::is_systematic_use_specific_page($page_id, $page_uri)) { for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_pages"] === "all" && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } else { if (strpos($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"], "all-") !== false && in_array("all-pages", preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"])) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_pages"] && in_array($page_id, preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_pages"])) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } } } } /**/ if (has_tag("", $page_id)) { for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"] === "all" && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"] && has_tag(preg_split("/[\r\n\t;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"]), $page_id) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } } } } /**/ for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"]) { /* URIs configured at this Level? */ /**/ foreach (preg_split("/[\r\n\t]+/", c_ws_plugin__optimizemember_ruris::fill_ruri_level_access_rc_vars($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"], $user)) as $str) { if ($str && preg_match("/" . preg_quote($str, "/") . "/", $page_uri) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } } } } /**/ if (is_array($ccaps_req = get_post_meta($page_id, "optimizemember_ccaps_req", true)) && !empty($ccaps_req)) { foreach ($ccaps_req as $ccap) { /* The ``$user`` MUST satisfy ALL Custom Capabilities. */ if (strlen($ccap) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_ccap_" . $ccap))) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_ccap_req" => $ccap), get_defined_vars()); } } } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["specific_ids"] && in_array($page_id, preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["specific_ids"])) && (!$check_user || !c_ws_plugin__optimizemember_sp_access::sp_access($page_id, "read-only"))) { return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", array("optimizemember_sp_req" => $page_id), get_defined_vars()); } } } } } /**/ do_action("ws_plugin__optimizemember_during_check_specific_page_level_access", get_defined_vars()); } } /**/ return apply_filters("ws_plugin__optimizemember_check_specific_page_level_access", null, get_defined_vars()); }
/** * Handles Post Level Access permissions *( for current Post )*. * * @package optimizeMember\Posts * @since 3.5 * * @return null Or exits script execution after redirection. */ public static function check_post_level_access() { global $post; /* ``get_the_ID()`` unavailable outside The Loop. */ /**/ do_action("ws_plugin__optimizemember_before_check_post_level_access", get_defined_vars()); /**/ $excluded = apply_filters("ws_plugin__optimizemember_check_post_level_access_excluded", false, get_defined_vars()); /**/ if (!$excluded && is_single() && is_object($post) && !empty($post->ID) && ($post_id = (int) $post->ID) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"]) { if (!c_ws_plugin__optimizemember_systematics::is_wp_systematic_use_page()) { $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) ? $user : false; /* Current User's object. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["login_redirection_override"] && ($login_redirection_uri = c_ws_plugin__optimizemember_login_redirects::login_redirection_uri($user, "root-returns-false")) && preg_match("/^" . preg_quote($login_redirection_uri, "/") . "\$/", $_SERVER["REQUEST_URI"]) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level0"))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "level", 0, $_SERVER["REQUEST_URI"], "sys") . exit; } else { if (!c_ws_plugin__optimizemember_systematics::is_systematic_use_page()) { for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"] === "all" && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "level", $n, $_SERVER["REQUEST_URI"]) . exit; } else { if (strpos($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"], "all-") !== false && in_array("all-" . $post->post_type . "s", preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"])) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "level", $n, $_SERVER["REQUEST_URI"]) . exit; } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"] && in_array($post_id, preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_posts"])) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "level", $n, $_SERVER["REQUEST_URI"]) . exit; } } } } /**/ for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"] === "all" && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "level", $n, $_SERVER["REQUEST_URI"], "catg") . exit; } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"] && (in_category($catgs = preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_catgs"]), $post_id) || c_ws_plugin__optimizemember_utils_conds::in_descendant_category($catgs, $post_id)) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "level", $n, $_SERVER["REQUEST_URI"], "catg") . exit; } } } /**/ if (has_tag()) { for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"] === "all" && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "level", $n, $_SERVER["REQUEST_URI"], "ptag") . exit; } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"] && has_tag(preg_split("/[\r\n\t;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"])) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "level", $n, $_SERVER["REQUEST_URI"], "ptag") . exit; } } } } /**/ for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"]) { /* URIs configured at this Level? */ /**/ foreach (preg_split("/[\r\n\t]+/", c_ws_plugin__optimizemember_ruris::fill_ruri_level_access_rc_vars($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"], $user)) as $str) { if ($str && preg_match("/" . preg_quote($str, "/") . "/", $_SERVER["REQUEST_URI"]) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && (!$user || !$user->has_cap("access_optimizemember_level" . $n))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "level", $n, $_SERVER["REQUEST_URI"], "ruri") . exit; } } } } /**/ if (is_array($ccaps_req = get_post_meta($post_id, "optimizemember_ccaps_req", true)) && !empty($ccaps_req) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true)) { foreach ($ccaps_req as $ccap) { /* The ``$user`` MUST satisfy ALL Custom Capability requirements. Stored as an array of Custom Capabilities. */ if (strlen($ccap) && (!$user || !$user->has_cap("access_optimizemember_ccap_" . $ccap))) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "ccap", $ccap, $_SERVER["REQUEST_URI"], "ccap") . exit; } } } /**/ /**/ $dripDays = get_post_meta($page_id, "optimizemember_drip_days", true); if (!empty($dripDays) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true)) { $dripUrl = get_post_meta($page_id, "optimizemember_drip_redirect_url", true); $time = optimizemember_paid_registration_time('level' . OPTIMIZEMEMBER_CURRENT_USER_ACCESS_LEVEL); if ($time && $time >= ($_days_ago = strtotime("-{$dripDays} days")) && !current_user_can('manage_options')) { if (!empty($dripUrl)) { wp_redirect($dripUrl); exit; } else { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("page", $page_id, "drip_days", $dripDays, $_SERVER["REQUEST_URI"], "drip_days") . exit; } } } /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["specific_ids"] && in_array($post_id, preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["specific_ids"])) && c_ws_plugin__optimizemember_no_cache::no_cache_constants(true) && !c_ws_plugin__optimizemember_sp_access::sp_access($post_id)) { c_ws_plugin__optimizemember_mo_page::wp_redirect_w_mop_vars("post", $post_id, "sp", $post_id, $_SERVER["REQUEST_URI"], "sp") . exit; } } } /**/ do_action("ws_plugin__optimizemember_during_check_post_level_access", get_defined_vars()); } } /**/ do_action("ws_plugin__optimizemember_after_check_post_level_access", get_defined_vars()); /**/ return; /* For uniformity. */ }
/** * Handles Tag Level Access *( for specific Tags )*. * * @package optimizeMember\Tags * @since 3.5 * * @param int|str $_tag Numeric Tag ID, Tag Slug, or Tag Name. * @param bool $check_user Test permissions against the current User? Defaults to true. * @return null|array Non-empty array ( with details ) if access is denied, else null if access is allowed. */ public static function check_specific_ptag_level_access($_tag = FALSE, $check_user = TRUE) { do_action("ws_plugin__optimizemember_before_check_specific_ptag_level_access", get_defined_vars()); /**/ if ($_tag && is_numeric($_tag) && is_object($term = get_term_by("id", $_tag, "post_tag"))) { $tag_id = (int) $_tag; /* Need ``$tag_id``, ``$tag_slug``, and also the ``$tag_name``. */ $tag_slug = $term->slug; /* Tag slug. */ $tag_name = $term->name; /* Tag name. */ } else { if ($_tag && is_string($_tag) && is_object($term = get_term_by("name", $_tag, "post_tag"))) { $tag_name = $_tag; /* Need ``$tag_id``, ``$tag_slug``, and also the ``$tag_name``. */ $tag_id = (int) $term->term_id; /* Tag ID. */ $tag_slug = $term->slug; /* Tag slug. */ } else { if ($_tag && is_string($_tag) && is_object($term = get_term_by("slug", $_tag, "post_tag"))) { $tag_slug = $_tag; /* Need ``$tag_id``, ``$tag_slug``, and also the ``$tag_name``. */ $tag_id = (int) $term->term_id; /* Tag ID. */ $tag_name = $term->name; /* Tag name. */ } } } /**/ $excluded = apply_filters("ws_plugin__optimizemember_check_specific_ptag_level_access_excluded", false, get_defined_vars()); /**/ if (!$excluded && !empty($tag_id) && !empty($tag_slug) && !empty($tag_name) && $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["membership_options_page"]) { $tag_uri = c_ws_plugin__optimizemember_utils_urls::parse_uri(get_tag_link($tag_id)); /* Get a full valid URI for this Tag. */ /**/ if (!c_ws_plugin__optimizemember_systematics_sp::is_wp_systematic_use_specific_page(null, $tag_uri)) { $user = is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID) ? $user : false; /* Current User's object. */ /**/ if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["login_redirection_override"] && ($login_redirection_uri = c_ws_plugin__optimizemember_login_redirects::login_redirection_uri($user, "root-returns-false")) && preg_match("/^" . preg_quote($login_redirection_uri, "/") . "\$/", $tag_uri) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level0"))) { return apply_filters("ws_plugin__optimizemember_check_specific_ptag_level_access", array("optimizemember_level_req" => 0), get_defined_vars()); } else { if (!c_ws_plugin__optimizemember_systematics_sp::is_systematic_use_specific_page(null, $tag_uri)) { for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"] === "all" && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_ptag_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } else { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"] && (in_array($tag_name, $tags = preg_split("/[\r\n\t;,]+/", $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ptags"])) || in_array($tag_slug, $tags)) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_ptag_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } } } /**/ for ($n = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["c"]["levels"]; $n >= 0; $n--) { if ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"]) { /* URIs configured at this Level? */ /**/ foreach (preg_split("/[\r\n\t]+/", c_ws_plugin__optimizemember_ruris::fill_ruri_level_access_rc_vars($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["level" . $n . "_ruris"], $user)) as $str) { if ($str && preg_match("/" . preg_quote($str, "/") . "/", $tag_uri) && (!$check_user || !$user || !$user->has_cap("access_optimizemember_level" . $n))) { return apply_filters("ws_plugin__optimizemember_check_specific_ptag_level_access", array("optimizemember_level_req" => $n), get_defined_vars()); } } } } } } /**/ do_action("ws_plugin__optimizemember_during_check_specific_ptag_level_access", get_defined_vars()); } } /**/ return apply_filters("ws_plugin__optimizemember_check_specific_ptag_level_access", null, get_defined_vars()); }