Restore to commit 74e578279624c6045ca440a3459ebfa1f8d54191
This commit is contained in:
449
chat/templates/Membership/public/css/public-style.css
Normal file
449
chat/templates/Membership/public/css/public-style.css
Normal file
@@ -0,0 +1,449 @@
|
||||
.pc-membership-checkout-wrapper {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.pc-membership-pricing-cards {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 24px;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.pc-membership-pricing-card {
|
||||
background: #fff;
|
||||
border: 2px solid #e5e5e5;
|
||||
border-radius: 8px;
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.pc-membership-pricing-card:hover {
|
||||
border-color: #2271b1;
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.pc-membership-pricing-card.featured {
|
||||
border-color: #2271b1;
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
.pc-membership-pricing-card.featured::before {
|
||||
content: 'Popular';
|
||||
position: absolute;
|
||||
top: -12px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: #2271b1;
|
||||
color: #fff;
|
||||
padding: 4px 16px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.pc-membership-pricing-header {
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.pc-membership-plan-name {
|
||||
font-size: 24px;
|
||||
margin: 0 0 15px;
|
||||
color: #23282d;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.pc-membership-plan-price {
|
||||
color: #2271b1;
|
||||
}
|
||||
|
||||
.pc-membership-price-amount {
|
||||
font-size: 42px;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.pc-membership-price-interval {
|
||||
font-size: 16px;
|
||||
color: #646970;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.pc-membership-trial-badge {
|
||||
display: inline-block;
|
||||
background: #46b450;
|
||||
color: #fff;
|
||||
padding: 4px 12px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.pc-membership-plan-description {
|
||||
color: #646970;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.pc-membership-plan-benefits {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 0 24px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.pc-membership-plan-benefits li {
|
||||
padding: 10px 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
color: #3c434a;
|
||||
border-bottom: 1px solid #f0f0f1;
|
||||
}
|
||||
|
||||
.pc-membership-plan-benefits li:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.pc-membership-plan-benefits .dashicons {
|
||||
color: #46b450;
|
||||
font-size: 20px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.pc-membership-select-plan-btn,
|
||||
.pc-membership-checkout-btn {
|
||||
width: 100%;
|
||||
padding: 14px 24px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
border-radius: 4px;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.pc-membership-checkout-form-wrapper {
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 30px;
|
||||
margin-top: 30px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.pc-membership-login-wrapper,
|
||||
.pc-membership-register-wrapper,
|
||||
.pc-membership-account-wrapper {
|
||||
max-width: 500px;
|
||||
margin: 0 auto;
|
||||
padding: 40px 20px;
|
||||
}
|
||||
|
||||
.pc-membership-login-form-container,
|
||||
.pc-membership-register-form-container,
|
||||
.pc-membership-account-wrapper {
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 40px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.pc-membership-login-form-container h2,
|
||||
.pc-membership-register-form-container h2,
|
||||
.pc-membership-account-wrapper h2,
|
||||
.pc-membership-account-wrapper h3 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 24px;
|
||||
color: #23282d;
|
||||
}
|
||||
|
||||
.pc-membership-form-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pc-membership-form-group label {
|
||||
display: block;
|
||||
font-weight: 600;
|
||||
margin-bottom: 6px;
|
||||
color: #3c434a;
|
||||
}
|
||||
|
||||
.pc-membership-form-group input[type="text"],
|
||||
.pc-membership-form-group input[type="email"],
|
||||
.pc-membership-form-group input[type="password"] {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 1px solid #c3c4c7;
|
||||
border-radius: 4px;
|
||||
font-size: 16px;
|
||||
transition: border-color 0.2s ease;
|
||||
}
|
||||
|
||||
.pc-membership-form-group input:focus {
|
||||
outline: none;
|
||||
border-color: #2271b1;
|
||||
box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.1);
|
||||
}
|
||||
|
||||
.pc-membership-remember-me {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.pc-membership-remember-me input {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.pc-membership-login-btn,
|
||||
.pc-membership-register-btn {
|
||||
width: 100%;
|
||||
padding: 14px 24px;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.pc-membership-login-links {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.pc-membership-login-links a {
|
||||
display: inline-block;
|
||||
margin: 0 10px;
|
||||
color: #2271b1;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.pc-membership-login-links a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.pc-membership-login-message,
|
||||
.pc-membership-register-message {
|
||||
margin-top: 15px;
|
||||
padding: 12px;
|
||||
border-radius: 4px;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.pc-membership-login-message.success,
|
||||
.pc-membership-register-message.success {
|
||||
background: #dff0d8;
|
||||
border: 1px solid #d6e9c6;
|
||||
color: #3c763d;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.pc-membership-login-message.error,
|
||||
.pc-membership-register-message.error {
|
||||
background: #f2dede;
|
||||
border: 1px solid #ebccd1;
|
||||
color: #a94442;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.pc-membership-account-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.pc-membership-account-header h2 {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.pc-membership-subscription-details {
|
||||
background: #f0f0f1;
|
||||
border-radius: 8px;
|
||||
padding: 24px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
|
||||
.pc-membership-subscription-details h3 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pc-membership-subscription-info {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pc-membership-subscription-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 10px 0;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.pc-membership-subscription-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.pc-membership-label {
|
||||
color: #646970;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.pc-membership-value {
|
||||
font-weight: 600;
|
||||
color: #23282d;
|
||||
}
|
||||
|
||||
.pc-membership-status-active {
|
||||
color: #46b450;
|
||||
}
|
||||
|
||||
.pc-membership-status-cancelled,
|
||||
.pc-membership-status-expired,
|
||||
.pc-membership-status-past_due {
|
||||
color: #dc3232;
|
||||
}
|
||||
|
||||
.pc-membership-status-pending {
|
||||
color: #f56e28;
|
||||
}
|
||||
|
||||
.pc-membership-subscription-actions {
|
||||
padding-top: 15px;
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.pc-membership-no-subscription {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
background: #f0f0f1;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.pc-membership-no-subscription p {
|
||||
margin-bottom: 20px;
|
||||
color: #646970;
|
||||
}
|
||||
|
||||
.pc-membership-account-section {
|
||||
margin-top: 30px;
|
||||
padding-top: 30px;
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.pc-membership-account-section h3 {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pc-membership-success-wrapper,
|
||||
.pc-membership-cancel-wrapper {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
padding: 60px 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pc-membership-success-message,
|
||||
.pc-membership-cancel-message {
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 50px 40px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.pc-membership-success-icon,
|
||||
.pc-membership-cancel-icon {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pc-membership-success-message h2,
|
||||
.pc-membership-cancel-message h2 {
|
||||
margin: 0 0 15px;
|
||||
color: #23282d;
|
||||
}
|
||||
|
||||
.pc-membership-success-message p,
|
||||
.pc-membership-cancel-message p {
|
||||
color: #646970;
|
||||
margin-bottom: 30px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.pc-membership-message {
|
||||
padding: 15px 20px;
|
||||
border-radius: 4px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.pc-membership-message-info {
|
||||
background: #d9edf7;
|
||||
border: 1px solid #bce8f1;
|
||||
color: #31708f;
|
||||
}
|
||||
|
||||
.pc-membership-message-success {
|
||||
background: #dff0d8;
|
||||
border: 1px solid #d6e9c6;
|
||||
color: #3c763d;
|
||||
}
|
||||
|
||||
.pc-membership-message-error {
|
||||
background: #f2dede;
|
||||
border: 1px solid #ebccd1;
|
||||
color: #a94442;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
.pc-membership-pricing-cards {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.pc-membership-pricing-card.featured {
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.pc-membership-login-form-container,
|
||||
.pc-membership-register-form-container,
|
||||
.pc-membership-account-wrapper {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.pc-membership-account-header {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pc-membership-subscription-row {
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.pc-membership-pricing-card,
|
||||
.pc-membership-select-plan-btn,
|
||||
.pc-membership-pricing-card:hover {
|
||||
transition: none;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-contrast: high) {
|
||||
.pc-membership-pricing-card {
|
||||
border-width: 3px;
|
||||
}
|
||||
|
||||
.pc-membership-plan-benefits .dashicons {
|
||||
color: #006600;
|
||||
}
|
||||
}
|
||||
207
chat/templates/Membership/public/js/public-script.js
Normal file
207
chat/templates/Membership/public/js/public-script.js
Normal file
@@ -0,0 +1,207 @@
|
||||
(function($) {
|
||||
'use strict';
|
||||
|
||||
var PCMembership = {
|
||||
stripe: null,
|
||||
|
||||
init: function() {
|
||||
this.bindEvents();
|
||||
this.initStripe();
|
||||
},
|
||||
|
||||
bindEvents: function() {
|
||||
$(document).on('click', '.pc-membership-select-plan-btn', $.proxy(this.selectPlan, this));
|
||||
$(document).on('submit', '#pc-membership-login-form', $.proxy(this.handleLogin, this));
|
||||
$(document).on('submit', '#pc-membership-register-form', $.proxy(this.handleRegister, this));
|
||||
$(document).on('submit', '#pc-membership-profile-form', $.proxy(this.handleProfileUpdate, this));
|
||||
$(document).on('click', '#pc-membership-cancel-subscription', $.proxy(this.cancelSubscription, this));
|
||||
$(document).on('click', '#pc-membership-update-payment-method', $.proxy(this.updatePaymentMethod, this));
|
||||
},
|
||||
|
||||
initStripe: function() {
|
||||
if (typeof Stripe !== 'undefined' && pcMembership.stripe_key) {
|
||||
this.stripe = Stripe(pcMembership.stripe_key);
|
||||
}
|
||||
},
|
||||
|
||||
selectPlan: function(e) {
|
||||
e.preventDefault();
|
||||
var planId = $(e.currentTarget).data('plan-id');
|
||||
|
||||
if (!planId) {
|
||||
alert(pcMembership.i18n.selectPlan);
|
||||
return;
|
||||
}
|
||||
|
||||
var $button = $(e.currentTarget);
|
||||
var originalText = $button.text();
|
||||
$button.text(pcMembership.i18n.processing).prop('disabled', true);
|
||||
|
||||
$.ajax({
|
||||
url: pcMembership.ajax_url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'pc_membership_create_checkout',
|
||||
plan_id: planId,
|
||||
nonce: pcMembership.nonce
|
||||
},
|
||||
success: $.proxy(function(response) {
|
||||
if (response.success && response.data.url) {
|
||||
window.location.href = response.data.url;
|
||||
} else {
|
||||
alert(pcMembership.i18n.error + ': ' + (response.data || 'Unknown error'));
|
||||
$button.text(originalText).prop('disabled', false);
|
||||
}
|
||||
}, this),
|
||||
error: $.proxy(function() {
|
||||
alert(pcMembership.i18n.error);
|
||||
$button.text(originalText).prop('disabled', false);
|
||||
}, this)
|
||||
});
|
||||
},
|
||||
|
||||
handleLogin: function(e) {
|
||||
e.preventDefault();
|
||||
var $form = $('#pc-membership-login-form');
|
||||
var $message = $('#pc-membership-login-message');
|
||||
var formData = $form.serialize();
|
||||
|
||||
$message.removeClass('success error').hide();
|
||||
|
||||
$.ajax({
|
||||
url: pcMembership.ajax_url,
|
||||
type: 'POST',
|
||||
data: formData + '&action=pc_membership_login&nonce=' + pcMembership.nonce,
|
||||
success: $.proxy(function(response) {
|
||||
if (response.success) {
|
||||
$message.addClass('success').text(pcMembership.i18n.success).show();
|
||||
setTimeout(function() {
|
||||
window.location.href = response.data.redirect || pcMembership.account_url;
|
||||
}, 1000);
|
||||
} else {
|
||||
$message.addClass('error').text(response.data || pcMembership.i18n.error).show();
|
||||
}
|
||||
}, this),
|
||||
error: function() {
|
||||
$message.addClass('error').text(pcMembership.i18n.error).show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
handleRegister: function(e) {
|
||||
e.preventDefault();
|
||||
var $form = $('#pc-membership-register-form');
|
||||
var $message = $('#pc-membership-register-message');
|
||||
var formData = $form.serialize();
|
||||
|
||||
var password = $('#user_password').val();
|
||||
var passwordConfirm = $('#user_password_confirm').val();
|
||||
|
||||
if (password !== passwordConfirm) {
|
||||
$message.addClass('error').text('Passwords do not match').show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length < 8) {
|
||||
$message.addClass('error').text('Password must be at least 8 characters').show();
|
||||
return;
|
||||
}
|
||||
|
||||
$message.removeClass('success error').hide();
|
||||
|
||||
$.ajax({
|
||||
url: pcMembership.ajax_url,
|
||||
type: 'POST',
|
||||
data: formData + '&action=pc_membership_register&nonce=' + pcMembership.nonce,
|
||||
success: $.proxy(function(response) {
|
||||
if (response.success) {
|
||||
$message.addClass('success').text(pcMembership.i18n.success).show();
|
||||
setTimeout(function() {
|
||||
window.location.href = response.data.redirect || pcMembership.account_url;
|
||||
}, 1000);
|
||||
} else {
|
||||
$message.addClass('error').text(response.data || pcMembership.i18n.error).show();
|
||||
}
|
||||
}, this),
|
||||
error: function() {
|
||||
$message.addClass('error').text(pcMembership.i18n.error).show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
handleProfileUpdate: function(e) {
|
||||
e.preventDefault();
|
||||
var $form = $('#pc-membership-profile-form');
|
||||
|
||||
$.ajax({
|
||||
url: pcMembership.ajax_url,
|
||||
type: 'POST',
|
||||
data: $form.serialize() + '&action=pc_membership_update_profile&nonce=' + pcMembership.nonce,
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
alert('Profile updated successfully');
|
||||
} else {
|
||||
alert(response.data || 'Error updating profile');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
cancelSubscription: function(e) {
|
||||
e.preventDefault();
|
||||
if (!confirm(pcMembership.i18n.confirmCancel)) return;
|
||||
|
||||
var subscriptionId = $(e.currentTarget).data('subscription-id');
|
||||
var $button = $(e.currentTarget);
|
||||
|
||||
$button.text(pcMembership.i18n.processing).prop('disabled', true);
|
||||
|
||||
$.ajax({
|
||||
url: pcMembership.ajax_url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'pc_membership_cancel_subscription',
|
||||
subscription_id: subscriptionId,
|
||||
nonce: pcMembership.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert(pcMembership.i18n.error);
|
||||
$button.text(pcMembership.i18n.cancel).prop('disabled', false);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert(pcMembership.i18n.error);
|
||||
$button.text(pcMembership.i18n.cancel).prop('disabled', false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updatePaymentMethod: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$.ajax({
|
||||
url: pcMembership.ajax_url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'pc_membership_update_payment_method',
|
||||
nonce: pcMembership.nonce
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success && response.data.url) {
|
||||
window.location.href = response.data.url;
|
||||
} else {
|
||||
alert(pcMembership.i18n.error);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
PCMembership.init();
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
656
chat/templates/Membership/public/public.php
Normal file
656
chat/templates/Membership/public/public.php
Normal file
@@ -0,0 +1,656 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class PC_Membership_Public {
|
||||
|
||||
public static function init() {
|
||||
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'enqueue_assets' ) );
|
||||
|
||||
add_shortcode( 'pc_membership_checkout', array( __CLASS__, 'checkout_shortcode' ) );
|
||||
add_shortcode( 'pc_membership_login', array( __CLASS__, 'login_shortcode' ) );
|
||||
add_shortcode( 'pc_membership_register', array( __CLASS__, 'register_shortcode' ) );
|
||||
add_shortcode( 'pc_membership_account', array( __CLASS__, 'account_shortcode' ) );
|
||||
add_shortcode( 'pc_membership_success', array( __CLASS__, 'success_shortcode' ) );
|
||||
add_shortcode( 'pc_membership_cancel', array( __CLASS__, 'cancel_shortcode' ) );
|
||||
add_shortcode( 'pc_membership_pricing', array( __CLASS__, 'pricing_shortcode' ) );
|
||||
|
||||
add_action( 'wp_ajax_pc_membership_create_checkout', array( __CLASS__, 'ajax_create_checkout' ) );
|
||||
add_action( 'wp_ajax_nopriv_pc_membership_create_checkout', array( __CLASS__, 'ajax_create_checkout' ) );
|
||||
|
||||
add_action( 'wp_ajax_pc_membership_cancel_subscription', array( __CLASS__, 'ajax_cancel_subscription' ) );
|
||||
add_action( 'wp_ajax_nopriv_pc_membership_cancel_subscription', array( __CLASS__, 'ajax_cancel_subscription' ) );
|
||||
|
||||
add_action( 'wp_ajax_pc_membership_update_payment_method', array( __CLASS__, 'ajax_update_payment_method' ) );
|
||||
add_action( 'wp_ajax_nopriv_pc_membership_update_payment_method', array( __CLASS__, 'ajax_update_payment_method' ) );
|
||||
|
||||
add_action( 'wp_ajax_pc_membership_login', array( __CLASS__, 'ajax_login' ) );
|
||||
add_action( 'wp_ajax_nopriv_pc_membership_login', array( __CLASS__, 'ajax_login' ) );
|
||||
|
||||
add_action( 'wp_ajax_pc_membership_register', array( __CLASS__, 'ajax_register' ) );
|
||||
add_action( 'wp_ajax_nopriv_pc_membership_register', array( __CLASS__, 'ajax_register' ) );
|
||||
|
||||
add_action( 'wp_ajax_pc_membership_update_profile', array( __CLASS__, 'ajax_update_profile' ) );
|
||||
|
||||
add_action( 'template_redirect', array( __CLASS__, 'handle_stripe_return' ) );
|
||||
}
|
||||
|
||||
public static function enqueue_assets() {
|
||||
if ( ! self::is_membership_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'pc-membership-public-style', PC_MEMBERSHIP_PLUGIN_URL . 'public/css/public-style.css', array(), PC_MEMBERSHIP_VERSION );
|
||||
wp_enqueue_script( 'pc-membership-stripe-js', 'https://js.stripe.com/v3/', array(), null, true );
|
||||
wp_enqueue_script( 'pc-membership-public-script', PC_MEMBERSHIP_PLUGIN_URL . 'public/js/public-script.js', array( 'jquery', 'pc-membership-stripe-js' ), PC_MEMBERSHIP_VERSION, true );
|
||||
|
||||
$options = get_option( 'pc_membership_options' );
|
||||
$publishable_key = '';
|
||||
|
||||
if ( ! empty( $options ) ) {
|
||||
$mode = isset( $options['mode'] ) ? $options['mode'] : 'test';
|
||||
$publishable_key = isset( $options[ $mode . '_publishable_key' ] ) ? $options[ $mode . '_publishable_key' ] : '';
|
||||
}
|
||||
|
||||
wp_localize_script( 'pc-membership-public-script', 'pcMembership', array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'nonce' => wp_create_nonce( 'pc_membership_nonce' ),
|
||||
'stripe_key' => $publishable_key,
|
||||
'i18n' => array(
|
||||
'processing' => __( 'Processing...', 'pc-membership-abc123' ),
|
||||
'selectPlan' => __( 'Please select a plan', 'pc-membership-abc123' ),
|
||||
'error' => __( 'An error occurred. Please try again.', 'pc-membership-abc123' ),
|
||||
'success' => __( 'Success!', 'pc-membership-abc123' ),
|
||||
'cancel' => __( 'Cancel Subscription', 'pc-membership-abc123' ),
|
||||
'confirmCancel'=> __( 'Are you sure you want to cancel your subscription?', 'pc-membership-abc123' ),
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
private static function is_membership_page() {
|
||||
if ( ! is_singular() && ! is_page() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$options = get_option( 'pc_membership_options', array() );
|
||||
$page_ids = array(
|
||||
isset( $options['checkout_page_id'] ) ? $options['checkout_page_id'] : 0,
|
||||
isset( $options['login_page_id'] ) ? $options['login_page_id'] : 0,
|
||||
isset( $options['register_page_id'] ) ? $options['register_page_id'] : 0,
|
||||
isset( $options['account_page_id'] ) ? $options['account_page_id'] : 0,
|
||||
isset( $options['success_page_id'] ) ? $options['success_page_id'] : 0,
|
||||
isset( $options['cancel_page_id'] ) ? $options['cancel_page_id'] : 0,
|
||||
);
|
||||
|
||||
return in_array( get_the_ID(), array_filter( $page_ids ) );
|
||||
}
|
||||
|
||||
public static function checkout_shortcode( $atts ) {
|
||||
ob_start();
|
||||
self::render_checkout_page();
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public static function render_checkout_page() {
|
||||
global $wpdb;
|
||||
|
||||
$plans = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}pc_membership_plans ORDER BY price ASC" );
|
||||
|
||||
if ( empty( $plans ) ) {
|
||||
echo '<div class="pc-membership-message pc-membership-message-info">';
|
||||
esc_html_e( 'No membership plans available at this time.', 'pc-membership-abc123' );
|
||||
echo '</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
$options = get_option( 'pc_membership_options' );
|
||||
$mode = isset( $options['mode'] ) ? $options['mode'] : 'test';
|
||||
|
||||
echo '<div class="pc-membership-checkout-wrapper">';
|
||||
echo '<div class="pc-membership-pricing-cards">';
|
||||
|
||||
foreach ( $plans as $plan ) {
|
||||
$benefits = array_filter( array_map( 'trim', explode( "\n", $plan->benefits ) ) );
|
||||
$billing_label = $plan->is_subscription
|
||||
? sprintf( '%s / %s', pc_membership_format_price( $plan->price ), $plan->billing_interval )
|
||||
: pc_membership_format_price( $plan->price );
|
||||
|
||||
echo '<div class="pc-membership-pricing-card" data-plan-id="' . esc_attr( $plan->id ) . '">';
|
||||
echo '<div class="pc-membership-pricing-header">';
|
||||
echo '<h3 class="pc-membership-plan-name">' . esc_html( $plan->name ) . '</h3>';
|
||||
echo '<div class="pc-membership-plan-price">';
|
||||
echo '<span class="pc-membership-price-amount">' . esc_html( pc_membership_format_price( $plan->price ) ) . '</span>';
|
||||
if ( $plan->is_subscription ) {
|
||||
echo '<span class="pc-membership-price-interval"> / ' . esc_html( $plan->billing_interval ) . '</span>';
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
if ( $plan->trial_days > 0 ) {
|
||||
echo '<div class="pc-membership-trial-badge">';
|
||||
printf( esc_html__( '%d Day Free Trial', 'pc-membership-abc123' ), $plan->trial_days );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
if ( $plan->description ) {
|
||||
echo '<div class="pc-membership-plan-description">' . wp_kses_post( $plan->description ) . '</div>';
|
||||
}
|
||||
|
||||
if ( ! empty( $benefits ) ) {
|
||||
echo '<ul class="pc-membership-plan-benefits">';
|
||||
foreach ( $benefits as $benefit ) {
|
||||
echo '<li><span class="dashicons dashicons-yes-alt"></span>' . esc_html( $benefit ) . '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
echo '<button class="pc-membership-select-plan-btn button button-primary" data-plan-id="' . esc_attr( $plan->id ) . '">';
|
||||
esc_html_e( 'Select Plan', 'pc-membership-abc123' );
|
||||
echo '</button>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div class="pc-membership-checkout-form-wrapper" style="display: none;">';
|
||||
echo '<div id="pc-membership-checkout-form-container"></div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
public static function login_shortcode( $atts ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$account_page = self::get_page_url( 'account' );
|
||||
if ( $account_page ) {
|
||||
wp_redirect( $account_page );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
ob_start();
|
||||
self::render_login_form();
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public static function render_login_form() {
|
||||
$options = get_option( 'pc_membership_options' );
|
||||
$register_page = isset( $options['register_page_id'] ) ? get_permalink( $options['register_page_id'] ) : false;
|
||||
$account_page = self::get_page_url( 'account' );
|
||||
?>
|
||||
<div class="pc-membership-login-wrapper">
|
||||
<div class="pc-membership-login-form-container">
|
||||
<h2><?php esc_html_e( 'Member Login', 'pc-membership-abc123' ); ?></h2>
|
||||
|
||||
<form id="pc-membership-login-form" method="post">
|
||||
<?php wp_nonce_field( 'pc_membership_login', 'pc_membership_login_nonce' ); ?>
|
||||
|
||||
<div class="pc-membership-form-group">
|
||||
<label for="user_login"><?php esc_html_e( 'Username or Email', 'pc-membership-abc123' ); ?></label>
|
||||
<input type="text" name="user_login" id="user_login" required class="regular-text">
|
||||
</div>
|
||||
|
||||
<div class="pc-membership-form-group">
|
||||
<label for="user_password"><?php esc_html_e( 'Password', 'pc-membership-abc123' ); ?></label>
|
||||
<input type="password" name="user_password" id="user_password" required class="regular-text">
|
||||
</div>
|
||||
|
||||
<div class="pc-membership-form-group">
|
||||
<label class="pc-membership-remember-me">
|
||||
<input type="checkbox" name="rememberme" value="forever">
|
||||
<?php esc_html_e( 'Remember me', 'pc-membership-abc123' ); ?>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="button button-primary pc-membership-login-btn">
|
||||
<?php esc_html_e( 'Log In', 'pc-membership-abc123' ); ?>
|
||||
</button>
|
||||
|
||||
<div class="pc-membership-login-links">
|
||||
<?php if ( $register_page ) : ?>
|
||||
<a href="<?php echo esc_url( $register_page ); ?>">
|
||||
<?php esc_html_e( 'Create an account', 'pc-membership-abc123' ); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>">
|
||||
<?php esc_html_e( 'Forgot password?', 'pc-membership-abc123' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div id="pc-membership-login-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function register_shortcode( $atts ) {
|
||||
if ( is_user_logged_in() ) {
|
||||
$account_page = self::get_page_url( 'account' );
|
||||
if ( $account_page ) {
|
||||
wp_redirect( $account_page );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
ob_start();
|
||||
self::render_registration_form();
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public static function render_registration_form() {
|
||||
$options = get_option( 'pc_membership_options' );
|
||||
$login_page = isset( $options['login_page_id'] ) ? get_permalink( $options['login_page_id'] ) : false;
|
||||
?>
|
||||
<div class="pc-membership-register-wrapper">
|
||||
<div class="pc-membership-register-form-container">
|
||||
<h2><?php esc_html_e( 'Create Account', 'pc-membership-abc123' ); ?></h2>
|
||||
|
||||
<form id="pc-membership-register-form" method="post">
|
||||
<?php wp_nonce_field( 'pc_membership_register', 'pc_membership_register_nonce' ); ?>
|
||||
|
||||
<div class="pc-membership-form-group">
|
||||
<label for="user_login"><?php esc_html_e( 'Username', 'pc-membership-abc123' ); ?> *</label>
|
||||
<input type="text" name="user_login" id="user_login" required class="regular-text" minlength="4">
|
||||
</div>
|
||||
|
||||
<div class="pc-membership-form-group">
|
||||
<label for="user_email"><?php esc_html_e( 'Email', 'pc-membership-abc123' ); ?> *</label>
|
||||
<input type="email" name="user_email" id="user_email" required class="regular-text">
|
||||
</div>
|
||||
|
||||
<div class="pc-membership-form-group">
|
||||
<label for="user_password"><?php esc_html_e( 'Password', 'pc-membership-abc123' ); ?> *</label>
|
||||
<input type="password" name="user_password" id="user_password" required class="regular-text" minlength="8">
|
||||
</div>
|
||||
|
||||
<div class="pc-membership-form-group">
|
||||
<label for="user_password_confirm"><?php esc_html_e( 'Confirm Password', 'pc-membership-abc123' ); ?> *</label>
|
||||
<input type="password" name="user_password_confirm" id="user_password_confirm" required class="regular-text">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="button button-primary pc-membership-register-btn">
|
||||
<?php esc_html_e( 'Create Account', 'pc-membership-abc123' ); ?>
|
||||
</button>
|
||||
|
||||
<div class="pc-membership-login-links">
|
||||
<?php if ( $login_page ) : ?>
|
||||
<a href="<?php echo esc_url( $login_page ); ?>">
|
||||
<?php esc_html_e( 'Already have an account? Log in', 'pc-membership-abc123' ); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div id="pc-membership-register-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function account_shortcode( $atts ) {
|
||||
if ( ! is_user_logged_in() ) {
|
||||
$login_page = self::get_page_url( 'login' );
|
||||
if ( $login_page ) {
|
||||
wp_redirect( $login_page );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
ob_start();
|
||||
self::render_account_page();
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public static function render_account_page() {
|
||||
$user = wp_get_current_user();
|
||||
$subscription = self::get_user_subscription( $user->ID );
|
||||
?>
|
||||
<div class="pc-membership-account-wrapper">
|
||||
<div class="pc-membership-account-header">
|
||||
<h2><?php printf( esc_html__( 'Welcome, %s', 'pc-membership-abc123' ), esc_html( $user->display_name ) ); ?></h2>
|
||||
<a href="<?php echo esc_url( wp_logout_url( self::get_page_url( 'login' ) ) ); ?>" class="button">
|
||||
<?php esc_html_e( 'Log Out', 'pc-membership-abc123' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php if ( $subscription ) : ?>
|
||||
<?php
|
||||
global $wpdb;
|
||||
$plan = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}pc_membership_plans WHERE id = %d", $subscription->plan_id ) );
|
||||
?>
|
||||
|
||||
<div class="pc-membership-subscription-details">
|
||||
<h3><?php esc_html_e( 'Your Subscription', 'pc-membership-abc123' ); ?></h3>
|
||||
|
||||
<div class="pc-membership-subscription-info">
|
||||
<div class="pc-membership-subscription-row">
|
||||
<span class="pc-membership-label"><?php esc_html_e( 'Plan', 'pc-membership-abc123' ); ?>:</span>
|
||||
<span class="pc-membership-value"><?php echo $plan ? esc_html( $plan->name ) : esc_html__( 'Unknown', 'pc-membership-abc123' ); ?></span>
|
||||
</div>
|
||||
|
||||
<div class="pc-membership-subscription-row">
|
||||
<span class="pc-membership-label"><?php esc_html_e( 'Status', 'pc-membership-abc123' ); ?>:</span>
|
||||
<span class="pc-membership-value pc-membership-status-<?php echo esc_attr( $subscription->status ); ?>">
|
||||
<?php echo esc_html( ucfirst( $subscription->status ) ); ?>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="pc-membership-subscription-row">
|
||||
<span class="pc-membership-label"><?php esc_html_e( 'Started', 'pc-membership-abc123' ); ?>:</span>
|
||||
<span class="pc-membership-value"><?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $subscription->started_at ) ) ); ?></span>
|
||||
</div>
|
||||
|
||||
<?php if ( $subscription->expires_at ) : ?>
|
||||
<div class="pc-membership-subscription-row">
|
||||
<span class="pc-membership-label"><?php esc_html_e( 'Expires', 'pc-membership-abc123' ); ?>:</span>
|
||||
<span class="pc-membership-value"><?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $subscription->expires_at ) ) ); ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if ( $subscription->status === 'active' && $plan && $plan->is_subscription ) : ?>
|
||||
<div class="pc-membership-subscription-actions">
|
||||
<button type="button" id="pc-membership-cancel-subscription" class="button button-secondary" data-subscription-id="<?php echo esc_attr( $subscription->id ); ?>">
|
||||
<?php esc_html_e( 'Cancel Subscription', 'pc-membership-abc123' ); ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="pc-membership-no-subscription">
|
||||
<p><?php esc_html_e( 'You don\'t have an active membership subscription.', 'pc-membership-abc123' ); ?></p>
|
||||
<a href="<?php echo esc_url( self::get_page_url( 'checkout' ) ); ?>" class="button button-primary">
|
||||
<?php esc_html_e( 'Choose a Plan', 'pc-membership-abc123' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="pc-membership-account-section">
|
||||
<h3><?php esc_html_e( 'Profile Information', 'pc-membership-abc123' ); ?></h3>
|
||||
<form id="pc-membership-profile-form" method="post">
|
||||
<?php wp_nonce_field( 'pc_membership_update_profile', 'pc_membership_profile_nonce' ); ?>
|
||||
|
||||
<div class="pc-membership-form-group">
|
||||
<label for="display_name"><?php esc_html_e( 'Display Name', 'pc-membership-abc123' ); ?></label>
|
||||
<input type="text" name="display_name" id="display_name" value="<?php echo esc_attr( $user->display_name ); ?>" class="regular-text">
|
||||
</div>
|
||||
|
||||
<div class="pc-membership-form-group">
|
||||
<label for="user_email"><?php esc_html_e( 'Email', 'pc-membership-abc123' ); ?></label>
|
||||
<input type="email" name="user_email" id="user_email" value="<?php echo esc_attr( $user->user_email ); ?>" class="regular-text" readonly>
|
||||
<p class="description"><?php esc_html_e( 'Email cannot be changed.', 'pc-membership-abc123' ); ?></p>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="button button-primary">
|
||||
<?php esc_html_e( 'Update Profile', 'pc-membership-abc123' ); ?>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function success_shortcode( $atts ) {
|
||||
ob_start();
|
||||
?>
|
||||
<div class="pc-membership-success-wrapper">
|
||||
<div class="pc-membership-success-message">
|
||||
<div class="pc-membership-success-icon">
|
||||
<span class="dashicons dashicons-yes-alt" style="font-size: 64px; height: 64px; width: 64px; color: #46b450;"></span>
|
||||
</div>
|
||||
<h2><?php esc_html_e( 'Payment Successful!', 'pc-membership-abc123' ); ?></h2>
|
||||
<p><?php esc_html_e( 'Thank you for your purchase. Your membership is now active.', 'pc-membership-abc123' ); ?></p>
|
||||
<a href="<?php echo esc_url( self::get_page_url( 'account' ) ); ?>" class="button button-primary">
|
||||
<?php esc_html_e( 'Go to My Account', 'pc-membership-abc123' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public static function cancel_shortcode( $atts ) {
|
||||
ob_start();
|
||||
?>
|
||||
<div class="pc-membership-cancel-wrapper">
|
||||
<div class="pc-membership-cancel-message">
|
||||
<div class="pc-membership-cancel-icon">
|
||||
<span class="dashicons dashicons-dismiss" style="font-size: 64px; height: 64px; width: 64px; color: #dc3232;"></span>
|
||||
</div>
|
||||
<h2><?php esc_html_e( 'Payment Cancelled', 'pc-membership-abc123' ); ?></h2>
|
||||
<p><?php esc_html_e( 'Your payment was cancelled. No charges were made.', 'pc-membership-abc123' ); ?></p>
|
||||
<a href="<?php echo esc_url( self::get_page_url( 'checkout' ) ); ?>" class="button button-primary">
|
||||
<?php esc_html_e( 'Try Again', 'pc-membership-abc123' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public static function pricing_shortcode( $atts ) {
|
||||
ob_start();
|
||||
self::render_checkout_page();
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
private static function get_page_url( $page_type ) {
|
||||
$options = get_option( 'pc_membership_options' );
|
||||
$page_id = isset( $options[ $page_type . '_page_id' ] ) ? absint( $options[ $page_type . '_page_id' ] ) : 0;
|
||||
return $page_id ? get_permalink( $page_id ) : home_url();
|
||||
}
|
||||
|
||||
private static function get_user_subscription( $user_id ) {
|
||||
global $wpdb;
|
||||
return $wpdb->get_row( $wpdb->prepare(
|
||||
"SELECT * FROM {$wpdb->prefix}pc_membership_subscriptions WHERE user_id = %d AND status = 'active' ORDER BY id DESC LIMIT 1",
|
||||
$user_id
|
||||
) );
|
||||
}
|
||||
|
||||
public static function ajax_create_checkout() {
|
||||
check_ajax_referer( 'pc_membership_nonce', 'nonce' );
|
||||
|
||||
$plan_id = isset( $_POST['plan_id'] ) ? absint( $_POST['plan_id'] ) : 0;
|
||||
|
||||
if ( ! $plan_id ) {
|
||||
wp_send_json_error( __( 'Invalid plan', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PC_Membership_Stripe' ) ) {
|
||||
require_once PC_MEMBERSHIP_PLUGIN_DIR . 'includes/stripe-handler.php';
|
||||
}
|
||||
|
||||
$result = PC_Membership_Stripe::create_checkout_session( $plan_id );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
wp_send_json_error( $result->get_error_message() );
|
||||
}
|
||||
|
||||
wp_send_json_success( array( 'url' => $result->url ) );
|
||||
}
|
||||
|
||||
public static function ajax_cancel_subscription() {
|
||||
check_ajax_referer( 'pc_membership_nonce', 'nonce' );
|
||||
|
||||
if ( ! is_user_logged_in() ) {
|
||||
wp_send_json_error( __( 'Must be logged in', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
$subscription_id = isset( $_POST['subscription_id'] ) ? absint( $_POST['subscription_id'] ) : 0;
|
||||
|
||||
if ( ! $subscription_id ) {
|
||||
wp_send_json_error( __( 'Invalid subscription', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
$subscription = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}pc_membership_subscriptions WHERE id = %d AND user_id = %d", $subscription_id, get_current_user_id() ) );
|
||||
|
||||
if ( ! $subscription ) {
|
||||
wp_send_json_error( __( 'Subscription not found', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PC_Membership_Stripe' ) ) {
|
||||
require_once PC_MEMBERSHIP_PLUGIN_DIR . 'includes/stripe-handler.php';
|
||||
}
|
||||
|
||||
$result = PC_Membership_Stripe::cancel_subscription( $subscription->stripe_subscription_id );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
wp_send_json_error( $result->get_error_message() );
|
||||
}
|
||||
|
||||
$wpdb->update( $wpdb->prefix . 'pc_membership_subscriptions', array( 'status' => 'cancelled' ), array( 'id' => $subscription_id ) );
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
public static function ajax_update_payment_method() {
|
||||
check_ajax_referer( 'pc_membership_nonce', 'nonce' );
|
||||
|
||||
if ( ! is_user_logged_in() ) {
|
||||
wp_send_json_error( __( 'Must be logged in', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'PC_Membership_Stripe' ) ) {
|
||||
require_once PC_MEMBERSHIP_PLUGIN_DIR . 'includes/stripe-handler.php';
|
||||
}
|
||||
|
||||
$result = PC_Membership_Stripe::create_portal_session();
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
wp_send_json_error( $result->get_error_message() );
|
||||
}
|
||||
|
||||
wp_send_json_success( array( 'url' => $result->url ) );
|
||||
}
|
||||
|
||||
public static function ajax_login() {
|
||||
check_ajax_referer( 'pc_membership_login', 'nonce' );
|
||||
|
||||
$user_login = isset( $_POST['user_login'] ) ? sanitize_text_field( wp_unslash( $_POST['user_login'] ) ) : '';
|
||||
$user_password = isset( $_POST['user_password'] ) ? $_POST['user_password'] : '';
|
||||
|
||||
if ( empty( $user_login ) || empty( $user_password ) ) {
|
||||
wp_send_json_error( __( 'Please enter username and password', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
$user = wp_authenticate_username_password( null, $user_login, $user_password );
|
||||
|
||||
if ( is_wp_error( $user ) ) {
|
||||
wp_send_json_error( $user->get_error_message() );
|
||||
}
|
||||
|
||||
wp_set_auth_cookie( $user->ID, true );
|
||||
|
||||
$redirect_url = self::get_page_url( 'account' );
|
||||
|
||||
wp_send_json_success( array( 'redirect' => $redirect_url ) );
|
||||
}
|
||||
|
||||
public static function ajax_register() {
|
||||
check_ajax_referer( 'pc_membership_register', 'nonce' );
|
||||
|
||||
$user_login = isset( $_POST['user_login'] ) ? sanitize_text_field( wp_unslash( $_POST['user_login'] ) ) : '';
|
||||
$user_email = isset( $_POST['user_email'] ) ? sanitize_email( wp_unslash( $_POST['user_email'] ) ) : '';
|
||||
$user_password = isset( $_POST['user_password'] ) ? $_POST['user_password'] : '';
|
||||
$user_password_confirm = isset( $_POST['user_password_confirm'] ) ? $_POST['user_password_confirm'] : '';
|
||||
|
||||
if ( empty( $user_login ) || empty( $user_email ) || empty( $user_password ) ) {
|
||||
wp_send_json_error( __( 'All fields are required', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
if ( ! is_email( $user_email ) ) {
|
||||
wp_send_json_error( __( 'Invalid email address', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
if ( $user_password !== $user_password_confirm ) {
|
||||
wp_send_json_error( __( 'Passwords do not match', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
if ( strlen( $user_password ) < 8 ) {
|
||||
wp_send_json_error( __( 'Password must be at least 8 characters', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
if ( username_exists( $user_login ) ) {
|
||||
wp_send_json_error( __( 'Username already exists', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
if ( email_exists( $user_email ) ) {
|
||||
wp_send_json_error( __( 'Email already registered', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
$user_id = wp_create_user( $user_login, $user_password, $user_email );
|
||||
|
||||
if ( is_wp_error( $user_id ) ) {
|
||||
wp_send_json_error( $user_id->get_error_message() );
|
||||
}
|
||||
|
||||
wp_update_user( array(
|
||||
'ID' => $user_id,
|
||||
'display_name' => $user_login,
|
||||
) );
|
||||
|
||||
$user = get_userdata( $user_id );
|
||||
$user->set_role( 'subscriber' );
|
||||
|
||||
wp_set_auth_cookie( $user_id, true );
|
||||
|
||||
do_action( 'pc_membership_user_registered', $user_id, $user_login, $user_email );
|
||||
|
||||
$redirect_url = self::get_page_url( 'account' );
|
||||
|
||||
wp_send_json_success( array( 'redirect' => $redirect_url ) );
|
||||
}
|
||||
|
||||
public static function ajax_update_profile() {
|
||||
check_ajax_referer( 'pc_membership_update_profile', 'nonce' );
|
||||
|
||||
if ( ! is_user_logged_in() ) {
|
||||
wp_send_json_error( __( 'Must be logged in', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
$display_name = isset( $_POST['display_name'] ) ? sanitize_text_field( wp_unslash( $_POST['display_name'] ) ) : '';
|
||||
|
||||
if ( empty( $display_name ) ) {
|
||||
wp_send_json_error( __( 'Display name is required', 'pc-membership-abc123' ) );
|
||||
}
|
||||
|
||||
$result = wp_update_user( array(
|
||||
'ID' => get_current_user_id(),
|
||||
'display_name' => $display_name,
|
||||
) );
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
wp_send_json_error( $result->get_error_message() );
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
public static function handle_stripe_return() {
|
||||
if ( ! isset( $_GET['session_id'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$session_id = sanitize_text_field( wp_unslash( $_GET['session_id'] ) );
|
||||
|
||||
if ( ! class_exists( 'PC_Membership_Stripe' ) ) {
|
||||
require_once PC_MEMBERSHIP_PLUGIN_DIR . 'includes/stripe-handler.php';
|
||||
}
|
||||
|
||||
$session = PC_Membership_Stripe::retrieve_session( $session_id );
|
||||
|
||||
if ( is_wp_error( $session ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$success_page = self::get_page_url( 'success' );
|
||||
if ( $success_page ) {
|
||||
wp_redirect( $success_page );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user