Ejemplo n.º 1
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;
 }