예제 #1
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;
 }
예제 #2
0
function membership_is_special_page($page_id = null, $check_is_page = true)
{
    global $M_options;
    if ($check_is_page && !is_page()) {
        return false;
    }
    $page_id = intval($page_id);
    if (!$page_id) {
        $page_id = get_the_ID();
    }
    $is_special = false;
    $is_special |= isset($M_options['nocontent_page']) && $page_id == $M_options['nocontent_page'];
    $is_special |= isset($M_options['registrationcompleted_page']) && $page_id == $M_options['registrationcompleted_page'];
    $is_special |= isset($M_options['subscriptions_page']) && $page_id == $M_options['subscriptions_page'];
    $is_special |= isset($M_options['account_page']) && $page_id == $M_options['account_page'];
    $is_special |= isset($M_options['registration_page']) && $page_id == $M_options['registration_page'];
    $is_special |= M_contains_schortcode($page_id, 'subscriptionform', true);
    $is_special |= M_contains_schortcode($page_id, 'accountform', true);
    $is_special |= M_contains_schortcode($page_id, 'upgradeform', true);
    $is_special |= M_contains_schortcode($page_id, 'renewform', true);
    $is_special |= M_contains_schortcode($page_id, 'subscriptionbutton', true);
    return $is_special;
}