public static function remove_restricted_posts($posts, $query = false) { return $posts; echo $query->request; exit; if (!is_singular() && !is_admin()) { $new_posts = array(); foreach ($posts as $post) { // The page is members only and we do NOT have access to it if (get_post_meta($post->ID, '_wpac_is_members_only', true) && !WordPressAccessControl::check_conditions($post->ID)) { if (get_post_meta($post->ID, '_wpac_show_in_search', true) != 1) { continue; } } // The page is non-members only and we do NOT have access to it if (get_post_meta($post->ID, '_wpac_is_nonmembers_only', true) && !WordPressAccessControl::check_conditions($post->ID)) { if (get_post_meta($post->ID, '_wpac_show_in_search', true) != 1) { continue; } } // Remove results where the search term is in a [member] or [nonmember] tag and we don't have access $st = get_search_query(); $content = do_shortcode($post->post_content); if (!empty($st) && is_search() && !stristr($content, $st)) { continue; } $new_posts[] = $post; } $query->found_posts = count($new_posts); $query->max_num_pages = ceil(count($new_posts) / $query->query_vars['posts_per_page']); $query->posts = $new_posts; $query->post_count = count($new_posts); return $new_posts; } return $posts; }
/** * Recursively removes any child nav menu item that the user doesn't have the * correct permission to view. * * @param integer $id * @param array $children */ protected function filter_children($id, &$children_elements) { if (isset($children_elements[$id])) { foreach ($children_elements[$id] as $index => $element) { // If it's a nav menu item, check permissions against the post/page that the // nav menu item points to, otherwise check the element itself. if (isset($element->post_type) && $element->post_type == 'nav_menu_item') { $object_id = $element->object_id; } else { $object_id = $element->{$this->db_fields['id']}; } // Make sure the page isn't an orphan (e.g. this is a page walker and the // element was a child of a members only page that got removed, so we // shouldn't show it) if (WordPressAccessControl::check_conditions($object_id) || get_option('wpac_show_in_menus', 'with_access') == 'always') { if (in_array($element->{$this->db_fields['parent']}, $this->track_ids) || $element->{$this->db_fields['parent']} == 0) { $this->track_ids[] = $element->{$this->db_fields['id']}; $this->filter_children($element->{$this->db_fields['id']}, $children_elements); } else { $this->truncate_children($element->{$this->db_fields['id']}, $children_elements); unset($children_elements[$id][$index]); } } else { $this->truncate_children($element->{$this->db_fields['id']}, $children_elements); unset($children_elements[$id][$index]); } } } }