Exemplo n.º 1
0
 function transition_user_through_subscriptions()
 {
     $relationships = $this->get_expiring_relationships();
     if (!empty($relationships)) {
         membership_debug_log(__('CRON: Loaded relationships', 'membership') . print_r($relationships, true));
         foreach ($relationships as $rel) {
             // Just creating a membership record for this user should automatically
             // start the transition through the subscription
             membership_debug_log(sprintf(__('CRON: Processing member %d', 'membership'), $rel->user_id));
             $member = Membership_Plugin::factory()->get_member($rel->user_id);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Get an membership by an user ID
  *
  * @param int $user_id
  */
 public static function get_membership($user_id)
 {
     $membership = null;
     // @see https://github.com/pronamic-wpmudev/membership-premium/blob/3.5.1.3/classes/Membership/Factory.php#L76
     if (method_exists('Membership_Plugin', 'factory')) {
         $factory = Membership_Plugin::factory();
         // @see https://github.com/pronamic-wpmudev/membership-premium/blob/3.5.1.3/classes/Membership/Factory.php#L76
         $membership = $factory->get_member($user_id);
     } elseif (class_exists('M_Membership')) {
         // @see https://plugins.trac.wordpress.org/browser/membership/tags/3.4.4.1/membershipincludes/classes/class.membership.php#L18
         $membership = new M_Membership($user_id);
     }
     return $membership;
 }
Exemplo n.º 3
0
/**
 * Instantiates the plugin and setups all modules.
 *
 * @since 3.5
 */
function membership_launch()
{
    // setup environment
    membership_setup_contsants();
    // database tables
    membership_setup_db_table_constants();
    // plugin setup
    $plugin = Membership_Plugin::instance();
    $plugin->set_factory(new Membership_Factory());
    $plugin->set_module(Membership_Module_System::NAME);
    $plugin->set_module(Membership_Module_Upgrade::NAME);
    $plugin->set_module(Membership_Module_Menu::NAME);
    if (Membership_Plugin::is_enabled()) {
        $plugin->set_module(Membership_Module_Protection::NAME);
    }
    $plugin->set_module(Membership_Module_Adminbar::NAME);
    $plugin->set_module(Membership_Module_Frontend_Registration::NAME);
    if (is_admin()) {
        //		$plugin->set_module( Membership_Module_Backend_Rules_Metabox::NAME ); // temporary deactivated, not ready to release
    } else {
        $plugin->set_module(Membership_Module_Frontend::NAME);
    }
    // take care of new users
    Membership_Plugin::factory()->hook_new_user_registration();
    do_action('membership_loaded', $plugin);
}
Exemplo n.º 4
0
<?php

global $M_options;
$factory = Membership_Plugin::factory();
if (isset($_REQUEST['gateway']) && isset($_REQUEST['extra_form'])) {
    $gateway = Membership_Gateway::get_gateway($_REQUEST['gateway']);
    if ($gateway && is_object($gateway) && $gateway->haspaymentform == true) {
        $sub = $factory->get_subscription($subscription);
        $pricing = $sub->get_pricingarray();
        do_action('membership_payment_form_' . $_REQUEST['gateway'], $sub, $pricing, $member->ID);
    }
} else {
    if ($member->on_sub($subscription)) {
        $sub = $factory->get_subscription($subscription);
        // Get the coupon
        $coupon = membership_get_current_coupon();
        ?>
<div id='membership-wrapper'>
		<legend><?php 
        echo __('Sign up for', 'membership'), " ", $sub->sub_name();
        ?>
</legend>

		<div class="alert">
			<?php 
        printf(__('You currently have a subscription for the %s subscription. If you wish to sign up a different subscription then you can do so below.', 'membership'), '<strong>' . $sub->sub_name() . '</strong>');
        ?>
		</div>

		<table class='purchasetable'><?php 
        $subs = $this->get_subscriptions();
Exemplo n.º 5
0
 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;
     }
 }
Exemplo n.º 6
0
 function popover_sendpayment_form($user_id = false)
 {
     global $M_options;
     $sub = $to_sub_id = false;
     $logged_in = is_user_logged_in();
     $subscription = isset($_REQUEST['subscription']) ? $_REQUEST['subscription'] : 0;
     // free subscription processing
     if ($logged_in && $subscription) {
         $sub = Membership_Plugin::factory()->get_subscription($subscription);
         if ($sub->is_free()) {
             $to_sub_id = $subscription;
         }
     }
     // coupon processing
     $coupon = filter_input(INPUT_POST, 'coupon_code');
     if ($logged_in && $coupon && $subscription) {
         $coupon = new M_Coupon($coupon);
         $coupon_obj = $coupon->get_coupon();
         if ($coupon->valid_coupon() && $coupon_obj->discount >= 100 && $coupon_obj->discount_type == 'pct') {
             $to_sub_id = $subscription;
             $coupon->increment_coupon_used();
         }
     }
     if ($to_sub_id) {
         $membership = Membership_Plugin::factory()->get_member(get_current_user_id());
         $membership->create_subscription($to_sub_id);
         if (!empty($M_options['registrationcompleted_message'])) {
             $html = '<div class="header"><h1>';
             $html .= sprintf(__('Subscription %s has been added.', 'membership'), $sub ? $sub->sub_name() : '');
             $html .= '</h1></div><div class="fullwidth">';
             $html .= stripslashes(wpautop($M_options['registrationcompleted_message']));
             $html .= '<a class="button button-primary ' . esc_attr(apply_filters('membership_subscription_button_color', '')) . '" href="' . M_get_account_permalink() . '">' . __('Go to your account', 'membership') . '</a>';
             $html .= '</div>';
             echo $html;
         } else {
             wp_send_json(array('redirect' => strpos(home_url(), 'https://') === 0 ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink()));
         }
         exit;
     }
     // render template
     ob_start();
     echo apply_filters('membership_popover_sendpayment_form_before_content', '');
     if (defined('MEMBERSHIP_POPOVER_SENDPAYMENT_FORM') && is_readable(MEMBERSHIP_POPOVER_SENDPAYMENT_FORM)) {
         include MEMBERSHIP_POPOVER_SENDPAYMENT_FORM;
     } else {
         $filename = apply_filters('membership_override_popover_sendpayment_form', membership_dir('membershipincludes/includes/popover_payment.form.php'));
         if (is_readable($filename)) {
             include $filename;
         }
     }
     echo apply_filters('membership_popover_sendpayment_form_after_content', ob_get_clean());
     exit;
 }
Exemplo n.º 7
0
 function send_ping($sub_id = false, $level_id = false, $user_id = false)
 {
     if (!class_exists('WP_Http')) {
         include_once ABSPATH . WPINC . '/class-http.php';
     }
     $this->ping = $this->get_ping();
     if (!$this->ping) {
         return;
     }
     $pingdata = apply_filters('membership_ping_constants_list', $this->pingconstants);
     $member = Membership_Plugin::factory()->get_member(empty($user_id) ? get_current_user_id() : $user_id);
     if (!$sub_id) {
         $ids = $member->get_subscription_ids();
         if (!empty($ids)) {
             $sub_id = $ids[0];
         }
     }
     if (!$level_id) {
         $ids = $member->get_level_ids();
         if (!empty($ids)) {
             $level_id = $ids[0]->level_id;
         }
     }
     foreach ($pingdata as $key => $value) {
         switch ($key) {
             case '%blogname%':
                 $pingdata[$key] = get_option('blogname');
                 break;
             case '%blogurl%':
                 $pingdata[$key] = get_option('home');
                 break;
             case '%username%':
                 $pingdata[$key] = $member->user_login;
                 break;
             case '%usernicename%':
                 $pingdata[$key] = $member->user_nicename;
                 break;
             case '%userdisplayname%':
                 $pingdata[$key] = $member->display_name;
                 break;
             case '%userfirstname%':
                 $pingdata[$key] = $member->user_firstname;
                 break;
             case '%userlastname%':
                 $pingdata[$key] = $member->user_lastname;
                 break;
             case '%useremail%':
                 $pingdata[$key] = $member->user_email;
                 break;
             case '%userid%':
                 $pingdata[$key] = $member->ID;
                 break;
             case '%networkname%':
                 $pingdata[$key] = get_site_option('site_name');
                 break;
             case '%networkurl%':
                 $pingdata[$key] = get_site_option('siteurl');
                 break;
             case '%subscriptionname%':
                 if (!empty($sub_id)) {
                     $sub = Membership_Plugin::factory()->get_subscription($sub_id);
                     $pingdata[$key] = $sub->sub_name();
                 } else {
                     $pingdata[$key] = '';
                 }
                 break;
             case '%levelname%':
                 if (!empty($level_id)) {
                     $level = Membership_Plugin::factory()->get_level($level_id);
                     $pingdata[$key] = $level->level_title();
                 } else {
                     $pingdata[$key] = '';
                 }
                 break;
             case '%timestamp%':
                 $pingdata[$key] = time();
                 break;
             default:
                 $pingdata[$key] = apply_filters('membership_pingfield_' . $key, '');
                 break;
         }
     }
     // Globally replace the values in the ping and then make it into an array to send
     $pingmessage = str_replace(array_keys($pingdata), array_values($pingdata), $this->ping->pinginfo);
     $pingmessage = array_map('trim', explode(PHP_EOL, $pingmessage));
     // make the ping message into a sendable bit of text
     $pingtosend = array();
     foreach ($pingmessage as $key => $value) {
         $temp = explode("=", $value);
         if (strpos($temp[0], '[') !== false && strpos($temp[0], ']') !== false) {
             //this key is an array - let's add to the $pingtosend array as an array
             $varname = $temp[0];
             $value = $temp[1];
             $start = strpos($varname, '[');
             $end = strpos($varname, ']');
             $key = substr($varname, 0, $start);
             $subkey = substr($varname, $start + 1, $end - $start - 1);
             if (!isset($pingtosend[$key])) {
                 $pingtosend[$key] = array($subkey => $value);
             } else {
                 $pingtosend[$key][$subkey] = $value;
             }
         } elseif (count($temp) == 2) {
             $pingtosend[$temp[0]] = $temp[1];
         }
     }
     // Send the request
     $request = new WP_Http();
     $url = $this->ping->pingurl;
     switch ($this->ping->pingtype) {
         case 'GET':
             if (strpos($url, '?') === false) {
                 $url .= '?';
             }
             $url .= http_build_query($pingtosend);
             // old method kept for consideration as using WP method.
             // $url = esc_url( add_query_arg( array_map( 'urlencode', $pingtosend ), $url ) );
             $result = $request->request($url, array('method' => 'GET', 'body' => ''));
             break;
         case 'POST':
             $result = $request->request($url, array('method' => 'POST', 'body' => $pingtosend));
             break;
     }
     /*
      'headers': an array of response headers, such as "x-powered-by" => "PHP/5.2.1"
      'body': the response string sent by the server, as you would see it with you web browser
      'response': an array of HTTP response codes. Typically, you'll want to have array('code'=>200, 'message'=>'OK')
      'cookies': an array of cookie information
     */
     $this->add_history($pingtosend, $result);
 }
Exemplo n.º 8
0
function M_Roles_update_level_information($level_id)
{
    $level = Membership_Plugin::factory()->get_level($level_id);
    $level->update_meta('associated_wp_role', $_POST['levelrole']);
}
Exemplo n.º 9
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;
 }
Exemplo n.º 10
0
 function handle_2checkout_return()
 {
     global $M_options;
     // Return handling code
     $timestamp = time();
     if (isset($_REQUEST['key'])) {
         $total = $_REQUEST['total'];
         $sub_id = false;
         $user_id = false;
         list($sub_id, $user_id) = explode(':', $_REQUEST['merchant_order_id']);
         if (esc_attr(get_option($this->gateway . "_twocheckout_status")) == 'test') {
             $hash = strtoupper(md5(esc_attr(get_option($this->gateway . "_twocheckout_secret_word")) . esc_attr(get_option($this->gateway . "_twocheckout_sid")) . $_REQUEST['order_number'] . $total));
         } else {
             $hash = strtoupper(md5(esc_attr(get_option($this->gateway . "_twocheckout_secret_word")) . esc_attr(get_option($this->gateway . "_twocheckout_sid")) . $_REQUEST['order_number'] . $total));
         }
         if ($sub_id && $user_id && $_REQUEST['key'] == $hash && $_REQUEST['credit_card_processed'] == 'Y') {
             $this->_record_transaction($user_id, $sub_id, $_REQUEST['total'], $_REQUEST['currency'], $timestamp, $_REQUEST['order_number'], 'Credit Card Verified', '');
             // Added for affiliate system link
             do_action('membership_payment_processed', $user_id, $sub_id, $_REQUEST['total'], $_REQUEST['currency'], $_REQUEST['order_number']);
             $member = Membership_Plugin::factory()->get_member($user_id);
             if ($member) {
                 $member->create_subscription($sub_id, $this->gateway);
                 membership_debug_log(sprintf(__('Order complete for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
             }
             do_action('membership_payment_subscr_signup', $user_id, $sub_id);
             if (!isset($M_options['registrationcompleted_page']) || 0 >= $M_options['registrationcompleted_page']) {
                 wp_redirect(get_option('home'));
             } else {
                 wp_redirect(M_get_registrationcompleted_permalink());
             }
             exit;
         }
     } else {
         if (isset($_REQUEST['message_type'])) {
             $md5_hash = strtoupper(md5("{$_REQUEST['sale_id']}" . esc_attr(get_option($this->gateway . "_twocheckout_sid")) . "{$_REQUEST['invoice_id']}" . esc_attr(get_option($this->gateway . "_twocheckout_secret_word"))));
             $sub_id = false;
             $user_id = false;
             //$product_id = $_REQUEST['item_id_1'];
             list($sub_id, $user_id, $from_sub_id) = explode(':', $_REQUEST['vendor_order_id']);
             if ($md5_hash == $_REQUEST['md5_hash']) {
                 switch ($_REQUEST['message_type']) {
                     case 'RECURRING_INSTALLMENT_SUCCESS':
                         if (!$this->_check_duplicate_transaction($user_id, $sub_id, $timestamp, $_POST['invoice_id'])) {
                             $this->_record_transaction($user_id, $sub_id, $_REQUEST['item_rec_list_amount_1'], $_REQUEST['list_currency'], $timestamp, $_POST['invoice_id'], 'Processed', '');
                             $member = Membership_Plugin::factory()->get_member($user_id);
                             if ($member) {
                                 remove_action('membership_expire_subscription', 'membership_record_user_expire', 10, 3);
                                 remove_action('membership_add_subscription', 'membership_record_user_subscribe', 10, 4);
                                 if ($from_sub_id) {
                                     $member->drop_subscription($from_sub_id);
                                 }
                                 $member->expire_subscription($sub_id);
                                 $member->create_subscription($sub_id, $this->gateway);
                                 membership_debug_log(sprintf(__('Recurring installment for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
                             }
                             // Added for affiliate system link
                             do_action('membership_payment_processed', $user_id, $sub_id, $_REQUEST['item_rec_list_amount_1'], $_REQUEST['list_currency'], $_POST['invoice_id']);
                         }
                         break;
                     case 'FRAUD_STATUS_CHANGED':
                     case 'INVOICE_STATUS_CHANGED':
                         // We don't really want to do anything here without pulling out more information
                         break;
                     case 'ORDER_CREATED':
                     case 'RECURRING_RESTARTED':
                         $transaction_amount = !empty($_REQUEST['item_rec_list_amount_1']) ? $_REQUEST['item_rec_list_amount_1'] : $_REQUEST['item_list_amount_1'];
                         $this->_record_transaction($user_id, $sub_id, $transaction_amount, $_REQUEST['list_currency'], $timestamp, $_POST['invoice_id'], 'Processed', '');
                         $member = Membership_Plugin::factory()->get_member($user_id);
                         if ($member) {
                             if ($from_sub_id) {
                                 $member->drop_subscription($from_sub_id);
                             }
                             $member->create_subscription($sub_id, $this->gateway);
                             membership_debug_log(sprintf(__('Recurring restarted for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
                         }
                         break;
                     case 'RECURRING_STOPPED':
                     case 'RECURRING_COMPLETE':
                     case 'RECURRING_INSTALLMENT_FAILED':
                     default:
                         $member = Membership_Plugin::factory()->get_member($user_id);
                         if ($member) {
                             $member->mark_for_expire($sub_id);
                             membership_debug_log(sprintf(__('Recurring failed for user %d on subscription %d.', 'membership'), $user_id, $sub_id));
                         }
                         do_action('membership_payment_subscr_cancel', $user_id, $sub_id);
                         break;
                 }
             } else {
                 // MD5 Hash Failed
                 header('Status: 403 Forbidden');
                 echo 'Error: Unexpected Security Value. Verification is not possible.';
                 membership_debug_log('Error: Unexpected Security Value. Verification is not possible.');
                 exit;
             }
             echo "OK";
             membership_debug_log('OK');
             exit;
         } else {
             // Did not find expected POST variables. Possible access attempt from a non PayPal site.
             header('Status: 400 Bad Request');
             echo 'Error: Missing POST variables. Identification is not possible.';
             membership_debug_log('Error: Missing POST variables. Identification is not possible.');
             exit;
         }
     }
 }
Exemplo n.º 11
0
function membership_record_level_move($fromlevel_id, $tolevel_id, $user_id)
{
    global $wpdb;
    $table = membership_db_prefix($wpdb, 'membership_news');
    $factory = Membership_Plugin::factory();
    // Get the information
    $user = new WP_User($user_id);
    $fromlevel = $factory->get_level($fromlevel_id);
    $tolevel = $factory->get_level($tolevel_id);
    $message = sprintf(__('<strong>%s</strong> has moved from level <strong>%s</strong> to level <strong>%s</strong>', 'membership'), $user->display_name, $fromlevel->level_title(), $tolevel->level_title());
    $wpdb->insert($table, array('newsitem' => $message, 'newsdate' => current_time('mysql')));
}
Exemplo n.º 12
0
function membership_exclude_inactive_users($bp_user_query)
{
    global $wpdb;
    if (Membership_Plugin::is_enabled()) {
        $query = new WP_User_Query(array('meta_key' => membership_db_prefix($wpdb, 'membership_active', false), 'meta_value' => 'no', 'meta_compare' => '='));
        if ($query->get_total() > 0) {
            $bp_user_query->query_vars['exclude'] = wp_list_pluck($query->get_results(), 'ID');
        }
    }
}
Exemplo n.º 13
0
 /**
  * Processes serial level purchase.
  *
  * @since  3.5
  *
  * @access protected
  * @global array   $M_options         The array of plugin options.
  *
  * @param array    $price             The array with current price information.
  * @param DateTime $date              The date when to process this transaction.
  * @param int      $total_occurencies The number of billing occurrences or payments for the subscription.
  *                                    To submit a subscription with no end date, this field must be submitted with a value of 9999
  *
  * @return array Returns transaction information on success, otherwise NULL.
  */
 protected function _process_serial_purchase($price, $date, $total_occurencies, $unit = null, $interval_length = null)
 {
     if ($price['amount'] == 0) {
         $this->_payment_result['status'] = 'success';
         return null;
     }
     // initialize AIM transaction to check CC
     if (count(array_filter($this->_transactions)) == 0) {
         $authOnly = true;
         $transaction = $this->_process_nonserial_purchase($price, $date, $authOnly);
         if (is_null($transaction)) {
             return null;
         }
         //$transaction['void'] = true;  // best not to uncomment this line unless you know what you are doing.
         $this->_transactions[] = $transaction;
         // WARNING: By removing the lines below you will end up charging users twice on the same day.
         // Please DO NOT remove these unless you are absolutely sure you know what you are doing, see line 881 and lines 986 - 1006
         $interval = self::_get_period_interval_in_date_format($price['unit']);
         $date->modify(sprintf('+%d %s', $price['period'], $interval));
     }
     $amount = number_format($price['amount'], 2, '.', '');
     $level = Membership_Plugin::factory()->get_level($price['level_id']);
     $name = substr(sprintf('%s / %s', $level->level_title(), $this->_subscription->sub_name()), 0, 50);
     $subscription = $this->_get_arb_subscription($price);
     $subscription->name = $name;
     $subscription->amount = $amount;
     $subscription->startDate = $date->format('Y-m-d');
     $subscription->totalOccurrences = $total_occurencies;
     if (!is_null($unit)) {
         $subscription->intervalUnit = $unit;
     }
     if (!is_null($interval_length)) {
         $subscription->intervalLength = $interval_length;
     }
     if (isset($price['origin'])) {
         // coupon is applied, so we need to add trial period
         $subscription->amount = $amount = number_format($price['origin'], 2, '.', '');
         $subscription->trialAmount = number_format($price['amount'], 2, '.', '');
         $subscription->trialOccurrences = 1;
         $subscription->totalOccurrences = $subscription->totalOccurrences + $subscription->trialOccurrences;
     }
     $arb = $this->_get_arb();
     $response = $arb->createSubscription($subscription);
     if ($response->isOk()) {
         $this->_payment_result['status'] = 'success';
         return array('method' => 'arb', 'transaction' => $response->getSubscriptionId(), 'date' => $date->format('U'), 'amount' => $amount);
     }
     $this->_payment_result['status'] = 'error';
     $this->_payment_result['errors'][] = $response->getMessageText();
     return null;
 }
Exemplo n.º 14
0
 function process_dripped_wizard_step()
 {
     $factory = Membership_Plugin::factory();
     if (isset($_POST['levelname'])) {
         // Create an initial subscription
         $sub_id = $this->create_subscription(__('Dripped Subscription', 'membership'));
         $sub = $factory->get_subscription($sub_id);
         $sub->toggleactivation();
         $sub->togglepublic();
         foreach ($_POST['levelname'] as $key => $value) {
             if (empty($value)) {
                 $value = __('Level ', 'membership') . ((int) $key + 1);
             }
             // Create a level
             $level_id = $this->create_level($value);
             // Add the level to the subscription
             $this->add_level_to_subscription($level_id, $sub_id, 'finite');
             // Activate and make public the levels and subscriptions
             $level = $factory->get_level($level_id);
             $level->toggleactivation();
         }
     }
     // Create a visitor level and set it in the options
     if (isset($_POST['creatavisitorlevel']) && $_POST['creatavisitorlevel'] == 'yes') {
         $level_id = $this->create_level(__('Visitors', 'membership'));
         $level = $factory->get_level($level_id);
         $level->toggleactivation();
         if (defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) {
             if (function_exists('get_blog_option')) {
                 if (function_exists('switch_to_blog')) {
                     switch_to_blog(MEMBERSHIP_GLOBAL_MAINSITE);
                 }
                 $M_options = get_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', array());
             } else {
                 $M_options = get_option('membership_options', array());
             }
         } else {
             $M_options = get_option('membership_options', array());
         }
         $M_options['strangerlevel'] = (int) $level_id;
         if (defined('MEMBERSHIP_GLOBAL_TABLES') && MEMBERSHIP_GLOBAL_TABLES === true) {
             if (function_exists('update_blog_option')) {
                 update_blog_option(MEMBERSHIP_GLOBAL_MAINSITE, 'membership_options', $M_options);
             } else {
                 update_option('membership_options', $M_options);
             }
         } else {
             update_option('membership_options', $M_options);
         }
     }
     // Activate the relevant gateway if it's set
     if (isset($_POST['wizardgateway'])) {
         $active = get_option('membership_activated_gateways', array());
         if (!in_array($_POST['wizardgateway'], $active)) {
             $active[] = $_POST['wizardgateway'];
             update_option('membership_activated_gateways', array_unique($active));
         }
     }
 }
 function process_payment_form()
 {
     global $M_options, $M_membership_url;
     $return = array();
     if (!is_ssl()) {
         wp_die(__('You must use HTTPS in order to do this', 'membership'));
         exit;
     }
     $popup = isset($M_options['formtype']) && $M_options['formtype'] == 'new' ? true : false;
     $coupon = membership_get_current_coupon();
     if (empty($M_options['paymentcurrency'])) {
         $M_options['paymentcurrency'] = 'USD';
     }
     $subscription = Membership_Plugin::factory()->get_subscription($_POST['subscription_id']);
     $pricing = $subscription->get_pricingarray();
     if (!empty($pricing) && !empty($coupon) && method_exists($coupon, 'valid_for_subscription') && $coupon->valid_for_subscription($subscription->id)) {
         $pricing = $coupon->apply_coupon_pricing($pricing);
     }
     $user_id = is_user_logged_in() ? get_current_user_id() : $_POST['user_id'];
     $user = get_userdata($user_id);
     $sub_id = $subscription->id;
     // A basic price or a single subscription
     if ($pricing) {
         $timestamp = time();
         if (get_option($this->gateway . "_mode", 'sandbox') == 'sandbox') {
             $endpoint = "https://test.authorize.net/gateway/transact.dll";
         } else {
             $endpoint = "https://secure.authorize.net/gateway/transact.dll";
         }
         $payment = new M_Gateway_Worker_AuthorizeNet_AIM($endpoint, get_option($this->gateway . "_delim_data", 'yes'), get_option($this->gateway . "_delim_char", ','), get_option($this->gateway . "_encap_char", ''), get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
         $payment->transaction($_POST['card_num']);
         $amount = number_format($pricing[0]['amount'], 2);
         // Billing Info
         $payment->setParameter("x_card_code", $_POST['card_code']);
         $payment->setParameter("x_exp_date ", $_POST['exp_month'] . $_POST['exp_year']);
         $payment->setParameter("x_amount", $amount);
         // Payment billing information passed to authorize, thanks to Kevin L. for spotting this.
         $payment->setParameter("x_first_name", $_POST['first_name']);
         $payment->setParameter("x_last_name", $_POST['last_name']);
         $payment->setParameter("x_address", $_POST['address']);
         $payment->setParameter("x_zip", $_POST['zip']);
         $payment->setParameter("x_email", is_email($user->user_email) != false ? is_email($user->user_email) : '');
         // Order Info
         $payment->setParameter("x_description", $subscription->sub_name());
         $payment->setParameter("x_duplicate_window", 30);
         // E-mail
         $payment->setParameter("x_header_email_receipt", get_option($this->gateway . "_header_email_receipt", ''));
         $payment->setParameter("x_footer_email_receipt", get_option($this->gateway . "_footer_email_receipt", ''));
         $payment->setParameter("x_email_customer", strtoupper(get_option($this->gateway . "_email_customer", '')));
         $payment->setParameter("x_customer_ip", $_SERVER['REMOTE_ADDR']);
         $payment->process();
         if ($payment->isApproved()) {
             $status = __('Processed', 'membership');
             $note = '';
             $member = Membership_Plugin::factory()->get_member($user_id);
             if ($member) {
                 if ($member->has_subscription() && $member->on_sub($sub_id)) {
                     remove_action('membership_expire_subscription', 'membership_record_user_expire', 10, 3);
                     remove_action('membership_add_subscription', 'membership_record_user_subscribe', 10, 4);
                     $member->expire_subscription($sub_id);
                     $member->create_subscription($sub_id, $this->gateway);
                 } else {
                     $member->create_subscription($sub_id, $this->gateway);
                 }
             }
             // TODO: create switch for handling different authorize aim respone codes
             $this->record_transaction($user_id, $sub_id, $amount, $M_options['paymentcurrency'], time(), $payment->results[6] == 0 ? 'TESTMODE' : $payment->results[6], $status, $note);
             do_action('membership_payment_subscr_signup', $user_id, $sub_id);
             $return['status'] = 'success';
             if ($popup && !empty($M_options['registrationcompleted_message'])) {
                 $return['redirect'] = 'no';
                 $registrationcompletedmessage = $this->get_completed_message($subscription);
                 $return['message'] = $registrationcompletedmessage;
             } else {
                 $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                 $return['message'] = '';
             }
         } else {
             $return['status'] = 'error';
             $return['errors'][] = __('Your payment was declined.  Please check all your details or use a different card.', 'membership');
         }
     } else {
         $return['status'] = 'error';
         $return['errors'][] = __('There was an issue determining the price.', 'membership');
     }
     echo json_encode($return);
     exit;
 }
Exemplo n.º 16
0
 /**
  * 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;
 }
Exemplo n.º 17
0
 /**
  * Returns singletone instance of the plugin.
  *
  * @since 3.5
  *
  * @static
  * @access public
  * @return Membership_Plugin
  */
 public static function instance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new Membership_Plugin();
     }
     return self::$_instance;
 }
Exemplo n.º 18
0
 /**
  *
  * @access public
  * @param type $content
  * @param type $error
  * @return type
  */
 public function signup_free_subscription($content, $error)
 {
     if (isset($_POST['custom'])) {
         list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
     }
     // create_subscription
     $member = Membership_Plugin::factory()->get_member($user_id);
     if ($member) {
         $member->create_subscription($sub_id, $this->gateway);
     }
     do_action('membership_payment_subscr_signup', $user_id, $sub_id);
     $content .= '<div id="reg-form">';
     // because we can't have an enclosing form for this part
     $content .= '<div class="formleft">';
     $message = get_option($this->gateway . "_completed_message", $this->defaultmessage);
     $content .= stripslashes($message);
     $content .= '</div>';
     $content .= "</div>";
     $content = apply_filters('membership_subscriptionform_signedup', $content, $user_id, $sub_id);
     return $content;
 }
Exemplo n.º 19
0
 function handle_paypal_return()
 {
     // PayPal IPN handling code
     if ((isset($_POST['payment_status']) || isset($_POST['txn_type'])) && isset($_POST['custom'])) {
         if (get_option($this->gateway . "_paypal_status") == 'live') {
             $domain = 'https://www.paypal.com';
         } else {
             $domain = 'https://www.sandbox.paypal.com';
         }
         membership_debug_log(__('Received PayPal IPN from - ', 'membership') . $domain);
         //Paypal post authenticity verification
         $ipn_data = (array) stripslashes_deep($_POST);
         $ipn_data['cmd'] = '_notify-validate';
         $response = wp_remote_post("{$domain}/cgi-bin/webscr", array('timeout' => 60, 'sslverify' => false, 'httpversion' => '1.1', 'body' => $ipn_data));
         if (!is_wp_error($response) && 200 == $response['response']['code'] && !empty($response['body']) && "VERIFIED" == $response['body']) {
             membership_debug_log('PayPal Transaction Verified');
         } else {
             $error = 'Response Error: Unexpected transaction response';
             membership_debug_log($error);
             membership_debug_log($response);
             echo $error;
             exit;
         }
         // handle cases that the system must ignore
         //if ($_POST['payment_status'] == 'In-Progress' || $_POST['payment_status'] == 'Partially-Refunded') exit;
         $new_status = false;
         // process PayPal response
         $factory = Membership_Plugin::factory();
         switch ($_POST['payment_status']) {
             case 'Partially-Refunded':
                 break;
             case 'In-Progress':
                 break;
             case 'Completed':
             case 'Processed':
                 // case: successful payment
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel, $fromsub) = explode(':', $_POST['custom']);
                 $newkey = md5('MEMBERSHIP' . $amount);
                 if ($key != $newkey) {
                     $member = $factory->get_member($user_id);
                     if ($member) {
                         if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                             $member->deactivate();
                         }
                     }
                 } elseif (!$this->_check_duplicate_transaction($user_id, $sub_id, $timestamp, trim($_POST['txn_id']))) {
                     $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, trim($_POST['txn_id']), $_POST['payment_status'], '');
                     if ($sublevel == '1') {
                         // This is the first level of a subscription so we need to create one if it doesn't already exist
                         $member = $factory->get_member($user_id);
                         if ($member) {
                             $member->create_subscription($sub_id, $this->gateway);
                             do_action('membership_payment_subscr_signup', $user_id, $sub_id);
                         }
                     } else {
                         $member = $factory->get_member($user_id);
                         if ($member) {
                             // Mark the payment so that we can move through ok
                             $member->record_active_payment($sub_id, $sublevel, $timestamp);
                         }
                     }
                     // remove any current subs for upgrades
                     $sub_ids = $member->get_subscription_ids();
                     foreach ($sub_ids as $fromsub) {
                         if ($sub_id == $fromsub) {
                             continue;
                         }
                         $member->drop_subscription($fromsub);
                     }
                     // Added for affiliate system link
                     do_action('membership_payment_processed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 }
                 membership_debug_log(__('Processed transaction received - ', 'membership') . print_r($_POST, true));
                 break;
             case 'Reversed':
                 // case: charge back
                 $note = __('Last transaction has been reversed. Reason: Payment has been reversed (charge back)', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Reversed transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                 }
                 do_action('membership_payment_reversed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Refunded':
                 // case: refund
                 $note = __('Last transaction has been reversed. Reason: Payment has been refunded', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Refunded transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                 }
                 do_action('membership_payment_refunded', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Denied':
                 // case: denied
                 $note = __('Last transaction has been reversed. Reason: Payment Denied', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Denied transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                 }
                 do_action('membership_payment_denied', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Pending':
                 // case: payment is pending
                 $pending_str = array('address' => __('Customer did not include a confirmed shipping address', 'membership'), 'authorization' => __('Funds not captured yet', 'membership'), 'echeck' => __('eCheck that has not cleared yet', 'membership'), 'intl' => __('Payment waiting for aproval by service provider', 'membership'), 'multi-currency' => __('Payment waiting for service provider to handle multi-currency process', 'membership'), 'unilateral' => __('Customer did not register or confirm his/her email yet', 'membership'), 'upgrade' => __('Waiting for service provider to upgrade the PayPal account', 'membership'), 'verify' => __('Waiting for service provider to verify his/her PayPal account', 'membership'), '*' => '');
                 $reason = @$_POST['pending_reason'];
                 $note = 'Last transaction is pending. Reason: ' . (isset($pending_str[$reason]) ? $pending_str[$reason] : $pending_str['*']);
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Pending transaction received - ', 'membership') . print_r($_POST, true));
                 do_action('membership_payment_pending', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             default:
                 // case: various error cases
         }
         //check for subscription details
         switch ($_POST['txn_type']) {
             case 'new_case':
                 // a dispute
                 if ($_POST['case_type'] == 'dispute') {
                     list($timestamp, $user_id, $sub_id, $key, $sublevel) = explode(':', $_POST['custom']);
                     // immediately suspend the account
                     $member = $factory->get_member($user_id);
                     if ($member) {
                         $member->deactivate();
                         membership_debug_log(sprintf(__('Dispute for %d', 'membership'), $user_id));
                     }
                 }
                 do_action('membership_payment_new_case', $user_id, $sub_id, $_POST['case_type']);
                 break;
         }
     } else {
         // Did not find expected POST variables. Possible access attempt from a non PayPal site.
         header('Status: 404 Not Found');
         echo 'Error: Missing POST variables. Identification is not possible.';
         membership_debug_log('Error: Missing POST variables. Identification is not possible.');
         exit;
     }
 }
Exemplo n.º 20
0
 public function load_core_levels($fullload = false)
 {
     $levels = $this->get_level_ids();
     if (!empty($levels)) {
         foreach ((array) $levels as $key => $lev) {
             if (!isset($this->levels[$lev->level_id])) {
                 $this->levels[$lev->level_id] = Membership_Plugin::factory()->get_level($lev->level_id, $fullload, array('core'));
             }
         }
     }
 }
Exemplo n.º 21
0
 /**
  * Returns subscription column.
  *
  * @since 3.5
  *
  * @access public
  * @param array $item The array of current item information.
  * @return string The column value
  */
 public function column_subscription($item)
 {
     $subscription = Membership_Plugin::factory()->get_subscription($item['transaction_subscription_ID']);
     return sprintf('<b>%s</b>%s', $subscription->sub_name(), $this->row_actions(array('&nbsp;')));
 }
Exemplo n.º 22
0
 function do_subscriptionprice_shortcode($atts, $content = null, $code = "")
 {
     global $wp_query;
     $defaults = array("holder" => '', "holderclass" => '', "item" => '', "itemclass" => '', "postfix" => '', "prefix" => '', "wrapwith" => '', "wrapwithclass" => '', "subscription" => '');
     extract(shortcode_atts($defaults, $atts));
     if (empty($subscription)) {
         return '';
     }
     $html = '';
     if (!empty($holder)) {
         $html .= "<{$holder} class='{$holderclass}'>";
     }
     if (!empty($item)) {
         $html .= "<{$item} class='{$itemclass}'>";
     }
     $html .= $prefix;
     // The title
     if (!empty($wrapwith)) {
         $html .= "<{$wrapwith} class='{$wrapwithclass}'>";
     }
     $sub = Membership_Plugin::factory()->get_subscription((int) $subscription);
     $first = $sub->get_level_at_position(1);
     if (!empty($first)) {
         $price = $first->level_price;
         if ($price == 0) {
             $price = "Free";
         } else {
             $M_options = get_option('membership_options', array());
             switch ($M_options['paymentcurrency']) {
                 case "USD":
                     $price = "\$" . $price;
                     break;
                 case "GBP":
                     $price = "&pound;" . $price;
                     break;
                 case "EUR":
                     $price = "&euro;" . $price;
                     break;
                 default:
                     $price = apply_filters('membership_currency_symbol_' . $M_options['paymentcurrency'], $M_options['paymentcurrency']) . $price;
             }
         }
     }
     $html .= $price;
     if (!empty($wrapwith)) {
         $html .= "</{$wrapwith}>";
     }
     $html .= $postfix;
     if (!empty($item)) {
         $html .= "</{$item}>";
     }
     if (!empty($holder)) {
         $html .= "</{$holder}>";
     }
     return $html;
 }
Exemplo n.º 23
0
 function handle_paypal_return()
 {
     // PayPal IPN handling code
     if ((isset($_POST['payment_status']) || isset($_POST['txn_type'])) && isset($_POST['custom'])) {
         if (get_option($this->gateway . "_paypal_status") == 'live') {
             $domain = 'https://www.paypal.com';
         } else {
             $domain = 'https://www.sandbox.paypal.com';
         }
         membership_debug_log(__('Received PayPal IPN from - ', 'membership') . $domain);
         //Paypal post authenticity verification
         $ipn_data = (array) stripslashes_deep($_POST);
         $ipn_data['cmd'] = '_notify-validate';
         $response = wp_remote_post("{$domain}/cgi-bin/webscr", array('timeout' => 60, 'httpversion' => '1.1', 'sslverify' => false, 'body' => $ipn_data));
         if (!is_wp_error($response) && 200 == $response['response']['code'] && !empty($response['body']) && "VERIFIED" == $response['body']) {
             membership_debug_log('PayPal Transaction Verified');
         } else {
             $error = 'Response Error: Unexpected transaction response';
             membership_debug_log($error);
             membership_debug_log($response);
             echo $error;
             exit;
         }
         // process PayPal response
         $factory = Membership_Plugin::factory();
         switch (filter_input(INPUT_POST, 'payment_status')) {
             case 'Completed':
             case 'Processed':
                 // case: successful payment
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], '');
                 membership_debug_log(__('Processed transaction received - ', 'membership') . print_r($_POST, true));
                 // Added for affiliate system link
                 do_action('membership_payment_processed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Reversed':
                 // case: charge back
                 $note = __('Last transaction has been reversed. Reason: Payment has been reversed (charge back)', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Reversed transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                 }
                 do_action('membership_payment_reversed', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Refunded':
                 // case: refund
                 $note = __('Last transaction has been reversed. Reason: Payment has been refunded', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Refunded transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                 }
                 do_action('membership_payment_refunded', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Denied':
                 // case: denied
                 $note = __('Last transaction has been reversed. Reason: Payment Denied', 'membership');
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], $note);
                 membership_debug_log(__('Denied transaction received - ', 'membership') . print_r($_POST, true));
                 $member = $factory->get_member($user_id);
                 if ($member) {
                     $member->expire_subscription($sub_id);
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                 }
                 do_action('membership_payment_denied', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
             case 'Pending':
                 // case: payment is pending
                 $pending_str = array('address' => __('Customer did not include a confirmed shipping address', 'membership'), 'authorization' => __('Funds not captured yet', 'membership'), 'echeck' => __('eCheck that has not cleared yet', 'membership'), 'intl' => __('Payment waiting for aproval by service provider', 'membership'), 'multi-currency' => __('Payment waiting for service provider to handle multi-currency process', 'membership'), 'unilateral' => __('Customer did not register or confirm his/her email yet', 'membership'), 'upgrade' => __('Waiting for service provider to upgrade the PayPal account', 'membership'), 'verify' => __('Waiting for service provider to verify his/her PayPal account', 'membership'), '*' => '');
                 $reason = @$_POST['pending_reason'];
                 $note = __('Last transaction is pending. Reason: ', 'membership') . (isset($pending_str[$reason]) ? $pending_str[$reason] : $pending_str['*']);
                 $amount = $_POST['mc_gross'];
                 $currency = $_POST['mc_currency'];
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 membership_debug_log(__('Pending transaction received - ', 'membership') . print_r($_POST, true));
                 $this->_record_transaction($user_id, $sub_id, $amount, $currency, current_time('timestamp'), $_POST['txn_id'], $_POST['payment_status'], $note);
                 do_action('membership_payment_pending', $user_id, $sub_id, $amount, $currency, $_POST['txn_id']);
                 break;
         }
         //check for subscription details
         switch ($_POST['txn_type']) {
             // Simple one-off payment
             case 'web_accept':
                 $amount = $_POST['mc_gross'];
                 list($timestamp, $user_id, $sub_id, $key, $from_sub) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $newkey = md5('MEMBERSHIP' . $amount);
                 if ($key != $newkey) {
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                     membership_debug_log(sprintf(__('Key does not match for amount - not creating subscription for user %d with key ', 'membership'), $user_id) . $newkey);
                 } else {
                     if ($from_sub) {
                         $member->drop_subscription($from_sub);
                     }
                     // create_subscription
                     $member->create_subscription($sub_id, $this->gateway);
                     membership_debug_log(sprintf(__('Creating subscription %d for user %d', 'membership'), $sub_id, $user_id));
                     do_action('membership_payment_subscr_signup', $user_id, $sub_id);
                 }
                 break;
             case 'subscr_signup':
                 // start the subscription
                 $amount = $_POST['mc_amount3'];
                 list($timestamp, $user_id, $sub_id, $key, $from_sub) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $newkey = md5('MEMBERSHIP' . $amount);
                 if ($key != $newkey) {
                     if (defined('MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION') && MEMBERSHIP_DEACTIVATE_USER_ON_CANCELATION == true) {
                         $member->deactivate();
                     }
                     membership_debug_log(sprintf(__('Key does not match for amount - not creating subscription for user %d with key ', 'membership'), $user_id) . $newkey);
                 } else {
                     if ($from_sub) {
                         $member->drop_subscription($from_sub);
                     }
                     // create_subscription
                     $member->create_subscription($sub_id, $this->gateway);
                     membership_debug_log(sprintf(__('Creating subscription %d for user %d', 'membership'), $sub_id, $user_id));
                     do_action('membership_payment_subscr_signup', $user_id, $sub_id);
                 }
                 break;
             case 'subscr_modify':
                 // modify the subscription
                 list($timestamp, $user_id, $sub_id, $key, $from_sub) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $member->drop_subscription($from_sub ? $from_sub : $sub_id);
                 $member->create_subscription((int) $_POST['item_number'], $this->gateway);
                 // Timestamp the update
                 update_user_meta($user_id, '_membership_last_upgraded', time());
                 membership_debug_log(sprintf(__('Moved from subscription - %d to subscription %d for user %d', 'membership'), $sub_id, (int) $_POST['item_number'], $user_id));
                 do_action('membership_payment_subscr_signup', $user_id, $sub_id);
                 break;
             case 'recurring_payment_profile_canceled':
             case 'subscr_cancel':
                 // mark for removal
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $member->mark_for_expire($sub_id);
                 membership_debug_log(sprintf(__('Marked for expiration %d on %d', 'membership'), $user_id, $sub_id));
                 do_action('membership_payment_subscr_cancel', $user_id, $sub_id);
                 break;
             case 'recurring_payment_suspended':
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $member->drop_subscription($sub_id);
                 membership_debug_log(sprintf(__('Recurring payment has been suspended - for %d', 'membership'), $user_id));
                 break;
             case 'recurring_payment_suspended_due_to_max_failed_payment':
             case 'recurring_payment_failed':
                 list($timestamp, $user_id, $sub_id, $key) = explode(':', $_POST['custom']);
                 $member = $factory->get_member($user_id);
                 $member->drop_subscription($sub_id);
                 membership_debug_log(sprintf(__('Recurring payment failed - the number of attempts to collect payment has exceeded the value specified for "max failed payments" - for %d', 'membership'), $user_id));
                 break;
             case 'new_case':
                 // a dispute
                 if ($_POST['case_type'] == 'dispute') {
                     // immediately suspend the account
                     $member = $factory->get_member($user_id);
                     $member->deactivate();
                     membership_debug_log(sprintf(__('Dispute for %d', 'membership'), $user_id));
                 }
                 do_action('membership_payment_new_case', $user_id, $sub_id, $_POST['case_type']);
                 break;
         }
     } else {
         // Did not find expected POST variables. Possible access attempt from a non PayPal site.
         header('Status: 404 Not Found');
         echo 'Error: Missing POST variables. Identification is not possible.';
         membership_debug_log('Error: Missing POST variables. Identification is not possible.');
         exit;
     }
 }
Exemplo n.º 24
0
 function can_view_current_page()
 {
     global $wp_query, $M_options, $M_previous_positive, $M_previous_negative;
     $valid = true;
     $global = Membership_Plugin::is_global_tables() ? MEMBERSHIP_GLOBAL_MAINSITE != get_current_blog_id() : false;
     // validate positive rules
     foreach ($this->positiverules as $key => $rule) {
         if ($global && !$rule->is_network_wide()) {
             continue;
         }
         if (method_exists(get_class($rule), 'alter_positive_queries')) {
             $rule->alter_positive_queries();
         }
         $M_previous_positive[$key]['name'] = $rule->name;
         $M_previous_positive[$key]['cascade'] = $this->allow_page_cascade;
         $M_previous_positive[$key]['result'] = $rule->validate_positive($M_previous_positive);
         $M_previous_positive[$key]['data'] = $rule->get_data();
         $valid = $M_previous_positive[$key]['result'];
         if (!$M_previous_positive[$key]['result']) {
             if (!in_array($rule->name, array('posts', 'categories'))) {
                 break;
             }
         }
     }
     if ($valid) {
         // validate negative rules
         foreach ($this->negativerules as $key => $rule) {
             if ($global && !$rule->is_network_wide()) {
                 continue;
             }
             $M_previous_negative[$key]['name'] = $rule->name;
             $M_previous_negative[$key]['cascade'] = $this->allow_page_cascade;
             $M_previous_negative[$key]['result'] = $rule->validate_negative($M_previous_negative);
             $M_previous_negative[$key]['data'] = $rule->get_data();
             $valid = $M_previous_negative[$key]['result'];
             if (!$M_previous_negative[$key]['result']) {
                 if (!in_array($rule->name, array('posts', 'categories'))) {
                     break;
                 }
             }
         }
     }
     // Are we protecting the front page?
     $protect_front_page = isset($M_options['protect_front_page']) && 'yes' == $M_options['protect_front_page'] ? true : false;
     $protect_front_page = apply_filters('membership_protect_front_page', $protect_front_page);
     if ((is_home() || is_front_page()) && !$protect_front_page) {
         return true;
     }
     return $valid;
 }
Exemplo n.º 25
0
 function send_message($user_id, $sub_id = false, $level_id = false)
 {
     global $wp_better_emails;
     $member = Membership_Plugin::factory()->get_member($user_id);
     if (!filter_var($member->user_email, FILTER_VALIDATE_EMAIL)) {
         return;
     }
     $this->comm = $this->get_communication();
     $commdata = apply_filters('membership_comm_constants_list', $this->commconstants);
     foreach (array_keys($commdata) as $key) {
         switch ($key) {
             case '%blogname%':
                 $commdata[$key] = get_option('blogname');
                 break;
             case '%blogurl%':
                 $commdata[$key] = get_option('home');
                 break;
             case '%username%':
                 $commdata[$key] = $member->user_login;
                 break;
             case '%usernicename%':
                 $commdata[$key] = $member->user_nicename;
                 break;
             case '%userdisplayname%':
                 $commdata[$key] = $member->display_name;
                 break;
             case '%userfirstname%':
                 $commdata[$key] = $member->user_firstname;
                 break;
             case '%userlastname%':
                 $commdata[$key] = $member->user_lastname;
                 break;
             case '%networkname%':
                 $commdata[$key] = get_site_option('site_name');
                 break;
             case '%networkurl%':
                 $commdata[$key] = get_site_option('siteurl');
                 break;
             case '%subscriptionname%':
                 if (!$sub_id) {
                     $ids = $member->get_subscription_ids();
                     if (!empty($ids)) {
                         $sub_id = $ids[0];
                     }
                 }
                 if (!empty($sub_id)) {
                     $sub = Membership_Plugin::factory()->get_subscription($sub_id);
                     $commdata[$key] = $sub->sub_name();
                 } else {
                     $commdata[$key] = '';
                 }
                 break;
             case '%levelname%':
                 if (!$level_id) {
                     $ids = $member->get_level_ids();
                     if (!empty($ids)) {
                         $level_id = $ids[0]->level_id;
                     }
                 }
                 if (!empty($level_id)) {
                     $level = Membership_Plugin::factory()->get_level($level_id);
                     $commdata[$key] = $level->level_title();
                 } else {
                     $commdata[$key] = '';
                 }
                 break;
             case '%accounturl%':
                 $commdata[$key] = M_get_account_permalink();
                 break;
             default:
                 $commdata[$key] = apply_filters('membership_commfield_' . $key, '', $user_id);
                 break;
         }
     }
     // Globally replace the values in the ping and then make it into an array to send
     $original_commmessage = str_replace(array_keys($commdata), array_values($commdata), stripslashes($this->comm->message));
     $original_subject = str_replace(array_keys($commdata), array_values($commdata), stripslashes($this->comm->subject));
     $html_message = wpautop($original_commmessage);
     $text_message = strip_tags(preg_replace('/\\<a .*?href="(.*?)".*?\\>.*?\\<\\/a\\>/is', '$0 [$1]', $original_commmessage));
     add_filter('wp_mail_content_type', 'M_Communications_set_html_content_type');
     $lambda_function = false;
     if ($wp_better_emails) {
         $html_message = apply_filters('wpbe_html_body', $wp_better_emails->template_vars_replacement($wp_better_emails->set_email_template($html_message, 'template')));
         $text_message = apply_filters('wpbe_plaintext_body', $wp_better_emails->template_vars_replacement($wp_better_emails->set_email_template($text_message, 'plaintext_template')));
         // lets use WP Better Email to wrap communication content if the plugin is used
         $lambda_function = create_function('', sprintf('return "%s";', addslashes($text_message)));
         add_filter('wpbe_plaintext_body', $lambda_function);
         add_filter('wpbe_plaintext_body', 'stripslashes', 11);
     } elseif (!defined('MEMBERSHIP_DONT_WRAP_COMMUNICATION')) {
         $html_message = "<html><head></head><body>{$html_message}</body></html>";
     }
     @wp_mail($member->user_email, stripslashes($original_subject), $html_message);
     remove_filter('wp_mail_content_type', 'M_Communications_set_html_content_type');
     if ($lambda_function) {
         remove_filter('wpbe_plaintext_body', $lambda_function);
         remove_filter('wpbe_plaintext_body', 'stripslashes', 11);
     }
 }
Exemplo n.º 26
0
    /**
     * Renders renew subscriptions.
     *
     * @since 3.5
     *
     * @access private
     * @global membershippublic $membershippublic The global membershippublic object.
     * @global array $M_options The settings array.
     */
    private function _render_renew_subscription()
    {
        global $membershippublic, $M_options;
        $factory = Membership_Plugin::factory();
        // The user has a subscription so we can display it with the information
        $member = current_member();
        $rels = array_filter((array) $member->get_relationships());
        if (empty($M_options['renewalperiod'])) {
            $M_options['renewalperiod'] = 7;
        }
        $success_msg = __('Your current subscriptions are listed here. You can renew, cancel or upgrade your subscriptions by using the forms below.', 'membership');
        ?>
<div id="membership-wrapper">
			<legend><?php 
        echo __('Your Subscriptions', 'membership');
        ?>
</legend>

			<div class="alert alert-success">
				<?php 
        echo $success_msg;
        ?>
			</div>

			<div class="priceboxes"><?php 
        foreach ($rels as $rel) {
            $sub = $factory->get_subscription($rel->sub_id);
            $nextlevel = $sub->get_next_level($rel->level_id, $rel->order_instance);
            $currentlevel = $sub->get_level_at($rel->level_id, $rel->order_instance);
            $expire_date = mysql2date('U', $rel->expirydate);
            $expire_date_string = date_i18n(get_option('date_format'), $expire_date);
            if (!empty($rel->usinggateway) && $rel->usinggateway != 'admin') {
                $gateway = Membership_Gateway::get_gateway($rel->usinggateway);
                if (!empty($gateway) && $gateway->issingle) {
                    $gatewayissingle = 'yes';
                } else {
                    $gatewayissingle = 'no';
                }
            } else {
                $gatewayissingle = 'admin';
            }
            ?>
<div class="pricebox subscribedbox" id="subscribedbox-<?php 
            echo $sub->id;
            ?>
">
						<div class="topbar">
							<span class="title"><?php 
            echo $sub->sub_name();
            ?>
</span>
						</div>

						<div class="pricedetails"><?php 
            if ($member->is_marked_for_expire($rel->sub_id)) {
                echo sprintf(__('Your membership has been cancelled and will expire on: <strong>%s</strong>', 'membership'), $expire_date_string);
            } else {
                if ($currentlevel->sub_type == 'indefinite') {
                    echo __('You are on an <strong>indefinite</strong> membership.', 'membership');
                } elseif ($gatewayissingle == 'yes') {
                    echo sprintf(__('Your membership is due to expire on: <strong>%s</strong> ', 'membership'), $expire_date_string);
                } else {
                    // Serial gateway
                    switch ($currentlevel->sub_type) {
                        case 'serial':
                            echo __('Your membership is set to <strong>automatically renew</strong>', 'membership');
                            break;
                        case 'finite':
                            if (!empty($nextlevel)) {
                                // We have a level we can move to next
                                echo __('Your membership is set to <strong>automatically renew</strong>', 'membership');
                            } else {
                                echo sprintf(__('Your membership is due to expire on: <strong>%s</strong> ', 'membership'), $expire_date_string);
                            }
                            break;
                    }
                }
            }
            // Get the last upgrade time
            $upgradedat = get_user_meta($member->ID, '_membership_last_upgraded', true);
            if (empty($upgradedat)) {
                $upgradedat = strtotime('-1 year');
            }
            $period = isset($M_options['upgradeperiod']) ? $M_options['upgradeperiod'] : 1;
            if (empty($period) && $period != 0) {
                $period = 1;
            }
            if (!$member->is_marked_for_expire($rel->sub_id) && $gatewayissingle == 'yes') {
                $renewalperiod = strtotime('-' . $M_options['renewalperiod'] . ' days', $expire_date);
                if ($nextlevel && time() >= $renewalperiod) {
                    // we have a next level so we can display the details and form for it
                    if ($member->has_active_payment($rel->sub_id, $nextlevel->level_id, $nextlevel->level_order)) {
                        ?>
<legend><?php 
                        echo __('Renewal your subscription', 'membership');
                        ?>
</legend>
										<div class="renew-form">
											<div class="formleft">
												<p><?php 
                        printf(__('Renewal for the %s following %s has been completed.', 'membership'), sprintf('<strong>%s %s</strong>', $nextlevel->level_period, $this->_get_period($nextlevel->level_period_unit, $nextlevel->level_period)), $expire_date_string);
                        ?>
</p>
											</div>
										</div> <!-- renew-form --><?php 
                    } else {
                        ?>
<div class="renew-form">
											<div class="formleft">
												<p><?php 
                        printf($nextlevel->level_price > 0 ? __('To renew your subscription for another %s following %s you will need to pay %s.', 'membership') : __('To renew your subscription for another %s following %s click on the button to the right.', 'membership'), sprintf('<strong>%s %s</strong>', $nextlevel->level_period, $this->_get_period($nextlevel->level_period_unit, $nextlevel->level_period)), $expire_date_string, sprintf('<strong>%s %s</strong>', $nextlevel->level_price, apply_filters('membership_real_currency_display', $M_options['paymentcurrency'])));
                        // Need to put in coupon code bit here in case they have signed up with one
                        $gateway->display_subscribe_button($sub, $sub->get_pricingarray(), $member->ID, $nextlevel->level_order);
                        ?>
</p>
											</div>
										</div> <!-- renew-form -->
										<?php 
                    }
                }
            }
            ?>
</div>

						<div class="bottombar">
							<div style="float:right;margin-right:10px"><?php 
            if (!$member->is_marked_for_expire($rel->sub_id)) {
                if ($gatewayissingle != 'admin' && method_exists($gateway, 'display_cancel_button')) {
                    $gateway->display_cancel_button($sub, $sub->get_pricingarray(), $member->ID);
                } else {
                    ?>
<form class="unsubbutton" method="post">
											<input type="hidden" name="action" value="unsubscribe">
											<input type="hidden" name="gateway" value="admin">
											<input type="hidden" name="subscription" value="<?php 
                    echo esc_attr($rel->sub_id);
                    ?>
">
											<input type="hidden" name="user" value="<?php 
                    echo esc_attr($member->ID);
                    ?>
">
											<?php 
                    wp_nonce_field('cancel-sub_' . $rel->sub_id);
                    ?>
											<input type="submit" value="<?php 
                    esc_attr_e('Unsubscribe', 'membership');
                    ?>
" class="button <?php 
                    echo apply_filters('membership_subscription_button_color', '');
                    ?>
">
										</form><?php 
                }
            }
            ?>
</div>
						</div>
					</div> <!-- price box --><?php 
            if ($upgradedat <= strtotime('-' . $period . ' days') || !current_user_has_subscription() && !empty($M_options['freeusersubscription'])) {
                $upgradesubs = array();
                foreach (array_filter((array) apply_filters('membership_override_upgrade_subscriptions', $membershippublic->get_subscriptions())) as $upgradesub) {
                    if ($upgradesub->id == $rel->sub_id || $member->on_sub($upgradesub->id)) {
                        // Don't want to show our current subscription as we will display this above.
                        continue;
                    }
                    $upgradesubs[] = $upgradesub;
                }
                // Show upgrades
                if (!empty($upgradesubs)) {
                    ?>
<legend class="upgradefrom-<?php 
                    echo $sub->id;
                    ?>
">
								<?php 
                    printf(_x('Upgrade from %s', 'Upgrade from {subscription name}', 'membership'), $sub->sub_name());
                    ?>
							</legend><?php 
                }
                foreach ($upgradesubs as $upgradesub) {
                    $subscription = $factory->get_subscription($upgradesub->id);
                    ?>
<div class="pricebox upgradebox upgradefrom-<?php 
                    echo $sub->id;
                    ?>
" id="upgradebox-<?php 
                    echo $subscription->id;
                    ?>
">
								<div class="topbar">
									<span class="title">
										<strong><?php 
                    _ex('Move to:', 'Move to another subscription', 'membership');
                    ?>
</strong>
										<?php 
                    echo $subscription->sub_name();
                    ?>
									</span>
								</div>

								<div class="pricedetails">
									<?php 
                    echo $subscription->sub_description();
                    ?>
								</div>

								<div class="bottombar">
									<div style="float:right;margin-right:10px"><?php 
                    // do an upgrade button
                    $pricing = $subscription->get_pricingarray();
                    if (!empty($pricing)) {
                        if ($gatewayissingle != 'admin') {
                            if ($currentlevel->level_price < 1) {
                                // We are on a free level, so need to do an upgrade from free
                                if (method_exists($gateway, 'display_upgrade_from_free_button')) {
                                    $gateway->display_upgrade_from_free_button($subscription, $pricing, $member->ID, $rel->sub_id, $sub->id);
                                }
                            } else {
                                // We want a normal upgrade button
                                if (method_exists($gateway, 'display_upgrade_button')) {
                                    $gateway->display_upgrade_button($subscription, $pricing, $member->ID, $rel->sub_id);
                                }
                            }
                        } else {
                            $class = '';
                            if (isset($M_options['formtype']) && $M_options['formtype'] == 'new') {
                                // pop up form
                                $link = add_query_arg(array('action' => 'buynow', 'subscription' => $subscription->id, 'from_subscription' => $rel->sub_id), admin_url('admin-ajax.php'));
                                $class = 'popover';
                            } else {
                                // original form
                                $link = add_query_arg(array('action' => 'registeruser', 'subscription' => $subscription->id, 'from_subscription' => $rel->sub_id), get_permalink($M_options['registration_page']));
                            }
                            ?>
<a href="<?php 
                            echo esc_url($link);
                            ?>
" class="button button-primary <?php 
                            echo $class;
                            ?>
 <?php 
                            echo esc_attr(apply_filters('membership_subscription_button_color', ''));
                            ?>
">
												<?php 
                            echo esc_html(apply_filters('membership_subscription_signup_text', __('Sign Up', 'membership')));
                            ?>
												</a><?php 
                        }
                    }
                    ?>
</div>

									<span class="price"><?php 
                    echo $subscription->sub_pricetext();
                    ?>
</span>
								</div>
							</div> <!-- pricebox --><?php 
                }
            }
        }
        ?>
</div> <!-- price boxes -->
		</div><!-- membership wrapper --><?php 
    }
Exemplo n.º 27
0
 /**
  * Adds "Enable Protection" menu to admin bar.
  *
  * @since 3.5
  * @action admin_bar_menu
  *
  * @access public
  * @param WP_Admin_Bar $wp_admin_bar Admin bar object.
  */
 public function add_enabled_protection_menu(WP_Admin_Bar $wp_admin_bar)
 {
     $linkurl = "admin.php?page=membership&action=activate";
     $linkurl = Membership_Plugin::is_global_tables() ? network_admin_url($linkurl, is_ssl() ? 'https' : 'http') : admin_url($linkurl, is_ssl() ? 'https' : 'http');
     $linkurl = wp_nonce_url($linkurl, 'toggle-plugin');
     $wp_admin_bar->add_menu(array('id' => 'membership', 'parent' => 'top-secondary', 'title' => __('Membership', 'membership') . ' : <span style="color:red;text-shadow:none">' . __('Disabled', 'membership') . "</span>", 'href' => $linkurl, 'meta' => array('title' => __('Click to Enable the Membership protection', 'membership'))));
     $wp_admin_bar->add_menu(array('parent' => 'membership', 'id' => 'membershipenable', 'title' => __('Enable Membership', 'membership'), 'href' => $linkurl));
 }
 function process_payment_form()
 {
     global $M_options, $M_membership_url;
     $return = array();
     if (!is_ssl()) {
         wp_die(__('You must use HTTPS in order to do this', 'membership'));
         exit;
     }
     $popup = isset($M_options['formtype']) && $M_options['formtype'] == 'new' ? true : false;
     $coupon = membership_get_current_coupon();
     if (empty($M_options['paymentcurrency'])) {
         $M_options['paymentcurrency'] = 'USD';
     }
     $factory = Membership_Plugin::factory();
     $subscription = $factory->get_subscription($_POST['subscription_id']);
     $pricing = $subscription->get_pricingarray();
     if (!empty($pricing) && !empty($coupon) && method_exists($coupon, 'valid_for_subscription') && $coupon->valid_for_subscription($subscription->id)) {
         $pricing = $coupon->apply_coupon_pricing($pricing);
     }
     $user_id = is_user_logged_in() ? get_current_user_id() : $_POST['user_id'];
     $user = get_userdata($user_id);
     $sub_id = $subscription->id;
     if (!empty($pricing)) {
         $free = true;
         foreach ($pricing as $key => $price) {
             if (!empty($price['amount']) && $price['amount'] > 0) {
                 $free = false;
             }
         }
         if (!$free) {
             if (count($pricing) == 1) {
                 // A basic price or a single subscription
                 if (in_array($pricing[0]['type'], array('indefinite', 'finite'))) {
                     // one-off payment - so we just use AIM instead
                     $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                     if (!empty($return) && $return['status'] == 'success') {
                         // The payment went through ok
                         $member = $factory->get_member($user_id);
                         if ($member) {
                             if ($member->has_subscription() && $member->on_sub($sub_id)) {
                                 //remove_action( 'membership_expire_subscription', 'membership_record_user_expire', 10, 2 );
                                 //remove_action( 'membership_add_subscription', 'membership_record_user_subscribe', 10, 4 );
                                 $member->expire_subscription($sub_id);
                                 $member->create_subscription($sub_id, $this->gateway);
                             } else {
                                 $member->create_subscription($sub_id, $this->gateway);
                             }
                         }
                         if ($popup && !empty($M_options['registrationcompleted_message'])) {
                             $return['redirect'] = 'no';
                             $registrationcompletedmessage = $this->get_completed_message($subscription);
                             $return['message'] = $registrationcompletedmessage;
                         } else {
                             $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                             $return['message'] = '';
                         }
                     } else {
                         // The payment didn't go through, so leave the return array holding the error
                     }
                     // Encode the return, echo it and exit so no more processing occurs
                     echo json_encode($return);
                     exit;
                 } elseif ($pricing[0]['type'] == 'serial') {
                     // Single serial subscription - we want to charge the first amount using AIM so we can validate the payment, then setup the subscription to start one period later
                     $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                     if (!empty($return) && $return['status'] == 'success') {
                         // The payment went through ok
                         $arbsubscription = new M_Gateway_Worker_AuthorizeNet_ARB(get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
                         $arbsubscription->setParameter('subscrName', $subscription->sub_name() . ' ' . __('subscription', 'membership'));
                         switch ($pricing[0]['unit']) {
                             case 'd':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                 $arbsubscription->setParameter('interval_unit', "days");
                                 $trialperiod = '+' . $pricing[0]['period'] . ' days';
                                 break;
                             case 'w':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 7);
                                 $arbsubscription->setParameter('interval_unit', "days");
                                 $trialperiod = '+' . $pricing[0]['period'] . ' weeks';
                                 break;
                             case 'm':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                 $arbsubscription->setParameter('interval_unit', "months");
                                 $trialperiod = '+' . $pricing[0]['period'] . ' months';
                                 break;
                             case 'y':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 12);
                                 $arbsubscription->setParameter('interval_unit', "months");
                                 $trialperiod = '+' . $pricing[0]['period'] . ' years';
                                 break;
                         }
                         // Add a period to the start date
                         $arbsubscription->setParameter('startDate', date("Y-m-d", strtotime($trialperiod)));
                         // Next period
                         $arbsubscription->setParameter('totalOccurrences', "9999");
                         // 9999 = ongoing subscription in ARB docs
                         $arbsubscription->setParameter('amount', number_format($pricing[0]['amount'], 2, '.', ''));
                         $arbsubscription->setParameter('cardNumber', $_POST['card_num']);
                         $arbsubscription->setParameter('expirationDate', $_POST['exp_year'] . '-' . $_POST['exp_month']);
                         $arbsubscription->setParameter('cardCode', $_POST['card_code']);
                         $arbsubscription->setParameter('firstName', $_POST['first_name']);
                         $arbsubscription->setParameter('lastName', $_POST['last_name']);
                         $arbsubscription->setParameter('address', $_POST['address']);
                         $arbsubscription->setParameter('zip', $_POST['zip']);
                         $arbsubscription->setParameter('customerId', $user->ID);
                         $arbsubscription->setParameter('customerEmail', is_email($user->user_email) != false ? $user->user_email : '');
                         $arbsubscription->createAccount();
                         if ($arbsubscription->isSuccessful()) {
                             // Get the subscription ID
                             $subscription_id = $arbsubscription->getSubscriberID();
                             $member = Membership_Plugin::factory()->get_member($user_id);
                             if ($member) {
                                 if ($member->has_subscription() && $member->on_sub($sub_id)) {
                                     //remove_action( 'membership_expire_subscription', 'membership_record_user_expire', 10, 2 );
                                     //remove_action( 'membership_add_subscription', 'membership_record_user_subscribe', 10, 4 );
                                     $member->expire_subscription($sub_id);
                                     $member->create_subscription($sub_id, $this->gateway);
                                 } else {
                                     $member->create_subscription($sub_id, $this->gateway);
                                 }
                                 // Store the subscription id in the user meta for later use
                                 update_user_meta($member->ID, 'membership_' . $this->gateway . '_subscription_' . $sub_id, $subscription_id);
                             }
                             if ($popup && !empty($M_options['registrationcompleted_message'])) {
                                 $return['redirect'] = 'no';
                                 $registrationcompletedmessage = $this->get_completed_message($subscription);
                                 $return['message'] = $registrationcompletedmessage;
                             } else {
                                 $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                                 $return['message'] = '';
                             }
                         } else {
                             // The subscription was not created!
                             $return['status'] = 'error';
                             $return['errors'][] = __('Sorry, your subscription could not be created.', 'membership');
                         }
                     } else {
                         // The payment didn't go through so return the error passed through from the aim processing
                     }
                     // Encode the return, echo it and exit so no more processing occurs
                     echo json_encode($return);
                     exit;
                 }
             } else {
                 // something much more complex
                 $processsecond = true;
                 $arbsubscription = new M_Gateway_Worker_AuthorizeNet_ARB(get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
                 $arbsubscription->setParameter('subscrName', $subscription->sub_name() . ' ' . __('subscription', 'membership'));
                 switch ($pricing[0]['type']) {
                     case 'finite':
                         // This is the one we are expecting here as anything else would be silly
                         // Set the trial period up
                         switch ($pricing[0]['unit']) {
                             case 'd':
                                 $trialperiod = '+' . $pricing[0]['period'] . ' days';
                                 break;
                             case 'w':
                                 $trialperiod = '+' . $pricing[0]['period'] . ' weeks';
                                 break;
                             case 'm':
                                 $trialperiod = '+' . $pricing[0]['period'] . ' months';
                                 break;
                             case 'y':
                                 $trialperiod = '+' . $pricing[0]['period'] . ' years';
                                 break;
                         }
                         break;
                     case 'indefinite':
                         // Hmmm - ok
                         $processsecond = false;
                         $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                         if (!empty($return) && $return['status'] == 'success') {
                             // The payment went through ok
                             $member = Membership_Plugin::factory()->get_member($user_id);
                             if ($member) {
                                 if ($member->has_subscription() && $member->on_sub($sub_id)) {
                                     //remove_action( 'membership_expire_subscription', 'membership_record_user_expire', 10, 2 );
                                     //remove_action( 'membership_add_subscription', 'membership_record_user_subscribe', 10, 4 );
                                     $member->expire_subscription($sub_id);
                                     $member->create_subscription($sub_id, $this->gateway);
                                 } else {
                                     $member->create_subscription($sub_id, $this->gateway);
                                 }
                             }
                             if ($popup && !empty($M_options['registrationcompleted_message'])) {
                                 $return['redirect'] = 'no';
                                 $registrationcompletedmessage = $this->get_completed_message($subscription);
                                 $return['message'] = $registrationcompletedmessage;
                             } else {
                                 $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                                 $return['message'] = '';
                             }
                         } else {
                             // The payment didn't go through, so leave the return array holding the error
                         }
                         // Encode the return, echo it and exit so no more processing occurs
                         echo json_encode($return);
                         exit;
                         break;
                     case 'serial':
                         // Hmmm - ok par deux
                         $processsecond = false;
                         $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                         if (!empty($return) && $return['status'] == 'success') {
                             // The payment went through ok
                             $arbsubscription = new M_Gateway_Worker_AuthorizeNet_ARB(get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
                             $arbsubscription->setParameter('subscrName', $subscription->sub_name() . ' ' . __('subscription', 'membership'));
                             switch ($pricing[0]['unit']) {
                                 case 'd':
                                     $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                     $arbsubscription->setParameter('interval_unit', "days");
                                     break;
                                 case 'w':
                                     $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 7);
                                     $arbsubscription->setParameter('interval_unit', "days");
                                     break;
                                 case 'm':
                                     $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                     $arbsubscription->setParameter('interval_unit', "months");
                                     break;
                                 case 'y':
                                     $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 12);
                                     $arbsubscription->setParameter('interval_unit', "months");
                                     break;
                             }
                             // Add a period to the start date
                             $arbsubscription->setParameter('startDate', date("Y-m-d", strtotime('+' . $arbsubscription->intervalLength . ' ' . $arbsubscription->intervalUnit)));
                             // Next period
                             $arbsubscription->setParameter('totalOccurrences', "9999");
                             // 9999 = ongoing subscription in ARB docs
                             $arbsubscription->setParameter('amount', number_format($pricing[0]['amount'], 2, '.', ''));
                             $arbsubscription->setParameter('cardNumber', $_POST['card_num']);
                             $arbsubscription->setParameter('expirationDate', $_POST['exp_year'] . '-' . $_POST['exp_month']);
                             $arbsubscription->setParameter('cardCode', $_POST['card_code']);
                             $arbsubscription->setParameter('firstName', $_POST['first_name']);
                             $arbsubscription->setParameter('lastName', $_POST['last_name']);
                             $arbsubscription->setParameter('address', $_POST['address']);
                             $arbsubscription->setParameter('zip', $_POST['zip']);
                             $arbsubscription->setParameter('customerId', $user->ID);
                             $arbsubscription->setParameter('customerEmail', is_email($user->user_email) != false ? $user->user_email : '');
                             $arbsubscription->createAccount();
                             if ($arbsubscription->isSuccessful()) {
                                 // Get the subscription ID
                                 $subscription_id = $arbsubscription->getSubscriberID();
                                 $member = Membership_Plugin::factory()->get_member($user_id);
                                 if ($member) {
                                     if ($member->has_subscription() && $member->on_sub($sub_id)) {
                                         //remove_action( 'membership_expire_subscription', 'membership_record_user_expire', 10, 2 );
                                         //remove_action( 'membership_add_subscription', 'membership_record_user_subscribe', 10, 4 );
                                         $member->expire_subscription($sub_id);
                                         $member->create_subscription($sub_id, $this->gateway);
                                     } else {
                                         $member->create_subscription($sub_id, $this->gateway);
                                     }
                                     // Store the subscription id in the user meta for later use
                                     update_user_meta($member->ID, 'membership_' . $this->gateway . '_subscription_' . $sub_id, $subscription_id);
                                 }
                                 if ($popup && !empty($M_options['registrationcompleted_message'])) {
                                     $return['redirect'] = 'no';
                                     $registrationcompletedmessage = $this->get_completed_message($subscription);
                                     $return['message'] = $registrationcompletedmessage;
                                 } else {
                                     $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                                     $return['message'] = '';
                                 }
                             } else {
                                 // The subscription was not created!
                                 $return['status'] = 'error';
                                 $return['errors'][] = __('Sorry, your subscription could not be created.', 'membership');
                             }
                         } else {
                             // The payment didn't go through so return the error passed through from the aim processing
                         }
                         // Encode the return, echo it and exit so no more processing occurs
                         echo json_encode($return);
                         exit;
                         break;
                 }
                 if ($processsecond == true) {
                     // We had an initial finite period so we need to see if we need to charge for it initially
                     if ($pricing[0]['amount'] >= 1) {
                         // The first period is not free so we have to charge for it
                         $return = $this->process_aim_payment($pricing[0]['amount'], $user, $subscription);
                     } else {
                         $return = array();
                         $return['status'] = 'success';
                     }
                     if (!empty($return) && $return['status'] == 'success') {
                         // The payment went through ok
                         $arbsubscription = new M_Gateway_Worker_AuthorizeNet_ARB(get_option($this->gateway . "_api_user", ''), get_option($this->gateway . "_api_key", ''), get_option($this->gateway . "_mode", 'sandbox') == 'sandbox');
                         $arbsubscription->setParameter('subscrName', $subscription->sub_name() . ' ' . __('subscription', 'membership'));
                         switch ($pricing[0]['unit']) {
                             case 'd':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                 $arbsubscription->setParameter('interval_unit', "days");
                                 break;
                             case 'w':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 7);
                                 $arbsubscription->setParameter('interval_unit', "days");
                                 break;
                             case 'm':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period']);
                                 $arbsubscription->setParameter('interval_unit', "months");
                                 break;
                             case 'y':
                                 $arbsubscription->setParameter('interval_length', $pricing[0]['period'] * 12);
                                 $arbsubscription->setParameter('interval_unit', "months");
                                 break;
                         }
                         // Add a period to the start date
                         $arbsubscription->setParameter('startDate', date("Y-m-d", strtotime($trialperiod)));
                         // Next period
                         switch ($pricing[1]['type']) {
                             case 'finite':
                                 // For finite and indefinite we set up a subscription and only charge the once
                             // For finite and indefinite we set up a subscription and only charge the once
                             case 'indefinite':
                                 $arbsubscription->setParameter('totalOccurrences', "1");
                                 // 1 = a single future charge
                                 break;
                             case 'serial':
                                 // For serial we set up the subscription to keep being charged
                                 $arbsubscription->setParameter('totalOccurrences', "9999");
                                 // 9999 = ongoing subscription in ARB docs
                                 break;
                         }
                         $arbsubscription->setParameter('amount', number_format($pricing[1]['amount'], 2, '.', ''));
                         $arbsubscription->setParameter('cardNumber', $_POST['card_num']);
                         $arbsubscription->setParameter('expirationDate', $_POST['exp_year'] . '-' . $_POST['exp_month']);
                         $arbsubscription->setParameter('cardCode', $_POST['card_code']);
                         $arbsubscription->setParameter('firstName', $_POST['first_name']);
                         $arbsubscription->setParameter('lastName', $_POST['last_name']);
                         $arbsubscription->setParameter('address', $_POST['address']);
                         $arbsubscription->setParameter('zip', $_POST['zip']);
                         $arbsubscription->setParameter('customerId', $user->ID);
                         $arbsubscription->setParameter('customerEmail', is_email($user->user_email) != false ? $user->user_email : '');
                         $arbsubscription->createAccount();
                         if ($arbsubscription->isSuccessful()) {
                             // Get the subscription ID
                             $subscription_id = $arbsubscription->getSubscriberID();
                             $member = Membership_Plugin::factory()->get_member($user_id);
                             if ($member) {
                                 if ($member->has_subscription() && $member->on_sub($sub_id)) {
                                     //remove_action( 'membership_expire_subscription', 'membership_record_user_expire', 10, 2 );
                                     //remove_action( 'membership_add_subscription', 'membership_record_user_subscribe', 10, 4 );
                                     $member->expire_subscription($sub_id);
                                     $member->create_subscription($sub_id, $this->gateway);
                                 } else {
                                     $member->create_subscription($sub_id, $this->gateway);
                                 }
                                 // Store the subscription id in the user meta for later use
                                 update_user_meta($member->ID, 'membership_' . $this->gateway . '_subscription_' . $sub_id, $subscription_id);
                             }
                             if ($popup && !empty($M_options['registrationcompleted_message'])) {
                                 $return['redirect'] = 'no';
                                 $registrationcompletedmessage = $this->get_completed_message($subscription);
                                 $return['message'] = $registrationcompletedmessage;
                             } else {
                                 $return['redirect'] = !strpos(home_url(), 'https:') ? str_replace('https:', 'http:', M_get_registrationcompleted_permalink()) : M_get_registrationcompleted_permalink();
                                 $return['message'] = '';
                             }
                         } else {
                             // The subscription was not created!
                             $return['status'] = 'error';
                             $return['errors'][] = __('Sorry, your subscription could not be created.', 'membership');
                         }
                     } else {
                         // The payment didn't go through so return the error passed through from the aim processing
                     }
                     // Encode the return, echo it and exit so no more processing occurs
                     echo json_encode($return);
                     exit;
                 }
             }
         }
     }
 }
Exemplo n.º 29
0
 /**
  * Removes registration page from menus that use wp_nav_menu
  *
  * @since 3.5.0.6
  *
  * @access public
  */
 function filter_nav_menu_items($items, $menu, $args)
 {
     global $M_options;
     if (!is_user_logged_in()) {
         //bail if not logged in
         return $items;
     }
     $current_user = wp_get_current_user();
     $member = Membership_Plugin::factory()->get_member($current_user->ID);
     if (!$member->has_subscription()) {
         //bail if member doesn't have subscription
         return $items;
     }
     foreach ($items as $key => $item) {
         if ($item->object_id == $M_options['registration_page']) {
             unset($items[$key]);
         }
     }
     return $items;
 }