static function get_dates($level_id, $user_id = false) { global $wpdb; if (empty($user_id)) { $user_id = Membership_Plugin::current_member()->ID; } $user_id = (int) $user_id; $level_id = (int) $level_id; // $sql = $wpdb->prepare( "SELECT startdate, updateddate, expirydate FROM '%s' WHERE user_id=%d AND level_id=%d", MEMBERSHIP_TABLE_RELATIONS, $user_id, $level_id ); $sql = $wpdb->prepare("SELECT * FROM " . MEMBERSHIP_TABLE_RELATIONS . " WHERE user_id=%d AND level_id=%d", $user_id, $level_id); $results = $wpdb->get_results($sql); return $results; }
function current_blog_count() { global $member, $wpdb; $member = Membership_Plugin::current_member(); if (!empty($member) && method_exists($member, 'has_cap')) { // We have a member and it is a correct object $count = 0; $blogs = get_blogs_of_user($member->ID); foreach ($blogs as $blog) { if ($this->is_user_blog_admin($member->ID, $blog->userblog_id)) { $count++; } } return (int) $count; } else { return 0; } }
function check_for_membership_pages($posts) { global $M_options; if (count($posts) != 1) { return $posts; } // We have only the one post, so check if it's one of our pages $post = $posts[0]; if ($post->post_type != 'page') { return $posts; } if (membership_is_registration_page($post->ID, false) || M_contains_schortcode($post->post_content, 'subscriptionform')) { // Redirect members with subscriptions to the subscriptions page if it exists, else account page. global $member; $member = Membership_Plugin::current_member(); if (!empty($member)) { if ($member->has_subscription() && $member->ID != 0 && !isset($_REQUEST['from_subscription'])) { if (!empty($M_options['subscriptions_page'])) { wp_redirect(get_permalink($M_options['subscriptions_page'])); exit; } else { wp_redirect(get_permalink($M_options['account_page'])); exit; } } } add_action('template_redirect', array($this, 'process_subscription_form'), 1); if (strpos($post->post_content, '[subscriptionform]') !== false || strpos($post->post_content, '[renewform]') !== false) { // bail - shortcode found return $posts; } // registration page found - add in the styles if (!current_theme_supports('membership_subscription_form')) { wp_enqueue_style('membership-subscriptionformcss', MEMBERSHIP_ABSURL . 'css/subscriptionform.css', null, Membership_Plugin::VERSION); add_action('wp_head', array($this, 'enqueue_public_form_styles'), 99); $this->enqueue_fancybox_scripts(); } do_action('membership_subscriptionbutton_onpage'); // There is no shortcode content in there, so override remove_filter('the_content', 'wpautop'); } elseif (membership_is_account_page($post->ID, false)) { // account page - check if page contains a shortcode if (strpos($post->post_content, '[accountform]') !== false || strpos($post->post_content, '[upgradeform]') !== false || strpos($post->post_content, '[renewform]') !== false) { // There is content in there with the shortcode so just return it return $posts; } // account page found - add in the styles if (!current_theme_supports('membership_account_form')) { wp_enqueue_style('membership-accountformcss', MEMBERSHIP_ABSURL . 'css/accountform.css', null, Membership_Plugin::VERSION); wp_enqueue_script('membership-accountformjs', MEMBERSHIP_ABSURL . 'js/accountform.js', array('jquery'), Membership_Plugin::VERSION); add_action('wp_head', array($this, 'enqueue_public_form_styles'), 99); } // There is no shortcode in there, so override remove_filter('the_content', 'wpautop'); } elseif (membership_is_subscription_page($post->ID, false)) { // Handle any updates passed $page = isset($_REQUEST['action']) ? addslashes($_REQUEST['action']) : ''; if (empty($page)) { $page = 'renewform'; } if ($page == 'subscriptionsignup') { if (is_user_logged_in()) { $member = current_member(); list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); if (wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id)) { $gateway = $_POST['gateway']; // Join the new subscription $member->create_subscription($sub_id, $gateway); do_action('membership_payment_subscr_signup', $user_id, $sub_id); // Timestamp the update update_user_meta($user_id, '_membership_last_upgraded', time()); // Added another redirect to the same url because the show_no_access filters // have already run on the "parse_request" action (Cole) wp_redirect(M_get_subscription_permalink()); exit; } } else { // check if a custom is posted and of so then process the user if (isset($_POST['custom'])) { list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); if (wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id)) { $gateway = $_POST['gateway']; // Join the new subscription $member = Membership_Plugin::factory()->get_member($user_id); $member->create_subscription($sub_id, $gateway); do_action('membership_payment_subscr_signup', $user_id, $sub_id); // Timestamp the update update_user_meta($user_id, '_membership_last_upgraded', time()); // Added another redirect to the same url because the show_no_access filters // have already run on the "parse_request" action (Cole) wp_redirect(M_get_subscription_permalink()); exit; } } } } // account page - check if page contains a shortcode if (strstr($post->post_content, '[upgradeform]') !== false || strstr($post->post_content, '[renewform]') !== false) { // There is content in there with the shortcode so just return it if (!current_theme_supports('membership_subscription_form')) { $this->enqueue_subscription_scripts(); } return $posts; } // account page found - add in the styles if (!current_theme_supports('membership_account_form')) { $this->enqueue_subscription_scripts(); } // There is no shortcode in there, so override remove_filter('the_content', 'wpautop'); } elseif (membership_is_protected_page($post->ID, false)) { // no access page - we must return the content entered by the user so just return it return $posts; } elseif (membership_is_welcome_page($post->ID, false)) { // Registration complete page // Handle any updates passed $page = isset($_REQUEST['action']) && !empty($_REQUEST['action']) ? addslashes($_REQUEST['action']) : 'renewform'; if ($page == 'subscriptionsignup') { if (is_user_logged_in() && isset($_POST['custom'])) { list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); if (wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id)) { $member = Membership_Plugin::factory()->get_member($user_id); $member->create_subscription($sub_id, $_POST['gateway']); do_action('membership_payment_subscr_signup', $user_id, $sub_id); // Timestamp the update update_user_meta($user_id, '_membership_last_upgraded', time()); // Added another redirect to the same url because the show_no_access filters // have already run on the "parse_request" action (Cole) wp_redirect(M_get_returnurl_permalink()); exit; } } else { // check if a custom is posted and of so then process the user if (isset($_POST['custom'])) { list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']); if (wp_verify_nonce($_REQUEST['_wpnonce'], 'free-sub_' . $sub_id)) { $member = Membership_Plugin::factory()->get_member($user_id); $member->create_subscription($sub_id, $_POST['gateway']); do_action('membership_payment_subscr_signup', $user_id, $sub_id); // Timestamp the update update_user_meta($user_id, '_membership_last_upgraded', time()); // Added another redirect to the same url because the show_no_access filters // have already run on the "parse_request" action (Cole) wp_redirect(M_get_returnurl_permalink()); exit; } } } } return $posts; } // If nothing else is hit, just return the content return $posts; }
/** * Initializes initial protection. * * @since 3.5 * @action parse_request * * @access public * @global Membership_Model_Member $member Current member * @global array $M_options The plugin settings. * @staticvar boolean $initialised Determines whether or not protection has been initialized. * @param WP $wp Instance of WP class. */ public function initialise_protection(WP $wp) { global $member, $M_options, $membershippublic; static $initialised = false; $member = Membership_Plugin::current_member(); if ($initialised) { // ensure that this is only called once, so return if we've been here already. return; } // Set up some common defaults $factory = Membership_Plugin::factory(); if (!empty($wp->query_vars['feed'])) { // This is a feed access, then set the feed rules $user_id = (int) $membershippublic->find_user_from_key(filter_input(INPUT_GET, 'k')); if ($user_id > 0) { // Logged in - check there settings, if they have any. $member = $factory->get_member($user_id); // Load the levels for this member - and associated rules $member->load_levels(true); } if (!$member) { // not passing a key so limit based on stranger settings // need to grab the stranger settings $member = $factory->get_member(get_current_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. $this->_add_filter('the_posts', 'show_noaccess_feed', 1); } } } else { $member = Membership_Plugin::current_member(); if (!$member->has_cap(Membership_Model_Member::CAP_MEMBERSHIP_ADMIN) && !$member->has_cap('manage_options') && !is_super_admin($member->ID) && !$member->has_levels()) { // This user can't access anything on the site - . add_filter('comments_open', '__return_false', PHP_INT_MAX); // Changed for this version to see if it helps to get around changed in WP 3.5 $this->_add_action('the_posts', 'show_noaccess_page', 1, 2); // Hide all pages from menus - except the signup one $this->_add_filter('get_pages', 'remove_pages_menu'); // Hide all categories from lists $this->_add_filter('get_terms', 'remove_categories', 1); } } do_action('membership-add-shortcodes'); // Set the initialisation status $initialised = true; }
function MBP_can_access_page($page) { global $member; $member = Membership_Plugin::current_member(); if (!empty($member) && method_exists($member, 'pass_thru')) { return $member->pass_thru('bppages', array('can_access_page' => $page)); } }