function upme_process_specific_sub_parent_pages_restriction($rule) { global $post; $restricted_pages = (array) $rule['site_content_page_restrictions']; $recursive_status = isset($rule['site_content_page_recursive_status']) ? $rule['site_content_page_recursive_status'] : 0; if ($recursive_status) { $parent_page_ids = upme_top_ancestors(array()); if (is_page() && count($parent_page_ids) != '0') { foreach ($parent_page_ids as $parent_ID) { if (in_array($parent_ID, $restricted_pages)) { return false; } } return true; } else { if (is_page() && count($parent_page_ids) == '0' && in_array($post->ID, $restricted_pages)) { return false; } else { return true; } } } else { $parent_page_id = upme_is_subpage(); if (is_page() && (in_array($post->ID, $restricted_pages) || $parent_page_id != '0' && in_array($parent_page_id, $restricted_pages))) { return false; } else { return true; } } }
function upme_top_ancestors($parents, $post_id = '') { global $post; $post_id = $post_id != '' ? $post_id : $post->ID; $current = get_post($post_id); if (is_page() && $current->post_parent) { array_push($parents, $current->post_parent); return upme_top_ancestors($parents, $current->post_parent); } else { return $parents; } }