Ejemplo n.º 1
0
 public function protectSubscriptionPages()
 {
     global $wp_query;
     // Keep visitors who are not logged in from seeing private pages
     if (!isset($wp_query->tax_query)) {
         $pid = isset($wp_query->post->ID) ? $wp_query->post->ID : NULL;
         Cart66AccessManager::verifyPageAccessRights($pid);
         // block subscription pages from non-subscribers
         $accountId = Cart66Common::isLoggedIn() ? Cart66Session::get('Cart66AccountId') : 0;
         $account = new Cart66Account($accountId);
         // Get a list of the required subscription ids
         $requiredFeatureLevels = Cart66AccessManager::getRequiredFeatureLevelsForPage($pid);
         if (count($requiredFeatureLevels)) {
             // Check to see if the logged in user has one of the required subscriptions
             Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] protectSubscriptionPages: Page access looking for " . $account->getFeatureLevel() . " in: " . print_r($requiredFeatureLevels, true));
             if (!in_array($account->getFeatureLevel(), $requiredFeatureLevels) || !$account->isActive()) {
                 Cart66Session::set('Cart66AccessDeniedRedirect', Cart66Common::getCurrentPageUrl());
                 wp_redirect(Cart66AccessManager::getDeniedLink());
                 exit;
             }
         }
     } else {
         $exclude = false;
         $meta_query = array();
         //echo nl2br(print_r($wp_query->posts, true));
         foreach ($wp_query->posts as $index => $p) {
             $pid = isset($p->ID) ? $p->ID : NULL;
             // block subscription pages from non-subscribers
             $accountId = Cart66Common::isLoggedIn() ? Cart66Session::get('Cart66AccountId') : 0;
             $account = new Cart66Account($accountId);
             // Get a list of the required subscription ids
             $requiredFeatureLevels = Cart66AccessManager::getRequiredFeatureLevelsForPage($pid);
             if (count($requiredFeatureLevels)) {
                 // Check to see if the logged in user has one of the required subscriptions
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] protectSubscriptionPages: Page access looking for " . $account->getFeatureLevel() . " in: " . print_r($requiredFeatureLevels, true));
                 if (!in_array($account->getFeatureLevel(), $requiredFeatureLevels) || !$account->isActive()) {
                     $exclude = false;
                     if (!Cart66Setting::getValue('remove_posts_from_taxonomy')) {
                         // Set message for when visitor is not logged in
                         if (!($message = Cart66Setting::getValue('post_not_logged_in'))) {
                             $message = __("You must be logged in to view this", "cart66") . " " . $p->post_type . ".";
                         }
                         if (Cart66Common::isLoggedIn()) {
                             // Set message for insuficient access rights
                             if (!($message = Cart66Setting::getValue('post_access_denied'))) {
                                 $message = __("Your current subscription does not allow you to view this", "cart66") . " " . $p->post_type . ".";
                             }
                         }
                         $p->post_content = $message;
                         $p->comment_status = 'closed';
                     } else {
                         $exclude = true;
                     }
                 }
             }
         }
         if ($exclude) {
             global $wpdb;
             $post_id = $wpdb->get_col("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_cart66_subscription'");
             $args = array('post__not_in' => $post_id);
             $args = array_merge($args, $wp_query->query);
             query_posts($args);
         }
     }
 }