function initialise_membership_protection($wp)
 {
     global $user, $member, $M_options, $M_Rules, $wp_query, $wp_rewrite, $M_active;
     // Set up some common defaults
     static $initialised = false;
     if ($initialised) {
         // ensure that this is only called once, so return if we've been here already.
         return;
     }
     if (empty($user) || !method_exists($user, 'has_cap')) {
         $user = wp_get_current_user();
     }
     if ($M_active == 'no') {
         // The plugin isn't active so just return
         return;
     }
     if (!method_exists($user, 'has_cap') || $user->has_cap('membershipadmin')) {
         // Admins can see everything - unless we have a cookie set to limit viewing
         if (!empty($_COOKIE['membershipuselevel']) && $_COOKIE['membershipuselevel'] != '0') {
             $level_id = (int) $_COOKIE['membershipuselevel'];
             $member = new M_Membership($user->ID);
             $member->assign_level($level_id, true);
         } else {
             return;
         }
     } else {
         // We are not a membershipadmin user
         if (!empty($wp->query_vars['feed'])) {
             // This is a feed access
             // Set the feed rules
             if (isset($_GET['k'])) {
                 $key = $_GET['k'];
                 $user_id = $this->find_user_from_key($key);
                 $user_id = (int) $user_id;
                 if ($user_id > 0) {
                     // Logged in - check there settings, if they have any.
                     $member = new M_Membership($user_id);
                     // Load the levels for this member - and associated rules
                     $member->load_levels(true);
                 } else {
                     $member = new M_Membership(false);
                     if (isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) {
                         $member->assign_level($M_options['strangerlevel'], true);
                     } else {
                         // This user can't access anything on the site - show a blank feed.
                         add_filter('the_posts', array(&$this, 'show_noaccess_feed'), 1);
                     }
                 }
             } else {
                 // not passing a key so limit based on stranger settings
                 // need to grab the stranger settings
                 $member = new M_Membership($user->ID);
                 if (isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) {
                     $member->assign_level($M_options['strangerlevel'], true);
                 } else {
                     // This user can't access anything on the site - show a blank feed.
                     add_filter('the_posts', array(&$this, 'show_noaccess_feed'), 1);
                 }
             }
         } else {
             // Users
             $member = new M_Membership($user->ID);
             if ($user->ID > 0 && $member->has_levels()) {
                 // Load the levels for this member - and associated rules
                 $member->load_levels(true);
             } else {
                 // not logged in so limit based on stranger settings
                 // need to grab the stranger settings
                 if (isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) {
                     $member->assign_level($M_options['strangerlevel'], true);
                 } else {
                     // This user can't access anything on the site - .
                     add_filter('comments_open', array(&$this, 'close_comments'), 99, 2);
                     // Changed for this version to see if it helps to get around changed in WP 3.5
                     //add_action('pre_get_posts', array(&$this, 'show_noaccess_page'), 1 );
                     add_action('the_posts', array(&$this, 'show_noaccess_page'), 1);
                     //the_posts
                     // Hide all pages from menus - except the signup one
                     add_filter('get_pages', array(&$this, 'remove_pages_menu'));
                     // Hide all categories from lists
                     add_filter('get_terms', array(&$this, 'remove_categories'), 1, 3);
                 }
             }
         }
     }
     // Set up the level shortcodes here
     $shortcodes = apply_filters('membership_level_shortcodes', array());
     if (!empty($shortcodes)) {
         foreach ($shortcodes as $key => $value) {
             if (!empty($value)) {
                 if ($member->has_level($key)) {
                     // member is on this level so can see the content
                     add_shortcode(stripslashes(trim($value)), array(&$this, 'do_level_shortcode'));
                 } else {
                     // member isn't on this level and so can't see the content
                     add_shortcode(stripslashes(trim($value)), array(&$this, 'do_levelprotected_shortcode'));
                 }
             }
         }
     }
     $shortcodes = apply_filters('membership_not_level_shortcodes', array());
     if (!empty($shortcodes)) {
         foreach ($shortcodes as $key => $value) {
             if (!empty($value)) {
                 if (!$member->has_level($key)) {
                     // member is on this level so can see the content
                     add_shortcode(stripslashes(trim($value)), array(&$this, 'do_level_shortcode'));
                 } else {
                     // member isn't on this level and so can't see the content
                     add_shortcode(stripslashes(trim($value)), array(&$this, 'do_levelprotected_shortcode'));
                 }
             }
         }
     }
     do_action('membership-add-shortcodes');
     // Set the initialisation status
     $initialised = true;
 }
 function initialise_membership_protection($nxt)
 {
     global $user, $member, $M_options, $M_Rules, $nxt_query, $nxt_rewrite, $M_active;
     // Set up some common defaults
     static $initialised = false;
     if ($initialised) {
         // ensure that this is only called once, so return if we've been here already.
         return;
     }
     if (empty($user) || !method_exists($user, 'has_cap')) {
         $user = nxt_get_current_user();
     }
     if (!method_exists($user, 'has_cap') || $user->has_cap('membershipadmin') || $M_active == 'no') {
         // Admins can see everything
         return;
     }
     if (!empty($nxt->query_vars['feed'])) {
         // This is a feed access
         // Set the feed rules
         if (isset($_GET['k'])) {
             $key = $_GET['k'];
             $user_id = $this->find_user_from_key($key);
             $user_id = (int) $user_id;
             if ($user_id > 0) {
                 // Logged in - check there settings, if they have any.
                 $member = new M_Membership($user_id);
                 // Load the levels for this member - and associated rules
                 $member->load_levels(true);
             } else {
                 $member = new M_Membership(false);
                 if (isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) {
                     $member->assign_level($M_options['strangerlevel'], true);
                 } else {
                     // This user can't access anything on the site - show a blank feed.
                     add_filter('the_posts', array(&$this, 'show_noaccess_feed'), 1);
                 }
             }
         } else {
             // not passing a key so limit based on stranger settings
             // need to grab the stranger settings
             $member = new M_Membership($user->ID);
             if (isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) {
                 $member->assign_level($M_options['strangerlevel'], true);
             } else {
                 // This user can't access anything on the site - show a blank feed.
                 add_filter('the_posts', array(&$this, 'show_noaccess_feed'), 1);
             }
         }
     } else {
         // Users
         $member = new M_Membership($user->ID);
         if ($user->ID > 0 && $member->has_levels()) {
             // Load the levels for this member - and associated rules
             $member->load_levels(true);
         } else {
             // not logged in so limit based on stranger settings
             // need to grab the stranger settings
             if (isset($M_options['strangerlevel']) && $M_options['strangerlevel'] != 0) {
                 $member->assign_level($M_options['strangerlevel'], true);
             } else {
                 // This user can't access anything on the site - .
                 add_filter('comments_open', array(&$this, 'close_comments'), 99, 2);
                 add_action('pre_get_posts', array(&$this, 'show_noaccess_page'), 1);
                 // Hide all pages from menus - except the signup one
                 add_filter('get_pages', array(&$this, 'remove_pages_menu'));
                 // Hide all categories from lists
                 add_filter('get_terms', array(&$this, 'remove_categories'), 1, 3);
             }
         }
     }
     // Set the initialisation status
     $initialised = true;
 }