Exemple #1
0
 /**
  * Filters protected pages from array.
  *
  * @action get_pages 1
  *
  * @param array $pages The array of pages.
  * @return array Filtered array which doesn't include prohibited pages.
  */
 public function add_unviewable_pages_menu($pages)
 {
     $page_ids = $this->get_dripped_page_ids($this->data);
     foreach ((array) $pages as $key => $page) {
         $special = membership_is_account_page($page->ID) || membership_is_special_page($page->ID, false);
         if (in_array($page->ID, $page_ids) || in_array($page->post_parent, $page_ids)) {
             if (!$special) {
                 unset($pages[$key]);
             }
         }
     }
     return $pages;
 }
Exemple #2
0
 /**
  * Redirects to protection page if need be.
  *
  * @since 3.5
  * @action the_posts 1
  *
  * @access public
  * @global array $M_options The plguins options.
  * @param array $posts The array of posts.
  * @return array The array of posts.
  */
 public function show_noaccess_page($posts, $wp_query)
 {
     //only for main query
     if (!$wp_query->is_main_query()) {
         return $posts;
     }
     global $M_options;
     if (empty($posts)) {
         // We don't have any posts, so we should just redirect to the no content page.
         if (!empty($M_options['nocontent_page']) && !headers_sent()) {
             // grab the content form the no content page
             wp_safe_redirect(get_permalink(absint($M_options['nocontent_page'])));
             exit;
         } else {
             return $posts;
         }
     }
     if (count($posts) == 1 && isset($posts[0]->post_type) && $posts[0]->post_type == 'page') {
         // We are on a page so get the first page and then check for ones we want to allow
         $page = $posts[0];
         if (membership_is_special_page($page->ID, false)) {
             return $posts;
         }
         // We are still here so we may be at a page that we shouldn't be able to see
         if (!empty($M_options['nocontent_page']) && $page->ID != $M_options['nocontent_page'] && !headers_sent()) {
             // grab the content form the no content page
             wp_safe_redirect(get_permalink(absint($M_options['nocontent_page'])));
             exit;
         }
         return $posts;
     } else {
         // We could be on a posts page / or on a single post.
         if (count($posts) == 1) {
             // We could be on a single posts page, or only have the one post to view
             if (isset($posts[0]->post_type) && $posts[0]->post_type != 'nav_menu_item') {
                 // We'll redirect if this isn't a navigation menu item
                 $post = $posts[0];
                 if (!empty($M_options['nocontent_page']) && isset($post->ID) && $post->ID != $M_options['nocontent_page'] && !headers_sent()) {
                     // grab the content form the no content page
                     wp_safe_redirect(get_permalink(absint($M_options['nocontent_page'])));
                     exit;
                 }
                 return $posts;
             }
         } else {
             // Check the first post in the list
             if (isset($posts[0]->post_type) && $posts[0]->post_type != 'nav_menu_item') {
                 // We'll redirect if this isn't a navigation menu item
                 $post = $posts[0];
                 if (!empty($M_options['nocontent_page']) && isset($post->ID) && $post->ID != $M_options['nocontent_page'] && !headers_sent()) {
                     // grab the content form the no content page
                     wp_safe_redirect(get_permalink(absint($M_options['nocontent_page'])));
                     exit;
                 }
                 return $posts;
             }
         }
     }
     // If we've reached here then something weird has happened :/
     return $posts;
 }