public static function initdb() { $settings = SwpmSettings::get_instance(); $installed_version = $settings->get_value('swpm-active-version'); //Set other default settings values $reg_prompt_email_subject = "Complete your registration"; $reg_prompt_email_body = "Dear {first_name} {last_name}" . "\n\nThank you for joining us!" . "\n\nPlease complete your registration by visiting the following link:" . "\n\n{reg_link}" . "\n\nThank You"; $reg_email_subject = "Your registration is complete"; $reg_email_body = "Dear {first_name} {last_name}\n\n" . "Your registration is now complete!\n\n" . "Registration details:\n" . "Username: {user_name}\n" . "Password: {password}\n\n" . "Please login to the member area at the following URL:\n\n" . "{login_link}\n\n" . "Thank You"; $upgrade_email_subject = "Subject for email sent after account upgrade"; $upgrade_email_body = "Dear {first_name} {last_name}" . "\n\nYour Account Has Been Upgraded." . "\n\nThank You"; $reset_email_subject = get_bloginfo('name') . ": New Password"; $reset_email_body = "Dear {first_name} {last_name}" . "\n\nHere is your new password:"******"\n\nUsername: {user_name}" . "\nPassword: {password}" . "\n\nYou can change the password from the edit profile section of the site (after you log into the site)" . "\n\nThank You"; $status_change_email_subject = "Account Updated!"; $status_change_email_body = "Dear {first_name} {last_name}," . "\n\nYour account status has been updated!" . " Please login to the member area at the following URL:" . "\n\n {login_link}" . "\n\nThank You"; $bulk_activate_email_subject = "Account Activated!"; $bulk_activate_email_body = "Hi," . "\n\nYour account has been activated!" . "\n\nYou can now login to the member area." . "\n\nThank You"; if (empty($installed_version)) { //Do fresh install tasks //Create the mandatory pages (if they are not there) SwpmMiscUtils::create_mandatory_wp_pages(); //End of page creation $settings->set_value('reg-complete-mail-subject', stripslashes($reg_email_subject))->set_value('reg-complete-mail-body', stripslashes($reg_email_body))->set_value('reg-prompt-complete-mail-subject', stripslashes($reg_prompt_email_subject))->set_value('reg-prompt-complete-mail-body', stripslashes($reg_prompt_email_body))->set_value('upgrade-complete-mail-subject', stripslashes($upgrade_email_subject))->set_value('upgrade-complete-mail-body', stripslashes($upgrade_email_body))->set_value('reset-mail-subject', stripslashes($reset_email_subject))->set_value('reset-mail-body', stripslashes($reset_email_body))->set_value('account-change-email-subject', stripslashes($status_change_email_subject))->set_value('account-change-email-body', stripslashes($status_change_email_body))->set_value('email-from', trim(get_option('admin_email'))); $settings->set_value('bulk-activate-notify-mail-subject', stripslashes($bulk_activate_email_subject)); $settings->set_value('bulk-activate-notify-mail-body', stripslashes($bulk_activate_email_body)); } if (version_compare($installed_version, SIMPLE_WP_MEMBERSHIP_VER) == -1) { //Do upgrade tasks } $settings->set_value('swpm-active-version', SIMPLE_WP_MEMBERSHIP_VER)->save(); //save everything. }
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; }
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); $email = sanitize_email(filter_input(INPUT_POST, 'email', FILTER_UNSAFE_RAW)); 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')) { $to_email_address = $settings->get_value('admin-notification-email'); $headers = 'From: ' . $from_address . "\r\n"; $subject = "Notification of New Member Registration"; $body = "A new member has registered. The following email was sent to the member." . "\n\n-------Member Email----------\n" . $body . "\n\n------End------\n"; $admin_notification = empty($to_email_address) ? $from_address : $to_email_address; wp_mail(trim($admin_notification), $subject, $body, $headers); SwpmLog::log_simple_debug('Admin notification email sent to: ' . $admin_notification, true); } return true; }
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; }
public static function check_and_restrict_comment_posting_to_members() { $allow_comments = SwpmSettings::get_instance()->get_value('members-login-to-comment'); if (empty($allow_comments)) { return; } if (is_admin()) { return; } if (SwpmAuth::get_instance()->is_logged_in()) { return; } $comment_id = filter_input(INPUT_POST, 'comment_post_ID'); if (empty($comment_id)) { return; } //Stop this request -> 1)we are on the front-side. 2) Comment posted by a not logged in member. 3) comment_post_ID missing. $_POST = array(); wp_die(SwpmUtils::_('Comments not allowed by a non-member.')); }
public function edit($id) { global $wpdb; $query = $wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "swpm_members_tbl WHERE member_id = %d", $id); $member = $wpdb->get_row($query, ARRAY_A); $email_address = $member['email']; $user_name = $member['user_name']; unset($member['member_id']); unset($member['user_name']); $form = new SwpmForm($member); if ($form->is_valid()) { $member = $form->get_sanitized(); $plain_password = isset($member['plain_password']) ? $member['plain_password'] : ""; SwpmUtils::update_wp_user($user_name, $member); unset($member['plain_password']); $wpdb->update($wpdb->prefix . "swpm_members_tbl", $member, array('member_id' => $id)); $message = array('succeeded' => true, 'message' => '<p>Member profile updated successfully.</p>'); do_action('swpm_admin_edit_custom_fields', $member + array('member_id' => $id)); SwpmTransfer::get_instance()->set('status', $message); $send_notification = filter_input(INPUT_POST, 'account_status_change'); if (!empty($send_notification)) { $settings = SwpmSettings::get_instance(); $from_address = $settings->get_value('email-from'); $headers = 'From: ' . $from_address . "\r\n"; $subject = filter_input(INPUT_POST, 'notificationmailhead'); $body = filter_input(INPUT_POST, 'notificationmailbody'); $settings->set_value('account-change-email-body', $body)->set_value('account-change-email-subject', $subject)->save(); $member['login_link'] = $settings->get_value('login-page-url'); $member['user_name'] = $user_name; $member['password'] = empty($plain_password) ? SwpmUtils::_("Your current password") : $plain_password; $values = array_values($member); $keys = array_map('swpm_enclose_var', array_keys($member)); $body = html_entity_decode(str_replace($keys, $values, $body)); wp_mail($email_address, $subject, $body, $headers); } wp_redirect('admin.php?page=simple_wp_membership'); exit(0); } $message = array('succeeded' => false, 'message' => SwpmUtils::_('Please correct the following:'), 'extra' => $form->get_errors()); SwpmTransfer::get_instance()->set('status', $message); }
public function delete_pending_account() { global $wpdb; $interval = SwpmSettings::get_instance()->get_value('delete-pending-account'); if (empty($interval)) { return; } for ($counter = 0;; $counter += 100) { $query = $wpdb->prepare("SELECT member_id\n FROM \n {$wpdb->prefix}swpm_members_tbl \n WHERE account_state='pending' \n AND subscription_starts < DATE_SUB(NOW(), INTERVAL %d MONTH) LIMIT %d, 100", $interval, $counter); $results = $wpdb->get_results($query); if (empty($results)) { break; } $to_delete = array(); foreach ($results as $result) { $to_delete[] = $result->member_id; } if (count($to_delete) > 0) { SwpmLog::log_simple_debug("Auto deleting pending account.", true); $query = "DELETE FROM {$wpdb->prefix}swpm_members_tbl \n WHERE member_id IN (" . implode(',', $to_delete) . ")"; $wpdb->query($query); } } }
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; }
public function reset_password($email) { $email = sanitize_email($email); if (!is_email($email)) { $message = '<div class="swpm-reset-pw-error">' . SwpmUtils::_("Email address not valid.") . '</div>'; $message = array('succeeded' => false, 'message' => $message); SwpmTransfer::get_instance()->set('status', $message); return; } global $wpdb; $query = 'SELECT member_id,user_name,first_name, last_name FROM ' . $wpdb->prefix . 'swpm_members_tbl ' . ' WHERE email = %s'; $user = $wpdb->get_row($wpdb->prepare($query, $email)); if (empty($user)) { $message = '<div class="swpm-reset-pw-error">' . SwpmUtils::_("No user found with that email address.") . '</div>'; $message .= '<div class="swpm-reset-pw-error-email">' . SwpmUtils::_("Email Address: ") . $email . '</div>'; $message = array('succeeded' => false, 'message' => $message); SwpmTransfer::get_instance()->set('status', $message); return; } $settings = SwpmSettings::get_instance(); $password = wp_generate_password(); $password_hash = SwpmUtils::encrypt_password(trim($password)); //should use $saned??; $wpdb->update($wpdb->prefix . "swpm_members_tbl", array('password' => $password_hash), array('member_id' => $user->member_id)); //Update wp user password add_filter('send_password_change_email', array(&$this, 'dont_send_password_change_email'), 1, 3); //Stop wordpress from sending a reset password email to admin. SwpmUtils::update_wp_user($user->user_name, array('plain_password' => $password)); $body = $settings->get_value('reset-mail-body'); $subject = $settings->get_value('reset-mail-subject'); $search = array('{user_name}', '{first_name}', '{last_name}', '{password}'); $replace = array($user->user_name, $user->first_name, $user->last_name, $password); $body = html_entity_decode($body); $body = str_replace($search, $replace, $body); $from = $settings->get_value('email-from'); $headers = "From: " . $from . "\r\n"; wp_mail($email, $subject, $body, $headers); SwpmLog::log_simple_debug("Member password has been reset. Password reset email sent to: " . $email, true); $message = '<div class="swpm-reset-pw-success">' . SwpmUtils::_("New password has been sent to your email address.") . '</div>'; $message .= '<div class="swpm-reset-pw-success-email">' . SwpmUtils::_("Email Address: ") . $email . '</div>'; $message = array('succeeded' => false, 'message' => $message); SwpmTransfer::get_instance()->set('status', $message); }
function swpm_debug_log_subsc($message, $success, $end = false) { $settings = SwpmSettings::get_instance(); $debug_enabled = $settings->get_value('enable-debug'); if (empty($debug_enabled)) { //Debug is not enabled return; } $debug_log_file_name = SIMPLE_WP_MEMBERSHIP_PATH . 'log.txt'; // Timestamp $text = '[' . date('m/d/Y g:i A') . '] - ' . ($success ? 'SUCCESS :' : 'FAILURE :') . $message . "\n"; if ($end) { $text .= "\n------------------------------------------------------------------\n\n"; } // Write to log $fp = fopen($debug_log_file_name, 'a'); fwrite($fp, $text); fclose($fp); // close file }
public function filter_post_with_moretag($id, $more_link, $more_link_text) { $this->moretags[] = $id; if ($this->can_i_read_post($id)) { return $more_link; } $msg = '<div class="swpm-margin-top-10">' . SwpmUtils::_("You need to login to view the rest of the content. ") . SwpmSettings::get_instance()->get_login_link() . '</div>'; return apply_filters('swpm_not_logged_in_more_tag_msg', $msg); }
public static function get_renewal_link() { $renewal = SwpmSettings::get_instance()->get_value('renewal-page-url'); if (empty($renewal)) { //No renewal page is configured so don't show any renewal page link. It is okay to have no renewal page configured. return ''; } return SwpmUtils::_('Please') . ' <a class="swpm-renewal-link" href="' . $renewal . '">' . SwpmUtils::_('renew') . '</a> ' . SwpmUtils::_(' your account to gain access to this content.'); }
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 function admin_settings() { $current_tab = SwpmSettings::get_instance()->current_tab; switch ($current_tab) { case 6: include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_addon_settings.php'; break; case 4: $link_for = filter_input(INPUT_POST, 'swpm_link_for', FILTER_SANITIZE_STRING); $member_id = filter_input(INPUT_POST, 'member_id', FILTER_SANITIZE_NUMBER_INT); $send_email = filter_input(INPUT_POST, 'swpm_reminder_email', FILTER_SANITIZE_NUMBER_INT); $links = SwpmUtils::get_registration_link($link_for, $send_email, $member_id); include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_tools_settings.php'; break; case 2: include SIMPLE_WP_MEMBERSHIP_PATH . 'views/payments/admin_payment_settings.php'; break; default: include SIMPLE_WP_MEMBERSHIP_PATH . 'views/admin_settings.php'; break; } }
public function admin_settings_menu() { $settings = SwpmSettings::get_instance(); $settings->handle_main_settings_admin_menu(); }
public static function is_current_url_a_system_page() { $current_page_url = SwpmMiscUtils::get_current_page_url(); //Check if the current page is the membership renewal page. $renewal_url = SwpmSettings::get_instance()->get_value('renewal-page-url'); if (empty($renewal_url)) { return false; } if (SwpmMiscUtils::compare_url($renewal_url, $current_page_url)) { return true; } //Check if the current page is the membership logn page. $login_page_url = SwpmSettings::get_instance()->get_value('login-page-url'); if (empty($login_page_url)) { return false; } if (SwpmMiscUtils::compare_url($login_page_url, $current_page_url)) { return true; } //Check if the current page is the membership join page. $registration_page_url = SwpmSettings::get_instance()->get_value('registration-page-url'); if (empty($registration_page_url)) { return false; } if (SwpmMiscUtils::compare_url($registration_page_url, $current_page_url)) { return true; } return false; }
public function handle_stripe_ipn() { SwpmLog::log_simple_debug("Stripe Buy Now IPN received. Processing request...", true); //SwpmLog::log_simple_debug(print_r($_REQUEST, true), true);//Useful for debugging purpose //Include the Stripe library. include SIMPLE_WP_MEMBERSHIP_PATH . 'lib/stripe-gateway/init.php'; //Read and sanitize the request parameters. $button_id = sanitize_text_field($_REQUEST['item_number']); $button_id = absint($button_id); $button_title = sanitize_text_field($_REQUEST['item_name']); $payment_amount = sanitize_text_field($_REQUEST['item_price']); $price_in_cents = $payment_amount * 100; //The amount (in cents). This value is used in Stripe API. $currency_code = sanitize_text_field($_REQUEST['currency_code']); $stripe_token = sanitize_text_field($_POST['stripeToken']); $stripe_token_type = sanitize_text_field($_POST['stripeTokenType']); $stripe_email = sanitize_email($_POST['stripeEmail']); //Retrieve the CPT for this button $button_cpt = get_post($button_id); if (!$button_cpt) { //Fatal error. Could not find this payment button post object. SwpmLog::log_simple_debug("Fatal Error! Failed to retrieve the payment button post object for the given button ID: " . $button_id, false); wp_die("Fatal Error! Payment button (ID: " . $button_id . ") does not exist. This request will fail."); } $membership_level_id = get_post_meta($button_id, 'membership_level_id', true); //Validate and verify some of the main values. $true_payment_amount = get_post_meta($button_id, 'payment_amount', true); if ($payment_amount != $true_payment_amount) { //Fatal error. Payment amount may have been tampered with. $error_msg = 'Fatal Error! Received payment amount (' . $payment_amount . ') does not match with the original amount (' . $true_payment_amount . ')'; SwpmLog::log_simple_debug($error_msg, false); wp_die($error_msg); } $true_currency_code = get_post_meta($button_id, 'payment_currency', true); if ($currency_code != $true_currency_code) { //Fatal error. Currency code may have been tampered with. $error_msg = 'Fatal Error! Received currency code (' . $currency_code . ') does not match with the original code (' . $true_currency_code . ')'; SwpmLog::log_simple_debug($error_msg, false); wp_die($error_msg); } //Validation passed. Go ahead with the charge. //Sandbox and other settings $settings = SwpmSettings::get_instance(); $sandbox_enabled = $settings->get_value('enable-sandbox-testing'); if ($sandbox_enabled) { SwpmLog::log_simple_debug("Sandbox payment mode is enabled. Using test API key details.", true); $secret_key = get_post_meta($button_id, 'stripe_test_secret_key', true); //Use sandbox API key } else { $secret_key = get_post_meta($button_id, 'stripe_live_secret_key', true); //Use live API key } //Set secret API key in the Stripe library \Stripe\Stripe::setApiKey($secret_key); // Get the credit card details submitted by the form $token = $stripe_token; // Create the charge on Stripe's servers - this will charge the user's card try { $charge = \Stripe\Charge::create(array("amount" => $price_in_cents, "currency" => strtolower($currency_code), "source" => $token, "description" => $button_title)); } catch (\Stripe\Error\Card $e) { // The card has been declined SwpmLog::log_simple_debug("Stripe Charge Error! The card has been declined. " . $e->getMessage(), false); $body = $e->getJsonBody(); $error = $body['error']; $error_string = print_r($error, true); SwpmLog::log_simple_debug("Error details: " . $error_string, false); wp_die("Stripe Charge Error! Card charge has been declined. " . $e->getMessage() . $error_string); } //Everything went ahead smoothly with the charge. SwpmLog::log_simple_debug("Stripe Buy Now charge successful.", true); //Grab the charge ID and set it as the transaction ID. $txn_id = $charge->id; //$charge->balance_transaction; //The charge ID can be used to retrieve the transaction details using hte following call. //\Stripe\Charge::retrieve($charge->id); $custom = sanitize_text_field($_REQUEST['custom']); $custom_var = SwpmTransactions::parse_custom_var($custom); $swpm_id = isset($custom_var['swpm_id']) ? $custom_var['swpm_id'] : ''; //Create the $ipn_data array. $ipn_data = array(); $ipn_data['mc_gross'] = $payment_amount; $ipn_data['first_name'] = ''; $ipn_data['last_name'] = ''; $ipn_data['payer_email'] = $stripe_email; $ipn_data['membership_level'] = $membership_level_id; $ipn_data['txn_id'] = $txn_id; $ipn_data['subscr_id'] = $txn_id; $ipn_data['swpm_id'] = $swpm_id; $ipn_data['ip'] = $custom_var['user_ip']; $ipn_data['custom'] = $custom; $ipn_data['gateway'] = 'stripe'; $ipn_data['status'] = 'completed'; $ipn_data['address_street'] = ''; $ipn_data['address_city'] = ''; $ipn_data['address_state'] = ''; $ipn_data['address_zipcode'] = ''; $ipn_data['country'] = ''; //Handle the membership signup related tasks. swpm_handle_subsc_signup_stand_alone($ipn_data, $membership_level_id, $txn_id, $swpm_id); //Save the transaction record SwpmTransactions::save_txn_record($ipn_data); SwpmLog::log_simple_debug('Transaction data saved.', true); //Trigger the stripe IPN processed action hook (so other plugins can can listen for this event). do_action('swpm_stripe_ipn_processed', $ipn_data); do_action('swpm_payment_ipn_processed', $ipn_data); //Redirect the user to the return URL (or to the homepage if a return URL is not specified for this payment button). $return_url = get_post_meta($button_id, 'return_url', true); if (empty($return_url)) { $return_url = SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL; } SwpmLog::log_simple_debug("Redirecting customer to: " . $return_url, true); SwpmLog::log_simple_debug("End of Stripe Buy Now IPN processing.", true, true); SwpmMiscUtils::redirect_to_url($return_url); }
function bulk_set_status($members, $status, $notify = false) { $ids = implode(',', array_map('absint', $members)); if (empty($ids)) { return; } global $wpdb; $query = "UPDATE " . $wpdb->prefix . "swpm_members_tbl " . " SET account_state = '" . $status . "' WHERE member_id in (" . $ids . ")"; $wpdb->query($query); if ($notify) { $settings = SwpmSettings::get_instance(); $emails = $wpdb->get_col("SELECT email FROM " . $wpdb->prefix . "swpm_members_tbl " . " WHERE member_id IN ( {$ids} ) "); $subject = $settings->get_value('bulk-activate-notify-mail-subject'); if (empty($subject)) { $subject = "Account Activated!"; } $body = $settings->get_value('bulk-activate-notify-mail-body'); if (empty($body)) { $body = "Hi, Your account has been activated successfully!"; } $from_address = $settings->get_value('email-from'); $to_email_list = implode(',', $emails); $headers = 'From: ' . $from_address . "\r\n"; $headers .= 'bcc: ' . $to_email_list . "\r\n"; wp_mail(array(), $subject, $body, $headers); SwpmLog::log_simple_debug("Bulk activation email notification sent. Activation email sent to the following email: " . $to_email_list, true); } }
} // Invalid IPN transaction. Check the log for details. $this->debug_log('IPN validation failed.', false); if (is_wp_error($response)) { $this->debug_log('Error response: ' . $response->get_error_message(), false); } return false; } function debug_log($message, $success, $end = false) { SwpmLog::log_simple_debug($message, $success, $end); } } // Start of IPN handling (script execution) $ipn_handler_instance = new swpm_paypal_ipn_handler(); $settings = SwpmSettings::get_instance(); $debug_enabled = $settings->get_value('enable-debug'); if (!empty($debug_enabled)) { $debug_log = "log.txt"; // Debug log file name echo 'Debug logging is enabled. Check the ' . $debug_log . ' file for debug output.'; $ipn_handler_instance->ipn_log = true; $ipn_handler_instance->ipn_log_file = $debug_log; if (empty($_POST)) { $ipn_handler_instance->debug_log('This debug line was generated because you entered the URL of the ipn handling script in the browser.', true, true); exit; } } $sandbox_enabled = $settings->get_value('enable-sandbox-testing'); if (!empty($sandbox_enabled)) { $ipn_handler_instance->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
public static function delete_account_button() { $allow_account_deletion = SwpmSettings::get_instance()->get_value('allow-account-deletion'); if (empty($allow_account_deletion)) { return ""; } return '<a href="/?delete_account=1"><div class="swpm-account-delete-button">' . SwpmUtils::_("Delete Account") . '</div></a>'; }
private function set_cookie($remember = '', $secure = '') { if ($remember) { $expiration = time() + 1209600; // 14 days $expire = $expiration + 43200; // 12 hours grace period } else { $expiration = time() + 172800; // 2 days. $expire = $expiration; //The minimum cookie expiration should be at least couple of days. } $expiration_timestamp = SwpmUtils::get_expiration_timestamp($this->userData); $enable_expired_login = SwpmSettings::get_instance()->get_value('enable-expired-account-login', ''); // make sure cookie doesn't live beyond account expiration date. // but if expired account login is enabled then ignore if account is expired $expiration = empty($enable_expired_login) ? min($expiration, $expiration_timestamp) : $expiration; $pass_frag = substr($this->userData->password, 8, 4); $scheme = 'auth'; if (!$secure) { $secure = is_ssl(); } $key = SwpmAuth::b_hash($this->userData->user_name . $pass_frag . '|' . $expiration, $scheme); $hash = hash_hmac('md5', $this->userData->user_name . '|' . $expiration, $key); $auth_cookie = $this->userData->user_name . '|' . $expiration . '|' . $hash; $auth_cookie_name = $secure ? SIMPLE_WP_MEMBERSHIP_SEC_AUTH : SIMPLE_WP_MEMBERSHIP_AUTH; //setcookie($auth_cookie_name, $auth_cookie, $expire, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN, $secure, true); setcookie($auth_cookie_name, $auth_cookie, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure, true); }
public static function delete_account_button() { $allow_account_deletion = SwpmSettings::get_instance()->get_value('allow-account-deletion'); if (empty($allow_account_deletion)) { return ""; } $account_delete_link = '<div class="swpm-profile-account-delete-section">'; $account_delete_link .= '<a href="' . SIMPLE_WP_MEMBERSHIP_SITE_HOME_URL . '/?swpm_delete_account=1"><div class="swpm-account-delete-button">' . SwpmUtils::_("Delete Account") . '</div></a>'; $account_delete_link .= '</div>'; return $account_delete_link; }
public static function create_mandatory_wp_pages() { $settings = SwpmSettings::get_instance(); //Create join us page $swpm_join_page_content = '<p style="color:red;font-weight:bold;">This page and the content has been automatically generated for you to give you a basic idea of how a "Join Us" page should look like. You can customize this page however you like it by editing this page from your WordPress page editor.</p>'; $swpm_join_page_content .= '<p style="font-weight:bold;">If you end up changing the URL of this page then make sure to update the URL value in the settings menu of the plugin.</p>'; $swpm_join_page_content .= '<p style="border-top:1px solid #ccc;padding-top:10px;margin-top:10px;"></p> <strong>Free Membership</strong> <br /> You get unlimited access to free membership content <br /> <em><strong>Price: Free!</strong></em> <br /><br />Link the following image to go to the Registration Page if you want your visitors to be able to create a free membership account<br /><br /> <img title="Join Now" src="' . SIMPLE_WP_MEMBERSHIP_URL . '/images/join-now-button-image.gif" alt="Join Now Button" width="277" height="82" /> <p style="border-bottom:1px solid #ccc;padding-bottom:10px;margin-bottom:10px;"></p>'; $swpm_join_page_content .= '<p><strong>You can register for a Free Membership or pay for one of the following membership options</strong></p>'; $swpm_join_page_content .= '<p style="border-top:1px solid #ccc;padding-top:10px;margin-top:10px;"></p> [ ==> Insert Payment Button For Your Paid Membership Levels Here <== ] <p style="border-bottom:1px solid #ccc;padding-bottom:10px;margin-bottom:10px;"></p>'; $swpm_join_page = array('post_title' => 'Join Us', 'post_name' => 'membership-join', 'post_content' => $swpm_join_page_content, 'post_parent' => 0, 'post_status' => 'publish', 'post_type' => 'page', 'comment_status' => 'closed', 'ping_status' => 'closed'); $join_page_obj = get_page_by_path('membership-join'); if (!$join_page_obj) { $join_page_id = wp_insert_post($swpm_join_page); } else { $join_page_id = $join_page_obj->ID; if ($join_page_obj->post_status == 'trash') { //For cases where page may be in trash, bring it out of trash wp_update_post(array('ID' => $join_page_obj->ID, 'post_status' => 'publish')); } } $swpm_join_page_permalink = get_permalink($join_page_id); $settings->set_value('join-us-page-url', $swpm_join_page_permalink); //Create registration page $swpm_rego_page = array('post_title' => SwpmUtils::_('Registration'), 'post_name' => 'membership-registration', 'post_content' => '[swpm_registration_form]', 'post_parent' => $join_page_id, 'post_status' => 'publish', 'post_type' => 'page', 'comment_status' => 'closed', 'ping_status' => 'closed'); $rego_page_obj = get_page_by_path('membership-registration'); if (!$rego_page_obj) { $rego_page_id = wp_insert_post($swpm_rego_page); } else { $rego_page_id = $rego_page_obj->ID; if ($rego_page_obj->post_status == 'trash') { //For cases where page may be in trash, bring it out of trash wp_update_post(array('ID' => $rego_page_obj->ID, 'post_status' => 'publish')); } } $swpm_rego_page_permalink = get_permalink($rego_page_id); $settings->set_value('registration-page-url', $swpm_rego_page_permalink); //Create login page $swpm_login_page = array('post_title' => SwpmUtils::_('Member Login'), 'post_name' => 'membership-login', 'post_content' => '[swpm_login_form]', 'post_parent' => 0, 'post_status' => 'publish', 'post_type' => 'page', 'comment_status' => 'closed', 'ping_status' => 'closed'); $login_page_obj = get_page_by_path('membership-login'); if (!$login_page_obj) { $login_page_id = wp_insert_post($swpm_login_page); } else { $login_page_id = $login_page_obj->ID; if ($login_page_obj->post_status == 'trash') { //For cases where page may be in trash, bring it out of trash wp_update_post(array('ID' => $login_page_obj->ID, 'post_status' => 'publish')); } } $swpm_login_page_permalink = get_permalink($login_page_id); $settings->set_value('login-page-url', $swpm_login_page_permalink); //Create profile page $swpm_profile_page = array('post_title' => SwpmUtils::_('Profile'), 'post_name' => 'membership-profile', 'post_content' => '[swpm_profile_form]', 'post_parent' => $login_page_id, 'post_status' => 'publish', 'post_type' => 'page', 'comment_status' => 'closed', 'ping_status' => 'closed'); $profile_page_obj = get_page_by_path('membership-profile'); if (!$profile_page_obj) { $profile_page_id = wp_insert_post($swpm_profile_page); } else { $profile_page_id = $profile_page_obj->ID; if ($profile_page_obj->post_status == 'trash') { //For cases where page may be in trash, bring it out of trash wp_update_post(array('ID' => $profile_page_obj->ID, 'post_status' => 'publish')); } } $swpm_profile_page_permalink = get_permalink($profile_page_id); $settings->set_value('profile-page-url', $swpm_profile_page_permalink); //Create reset page $swpm_reset_page = array('post_title' => SwpmUtils::_('Password Reset'), 'post_name' => 'password-reset', 'post_content' => '[swpm_reset_form]', 'post_parent' => $login_page_id, 'post_status' => 'publish', 'post_type' => 'page', 'comment_status' => 'closed', 'ping_status' => 'closed'); $reset_page_obj = get_page_by_path('password-reset'); if (!$profile_page_obj) { $reset_page_id = wp_insert_post($swpm_reset_page); } else { $reset_page_id = $reset_page_obj->ID; if ($reset_page_obj->post_status == 'trash') { //For cases where page may be in trash, bring it out of trash wp_update_post(array('ID' => $reset_page_obj->ID, 'post_status' => 'publish')); } } $swpm_reset_page_permalink = get_permalink($reset_page_id); $settings->set_value('reset-page-url', $swpm_reset_page_permalink); $settings->save(); //Save all settings object changes }