Ejemplo n.º 1
0
 protected function user_name()
 {
     global $wpdb;
     if (!empty($this->fields['user_name'])) {
         return;
     }
     $user_name = filter_input(INPUT_POST, 'user_name', FILTER_SANITIZE_STRING);
     if (empty($user_name)) {
         $this->errors['user_name'] = SwpmUtils::_('Username is required');
         return;
     }
     if (!SwpmMemberUtils::is_valid_user_name($user_name)) {
         $this->errors['user_name'] = SwpmUtils::_('Username contains invalid character');
         return;
     }
     $saned = sanitize_text_field($user_name);
     $query = "SELECT count(member_id) FROM {$wpdb->prefix}swpm_members_tbl WHERE user_name= %s";
     $result = $wpdb->get_var($wpdb->prepare($query, strip_tags($saned)));
     if ($result > 0) {
         if ($saned != $this->fields['user_name']) {
             $this->errors['user_name'] = SwpmUtils::_('Username already exists.');
             return;
         }
     }
     $this->sanitized['user_name'] = $saned;
 }
 public function swpm_ty_page_rego_sc($args)
 {
     $output = '';
     $settings = SwpmSettings::get_instance();
     //If user is logged in then the purchase will be applied to the existing profile
     if (SwpmMemberUtils::is_member_logged_in()) {
         $username = SwpmMemberUtils::get_logged_in_members_username();
         $output .= '<div class="swpm-ty-page-registration-logged-in swpm-yellow-box">';
         $output .= '<p>' . SwpmUtils::_('Your membership profile will be updated to reflect the payment.') . '</p>';
         $output .= SwpmUtils::_('Your profile username: '******'</div>';
         return $output;
     }
     $output .= '<div class="swpm-ty-page-registration">';
     $member_data = SwpmUtils::get_incomplete_paid_member_info_by_ip();
     if ($member_data) {
         //Found a member profile record for this IP that needs to be completed
         $reg_page_url = $settings->get_value('registration-page-url');
         $rego_complete_url = add_query_arg(array('member_id' => $member_data->member_id, 'code' => $member_data->reg_code), $reg_page_url);
         $output .= '<div class="swpm-ty-page-registration-link swpm-yellow-box">';
         $output .= '<p>' . SwpmUtils::_('Click on the following link to complete the registration.') . '</p>';
         $output .= '<p><a href="' . $rego_complete_url . '">' . SwpmUtils::_('Click here to complete your paid registration') . '</a></p>';
         $output .= '</div>';
     } else {
         //Nothing found. Check again later.
         $output .= '<div class="swpm-ty-page-registration-link swpm-yellow-box">';
         $output .= SwpmUtils::_('If you have just made a membership payment then your payment is yet to be processed. Please check back in a few minutes. An email will be sent to you with the details shortly.');
         $output .= '</div>';
     }
     $output .= '</div>';
     //end of .swpm-ty-page-registration
     return $output;
 }
 function wp_password_reset_hook($user, $pass)
 {
     $swpm_user = SwpmMemberUtils::get_user_by_user_name($user->user_login);
     $swpm_id = $swpm_user->member_id;
     if (!empty($swpm_id)) {
         $password_hash = SwpmUtils::encrypt_password($pass);
         global $wpdb;
         $wpdb->update($wpdb->prefix . "swpm_members_tbl", array('password' => $password_hash), array('member_id' => $swpm_id));
     }
 }
 public function swpm_show_expiry_date_sc($args)
 {
     $output = '<div class="swpm-show-expiry-date">';
     if (SwpmMemberUtils::is_member_logged_in()) {
         $auth = SwpmAuth::get_instance();
         $expiry_date = $auth->get_expire_date();
         $output .= SwpmUtils::_('Expiry: ') . $expiry_date;
     } else {
         $output .= SwpmUtils::_('You are not logged-in as a member');
     }
     $output .= '</div>';
     return $output;
 }
 protected function send_reg_email()
 {
     global $wpdb;
     if (empty($this->member_info)) {
         return false;
     }
     $member_info = $this->member_info;
     $settings = SwpmSettings::get_instance();
     $subject = $settings->get_value('reg-complete-mail-subject');
     $body = $settings->get_value('reg-complete-mail-body');
     $from_address = $settings->get_value('email-from');
     $login_link = $settings->get_value('login-page-url');
     $headers = 'From: ' . $from_address . "\r\n";
     $member_info['membership_level_name'] = SwpmPermission::get_instance($member_info['membership_level'])->get('alias');
     $member_info['password'] = $member_info['plain_password'];
     $member_info['login_link'] = $login_link;
     $values = array_values($member_info);
     $keys = array_map('swpm_enclose_var', array_keys($member_info));
     $body = html_entity_decode($body);
     $body = str_replace($keys, $values, $body);
     $swpm_user = SwpmMemberUtils::get_user_by_user_name($member_info['user_name']);
     $member_id = $swpm_user->member_id;
     $body = SwpmMiscUtils::replace_dynamic_tags($body, $member_id);
     //Do the standard merge var replacement.
     $email = sanitize_email(filter_input(INPUT_POST, 'email', FILTER_UNSAFE_RAW));
     //Send notification email to the member
     wp_mail(trim($email), $subject, $body, $headers);
     SwpmLog::log_simple_debug('Member notification email sent to: ' . $email, true);
     if ($settings->get_value('enable-admin-notification-after-reg')) {
         //Send notification email to the site admin
         $admin_notification = $settings->get_value('admin-notification-email');
         $admin_notification = empty($admin_notification) ? $from_address : $admin_notification;
         $notify_emails_array = explode(",", $admin_notification);
         $headers = 'From: ' . $from_address . "\r\n";
         $subject = "Notification of New Member Registration";
         $admin_notify_body = $settings->get_value('reg-complete-mail-body-admin');
         if (empty($admin_notify_body)) {
             $admin_notify_body = "A new member has completed the registration.\n\n" . "Username: {user_name}\n" . "Email: {email}\n\n" . "Please login to the admin dashboard to view details of this user.\n\n" . "You can customize this email message from the Email Settings menu of the plugin.\n\n" . "Thank You";
         }
         $admin_notify_body = SwpmMiscUtils::replace_dynamic_tags($admin_notify_body, $member_id);
         //Do the standard merge var replacement.
         foreach ($notify_emails_array as $to_email) {
             $to_email = trim($to_email);
             wp_mail($to_email, $subject, $admin_notify_body, $headers);
             SwpmLog::log_simple_debug('Admin notification email sent to: ' . $to_email, true);
         }
     }
     return true;
 }
Ejemplo n.º 6
0
 public static function validate_user_name_ajax()
 {
     global $wpdb;
     $field_value = filter_input(INPUT_GET, 'fieldValue');
     $field_id = filter_input(INPUT_GET, 'fieldId');
     if (!SwpmMemberUtils::is_valid_user_name($field_value)) {
         echo '[ "' . $field_id . '",false,"&chi;&nbsp;' . SwpmUtils::_('Name contains invalid character') . '"]';
         exit;
     }
     $table = $wpdb->prefix . "swpm_members_tbl";
     $query = $wpdb->prepare("SELECT COUNT(*) FROM {$table} WHERE user_name = %s", $field_value);
     $exists = $wpdb->get_var($query) > 0;
     echo '[ "' . $field_id . ($exists ? '",false,"&chi;&nbsp;' . SwpmUtils::_('Aready taken') . '"]' : '",true,"&radic;&nbsp;' . SwpmUtils::_('Available') . '"]');
     exit;
 }
function swpm_render_pp_subscription_button_sc_output($button_code, $args)
{
    $button_id = isset($args['id']) ? $args['id'] : '';
    if (empty($button_id)) {
        return '<p style="color: red;">Error! swpm_render_pp_subscription_button_sc_output() function requires the button ID value to be passed to it.</p>';
    }
    //Check new_window parameter
    $window_target = isset($args['new_window']) ? 'target="_blank"' : '';
    $settings = SwpmSettings::get_instance();
    $button_cpt = get_post($button_id);
    //Retrieve the CPT for this button
    $membership_level_id = get_post_meta($button_id, 'membership_level_id', true);
    $paypal_email = get_post_meta($button_id, 'paypal_email', true);
    $payment_currency = get_post_meta($button_id, 'payment_currency', true);
    //Subscription payment details
    $billing_amount = get_post_meta($button_id, 'billing_amount', true);
    if (!is_numeric($billing_amount)) {
        return '<p style="color: red;">Error! The billing amount value of the button must be a numeric number. Example: 49.50 </p>';
    }
    $billing_amount = round($billing_amount, 2);
    //round the amount to 2 decimal place.
    $billing_cycle = get_post_meta($button_id, 'billing_cycle', true);
    $billing_cycle_term = get_post_meta($button_id, 'billing_cycle_term', true);
    $billing_cycle_count = get_post_meta($button_id, 'billing_cycle_count', true);
    $billing_reattempt = get_post_meta($button_id, 'billing_reattempt', true);
    //Trial billing details
    $trial_billing_amount = get_post_meta($button_id, 'trial_billing_amount', true);
    if (!empty($trial_billing_amount)) {
        if (!is_numeric($trial_billing_amount)) {
            return '<p style="color: red;">Error! The trial billing amount value of the button must be a numeric number. Example: 19.50 </p>';
        }
    }
    $trial_billing_cycle = get_post_meta($button_id, 'trial_billing_cycle', true);
    $trial_billing_cycle_term = get_post_meta($button_id, 'trial_billing_cycle_term', true);
    $sandbox_enabled = $settings->get_value('enable-sandbox-testing');
    $notify_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL . '/?swpm_process_ipn=1';
    $return_url = get_post_meta($button_id, 'return_url', true);
    if (empty($return_url)) {
        $return_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL;
    }
    $cancel_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL;
    $user_ip = SwpmUtils::get_user_ip_address();
    $_SESSION['swpm_payment_button_interaction'] = $user_ip;
    //Custom field data
    $custom_field_value = 'subsc_ref=' . $membership_level_id;
    $custom_field_value .= '&user_ip=' . $user_ip;
    if (SwpmMemberUtils::is_member_logged_in()) {
        $custom_field_value .= '&swpm_id=' . SwpmMemberUtils::get_logged_in_members_id();
    }
    $custom_field_value = apply_filters('swpm_custom_field_value_filter', $custom_field_value);
    /* === PayPal Subscription Button Form === */
    $output = '';
    $output .= '<div class="swpm-button-wrapper swpm-pp-subscription-wrapper">';
    if ($sandbox_enabled) {
        $output .= '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" ' . $window_target . '>';
    } else {
        $output .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" ' . $window_target . '>';
    }
    $output .= '<input type="hidden" name="cmd" value="_xclick-subscriptions" />';
    $output .= '<input type="hidden" name="charset" value="utf-8" />';
    $output .= '<input type="hidden" name="bn" value="TipsandTricks_SP" />';
    $output .= '<input type="hidden" name="business" value="' . $paypal_email . '" />';
    $output .= '<input type="hidden" name="currency_code" value="' . $payment_currency . '" />';
    $output .= '<input type="hidden" name="item_number" value="' . $button_id . '" />';
    $output .= '<input type="hidden" name="item_name" value="' . htmlspecialchars($button_cpt->post_title) . '" />';
    //Check trial billing
    if (!empty($trial_billing_cycle)) {
        $output .= '<input type="hidden" name="a1" value="' . $trial_billing_amount . '" /><input type="hidden" name="p1" value="' . $trial_billing_cycle . '" /><input type="hidden" name="t1" value="' . $trial_billing_cycle_term . '" />';
    }
    //Main subscription billing
    if (!empty($billing_cycle)) {
        $output .= '<input type="hidden" name="a3" value="' . $billing_amount . '" /><input type="hidden" name="p3" value="' . $billing_cycle . '" /><input type="hidden" name="t3" value="' . $billing_cycle_term . '" />';
    }
    //Re-attempt on failure
    if ($billing_reattempt != '') {
        $output .= '<input type="hidden" name="sra" value="1" />';
    }
    //Reccurring times
    if ($billing_cycle_count > 1) {
        //do not include srt value if billing cycle count set to 1 or a negetive number.
        $output .= '<input type="hidden" name="src" value="1" /><input type="hidden" name="srt" value="' . $billing_cycle_count . '" />';
    } else {
        if (empty($billing_cycle_count)) {
            $output .= '<input type="hidden" name="src" value="1" />';
        }
    }
    //Other required data
    $output .= '<input type="hidden" name="no_shipping" value="1" />';
    //Do not prompt for an address
    $output .= '<input type="hidden" name="notify_url" value="' . $notify_url . '" />';
    $output .= '<input type="hidden" name="return" value="' . $return_url . '" />';
    $output .= '<input type="hidden" name="cancel_return" value="' . $cancel_url . '" />';
    $output .= '<input type="hidden" name="custom" value="' . $custom_field_value . '" />';
    //Filter to add additional payment input fields to the form (example: langauge code or country code etc).
    $output .= apply_filters('swpm_pp_payment_form_additional_fields', '');
    //Submit button
    $button_image_url = get_post_meta($button_id, 'button_image_url', true);
    if (!empty($button_image_url)) {
        $output .= '<input type="image" src="' . $button_image_url . '" class="swpm-subscription-button-submit" alt="' . SwpmUtils::_('Subscribe Now') . '"/>';
    } else {
        $button_text = isset($args['button_text']) ? $args['button_text'] : SwpmUtils::_('Subscribe Now');
        $output .= '<input type="submit" class="swpm-subscription-button-submit" value="' . $button_text . '" />';
    }
    $output .= '</form>';
    //End .form
    $output .= '</div>';
    //End .swpm_button_wrapper
    return $output;
}
function swpm_render_stripe_buy_now_button_sc_output($button_code, $args)
{
    $button_id = isset($args['id']) ? $args['id'] : '';
    if (empty($button_id)) {
        return '<p class="swpm-red-box">Error! swpm_render_stripe_buy_now_button_sc_output() function requires the button ID value to be passed to it.</p>';
    }
    //Check new_window parameter
    $window_target = isset($args['new_window']) ? 'target="_blank"' : '';
    $button_text = isset($args['button_text']) ? $args['button_text'] : SwpmUtils::_('Buy Now');
    $billing_address = isset($args['billing_address']) ? '1' : '';
    //By default don't show the billing address in the checkout form.
    $item_logo = '';
    //Can be used to show an item logo or thumbnail in the checkout form.
    $settings = SwpmSettings::get_instance();
    $button_cpt = get_post($button_id);
    //Retrieve the CPT for this button
    $item_name = htmlspecialchars($button_cpt->post_title);
    $membership_level_id = get_post_meta($button_id, 'membership_level_id', true);
    //Verify that this membership level exists (to prevent user paying for a level that has been deleted)
    if (!SwpmUtils::membership_level_id_exists($membership_level_id)) {
        return '<p class="swpm-red-box">Error! The membership level specified in this button does not exist. You may have deleted this membership level. Edit the button and use the correct membership level.</p>';
    }
    //Payment amount and currency
    $payment_amount = get_post_meta($button_id, 'payment_amount', true);
    if (!is_numeric($payment_amount)) {
        return '<p class="swpm-red-box">Error! The payment amount value of the button must be a numeric number. Example: 49.50 </p>';
    }
    $payment_amount = round($payment_amount, 2);
    //round the amount to 2 decimal place.
    $price_in_cents = $payment_amount * 100;
    //The amount (in cents). This value is passed to Stripe API.
    $payment_currency = get_post_meta($button_id, 'payment_currency', true);
    //Return, cancel, notifiy URLs
    $return_url = get_post_meta($button_id, 'return_url', true);
    if (empty($return_url)) {
        $return_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL;
    }
    $notify_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL . '/?swpm_process_stripe_buy_now=1';
    //We are going to use it to do post payment processing.
    //$button_image_url = get_post_meta($button_id, 'button_image_url', true);//Stripe doesn't currenty support button image for their standard checkout.
    //User's IP address
    $user_ip = SwpmUtils::get_user_ip_address();
    $_SESSION['swpm_payment_button_interaction'] = $user_ip;
    //Custom field data
    $custom_field_value = 'subsc_ref=' . $membership_level_id;
    $custom_field_value .= '&user_ip=' . $user_ip;
    if (SwpmMemberUtils::is_member_logged_in()) {
        $custom_field_value .= '&swpm_id=' . SwpmMemberUtils::get_logged_in_members_id();
    }
    $custom_field_value = apply_filters('swpm_custom_field_value_filter', $custom_field_value);
    //Sandbox settings
    $sandbox_enabled = $settings->get_value('enable-sandbox-testing');
    //API keys
    $stripe_test_secret_key = get_post_meta($button_id, 'stripe_test_secret_key', true);
    $stripe_test_publishable_key = get_post_meta($button_id, 'stripe_test_publishable_key', true);
    $stripe_live_secret_key = get_post_meta($button_id, 'stripe_live_secret_key', true);
    $stripe_live_publishable_key = get_post_meta($button_id, 'stripe_live_publishable_key', true);
    if ($sandbox_enabled) {
        $publishable_key = $stripe_test_publishable_key;
        //Use sandbox API key
    } else {
        $publishable_key = $stripe_live_publishable_key;
        //Use live API key
    }
    /* === Stripe Buy Now Button Form === */
    $output = '';
    $output .= '<div class="swpm-button-wrapper swpm-stripe-buy-now-wrapper">';
    $output .= "<form action='" . $notify_url . "' METHOD='POST'> ";
    $output .= "<script src='https://checkout.stripe.com/checkout.js' class='stripe-button'\r\n        data-key='" . $publishable_key . "'\r\n        data-panel-label='Pay'\r\n        data-amount='{$price_in_cents}'\r\n        data-name='{$item_name}'";
    $output .= "data-description='{$payment_amount} {$payment_currency}'";
    $output .= "data-label='{$button_text}'";
    //Stripe doesn't currenty support button image for their standard checkout.
    $output .= "data-currency='{$payment_currency}'";
    if (!empty($item_logo)) {
        //Show item logo/thumbnail in the stripe payment window
        $output .= "data-image='{$item_logo}'";
    }
    if (!empty($billing_address)) {
        //Show billing address in the stipe payment window
        $output .= "data-billingAddress='true'";
    }
    $output .= apply_filters('swpm_stripe_additional_checkout_data_parameters', '');
    //Filter to allow the addition of extra data parameters for stripe checkout.
    $output .= "></script>";
    $output .= wp_nonce_field('stripe_payments', '_wpnonce', true, false);
    $output .= '<input type="hidden" name="item_number" value="' . $button_id . '" />';
    $output .= "<input type='hidden' value='{$item_name}' name='item_name' />";
    $output .= "<input type='hidden' value='{$payment_amount}' name='item_price' />";
    $output .= "<input type='hidden' value='{$payment_currency}' name='currency_code' />";
    $output .= "<input type='hidden' value='{$custom_field_value}' name='custom' />";
    //Filter to add additional payment input fields to the form.
    $output .= apply_filters('swpm_stripe_payment_form_additional_fields', '');
    $output .= "</form>";
    $output .= '</div>';
    //End .swpm_button_wrapper
    return $output;
}
 public static function delete_user_by_id($id)
 {
     $swpm_user = SwpmMemberUtils::get_user_by_id($id);
     $user_name = $swpm_user->user_name;
     SwpmMembers::delete_wp_user($user_name);
     //Deletes the WP User record
     SwpmMembers::delete_swpm_user_by_id($id);
     //Deletes the SWPM record
 }
 public static function replace_dynamic_tags($msg_body, $member_id, $additional_args = '')
 {
     $settings = SwpmSettings::get_instance();
     $user_record = SwpmMemberUtils::get_user_by_id($member_id);
     $password = '';
     $reg_link = '';
     if (!empty($additional_args)) {
         $password = isset($additional_args['password']) ? $additional_args['password'] : $password;
         $reg_link = isset($additional_args['reg_link']) ? $additional_args['reg_link'] : $reg_link;
     }
     $login_link = $settings->get_value('login-page-url');
     //Define the replacable tags
     $tags = array("{member_id}", "{user_name}", "{first_name}", "{last_name}", "{membership_level}", "{account_state}", "{email}", "{phone}", "{member_since}", "{subscription_starts}", "{company_name}", "{password}", "{login_link}", "{reg_link}");
     //Define the values
     $vals = array($member_id, $user_record->user_name, $user_record->first_name, $user_record->last_name, $user_record->membership_level, $user_record->account_state, $user_record->email, $user_record->phone, $user_record->member_since, $user_record->subscription_starts, $user_record->company_name, $password, $login_link, $reg_link);
     $msg_body = str_replace($tags, $vals, $msg_body);
     return $msg_body;
 }
Ejemplo n.º 11
0
!</h1>

<p>If you have any problems with these downloads, please contact us and we'll get it sorted pronto.</p>

                <?php 
}
while (have_posts()) {
    the_post();
    get_template_part('content', 'page');
}
?>
                
                
                <?php 
if ($auth->is_logged_in()) {
    $member_level = SwpmMemberUtils::get_logged_in_members_level();
    ?>

<div id="tabs">
  <ul>
    <li class="li-inline ui-tab-headers"><a href="#tabs-1">Downloads</a></li>
    <li class="li-inline ui-tab-headers"><a href="#tabs-2"  id="tabs2">Edit Profile</a></li>
  </ul>

  <?php 
    if (isset($_POST['swpm_editprofile_submit'])) {
        ?>
        <script>
        document.getElementById('tabs2').click();
        window.scrollTo(0,0);
        </script>
Ejemplo n.º 12
0
 public static function delete_user_by_id($id)
 {
     if (!is_numeric($id)) {
         wp_die('Error! Member ID must be numeric.');
     }
     $swpm_user = SwpmMemberUtils::get_user_by_id($id);
     $user_name = $swpm_user->user_name;
     SwpmMembers::delete_wp_user($user_name);
     //Deletes the WP User record
     SwpmMembers::delete_swpm_user_by_id($id);
     //Deletes the SWPM record
 }