| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Leaky Paywall shortcodes |
| 5 |
* |
| 6 |
* @package zeen101's Leaky Paywall |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
if (!function_exists('do_leaky_paywall_login')) { |
| 11 |
|
| 12 |
/** |
| 13 |
* Shortcode for zeen101's Leaky Paywall |
| 14 |
* Prints out the zeen101's Leaky Paywall |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
* |
| 18 |
* @param array $atts Shortcode attributes. |
| 19 |
*/ |
| 20 |
function do_leaky_paywall_login($atts) |
| 21 |
{ |
| 22 |
$settings = get_leaky_paywall_settings(); |
| 23 |
|
| 24 |
$defaults = array( |
| 25 |
'heading' => __('Email address:', 'leaky-paywall'), |
| 26 |
'description' => __('Check your email for a link to log in.', 'leaky-paywall'), |
| 27 |
'email_sent' => __('Email sent. Please check your email for the login link.', 'leaky-paywall'), |
| 28 |
'error_msg' => __('Error sending login email, please try again later.', 'leaky-paywall'), |
| 29 |
'missing_email_msg' => __('Please supply a valid email address.', 'leaky-paywall'), |
| 30 |
'login_redirect_url' => '', |
| 31 |
); |
| 32 |
|
| 33 |
// Merge defaults with passed atts. |
| 34 |
$args = shortcode_atts($defaults, $atts); |
| 35 |
$results = ''; |
| 36 |
|
| 37 |
if ($args['login_redirect_url']) { |
| 38 |
$page_link = $args['login_redirect_url']; |
| 39 |
} elseif (!empty($settings['page_for_profile'])) { |
| 40 |
$page_link = get_page_link($settings['page_for_profile']); |
| 41 |
} elseif (!empty($settings['page_for_subscription'])) { |
| 42 |
$page_link = get_page_link($settings['page_for_subscription']); |
| 43 |
} else { |
| 44 |
$page_link = home_url(); |
| 45 |
} |
| 46 |
|
| 47 |
$results .= apply_filters('leaky_paywall_before_login_form', ''); |
| 48 |
|
| 49 |
$results .= '<div id="leaky-paywall-login-form">'; |
| 50 |
|
| 51 |
if (isset($_GET['login']) && 'failed' === $_GET['login']) { |
| 52 |
$results .= '<div class="leaky_paywall_message error"><p>' . esc_html__('Incorrect username or password.', 'leaky-paywall') . '</p></div>'; |
| 53 |
} |
| 54 |
|
| 55 |
add_action('login_form_bottom', 'leaky_paywall_add_lost_password_link'); |
| 56 |
|
| 57 |
$args = array( |
| 58 |
'echo' => false, |
| 59 |
'redirect' => $page_link, |
| 60 |
); |
| 61 |
|
| 62 |
$results .= wp_login_form(apply_filters('leaky_paywall_login_form_args', $args)); |
| 63 |
|
| 64 |
$results .= '</div>'; |
| 65 |
|
| 66 |
return $results; |
| 67 |
} |
| 68 |
add_shortcode('leaky_paywall_login', 'do_leaky_paywall_login'); |
| 69 |
} |
| 70 |
|
| 71 |
if (!function_exists('do_leaky_paywall_subscription')) { |
| 72 |
|
| 73 |
/** |
| 74 |
* Shortcode for zeen101's Leaky Paywall |
| 75 |
* Prints out the zeen101's Leaky Paywall |
| 76 |
* |
| 77 |
* @since 1.0.0 |
| 78 |
* |
| 79 |
* @param array $atts Shortcode attributes. |
| 80 |
*/ |
| 81 |
function do_leaky_paywall_subscription($atts) |
| 82 |
{ |
| 83 |
if (isset($_REQUEST['level_id'])) { |
| 84 |
return do_leaky_paywall_register_form($atts); |
| 85 |
} |
| 86 |
|
| 87 |
$settings = get_leaky_paywall_settings(); |
| 88 |
$mode = leaky_paywall_get_current_mode(); |
| 89 |
|
| 90 |
$defaults = array( |
| 91 |
'login_heading' => __('Enter your email address to start your subscription:', 'leaky-paywall'), |
| 92 |
'login_desc' => __('Check your email for a link to start your subscription.', 'leaky-paywall'), |
| 93 |
); |
| 94 |
|
| 95 |
$args = shortcode_atts($defaults, $atts); |
| 96 |
|
| 97 |
$results = ''; |
| 98 |
|
| 99 |
if (is_user_logged_in()) { |
| 100 |
|
| 101 |
$sites = array(''); |
| 102 |
if (is_multisite_premium()) { |
| 103 |
global $blog_id; |
| 104 |
if (!is_main_site($blog_id)) { |
| 105 |
$sites = array('_all', '_' . $blog_id); |
| 106 |
} else { |
| 107 |
$sites = array('_all', '_' . $blog_id, ''); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
$user = wp_get_current_user(); |
| 112 |
|
| 113 |
$results .= apply_filters('leaky_paywall_subscriber_info_start', ''); |
| 114 |
|
| 115 |
$results .= '<div class="issuem-leaky-paywall-subscriber-info">'; |
| 116 |
|
| 117 |
foreach ($sites as $site) { |
| 118 |
|
| 119 |
$expires = leaky_paywall_has_user_paid($user->user_email, $site); |
| 120 |
|
| 121 |
if (false !== $expires) { |
| 122 |
|
| 123 |
$results .= apply_filters('leaky_paywall_subscriber_info_paid_subscriber_start', ''); |
| 124 |
|
| 125 |
$payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); |
| 126 |
$subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true); |
| 127 |
$plan = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_plan' . $site, true); |
| 128 |
$status = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, true); |
| 129 |
|
| 130 |
if (empty($payment_gateway) && empty($subscriber_id)) { |
| 131 |
continue; |
| 132 |
} |
| 133 |
|
| 134 |
$results .= apply_filters('leaky_paywall_subscriber_info_paid_subscriber_end', ''); |
| 135 |
|
| 136 |
$results .= '<p><a href="' . wp_logout_url(get_page_link($settings['page_for_login'])) . '">' . __('Log Out', 'leaky-paywall') . '</a></p>'; |
| 137 |
|
| 138 |
break; // We only want one. |
| 139 |
|
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
$results .= '</div>'; |
| 144 |
|
| 145 |
$results .= apply_filters('leaky_paywall_subscriber_info_end', ''); |
| 146 |
} |
| 147 |
|
| 148 |
$results .= leaky_paywall_subscription_options(); |
| 149 |
|
| 150 |
return $results; |
| 151 |
} |
| 152 |
add_shortcode('leaky_paywall_subscription', 'do_leaky_paywall_subscription'); |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
/** |
| 157 |
* Shortcode for zeen101's Leaky Paywall |
| 158 |
* Prints out the zeen101's Leaky Paywall |
| 159 |
* |
| 160 |
* @throws Exception Stripe error. |
| 161 |
*/ |
| 162 |
function do_leaky_paywall_profile() |
| 163 |
{ |
| 164 |
$settings = get_leaky_paywall_settings(); |
| 165 |
$mode = leaky_paywall_get_current_mode(); |
| 166 |
$site = leaky_paywall_get_current_site(); |
| 167 |
|
| 168 |
$update_billing_address_success = ''; |
| 169 |
$update_billing_address_error = ''; |
| 170 |
|
| 171 |
if ( isset( $_POST['lp_update_billing_address_nonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['lp_update_billing_address_nonce'] ) ), 'lp_update_billing_address' ) ) { |
| 172 |
|
| 173 |
$current_user = wp_get_current_user(); |
| 174 |
$profile_sub_id = get_user_meta( $current_user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true ); |
| 175 |
$profile_pay_gw = get_user_meta( $current_user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true ); |
| 176 |
|
| 177 |
if ( $profile_sub_id && 'stripe' === $profile_pay_gw ) { |
| 178 |
|
| 179 |
$billing_address = array( |
| 180 |
'name' => isset( $_POST['lp_billing_name'] ) ? sanitize_text_field( wp_unslash( $_POST['lp_billing_name'] ) ) : '', |
| 181 |
'line1' => isset( $_POST['lp_billing_line1'] ) ? sanitize_text_field( wp_unslash( $_POST['lp_billing_line1'] ) ) : '', |
| 182 |
'line2' => isset( $_POST['lp_billing_line2'] ) ? sanitize_text_field( wp_unslash( $_POST['lp_billing_line2'] ) ) : '', |
| 183 |
'city' => isset( $_POST['lp_billing_city'] ) ? sanitize_text_field( wp_unslash( $_POST['lp_billing_city'] ) ) : '', |
| 184 |
'state' => isset( $_POST['lp_billing_state'] ) ? sanitize_text_field( wp_unslash( $_POST['lp_billing_state'] ) ) : '', |
| 185 |
'postal_code' => isset( $_POST['lp_billing_postal_code'] ) ? sanitize_text_field( wp_unslash( $_POST['lp_billing_postal_code'] ) ) : '', |
| 186 |
'country' => isset( $_POST['lp_billing_country'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_POST['lp_billing_country'] ) ) ) : '', |
| 187 |
); |
| 188 |
|
| 189 |
update_user_meta( $current_user->ID, '_lp_billing_address', $billing_address ); |
| 190 |
|
| 191 |
try { |
| 192 |
$stripe = leaky_paywall_initialize_stripe_api(); |
| 193 |
leaky_paywall_stripe_update_billing_address( $stripe, $profile_sub_id, $billing_address ); |
| 194 |
$update_billing_address_success = __( 'Your billing address has been updated.', 'leaky-paywall' ); |
| 195 |
} catch ( \Stripe\Exception\ApiErrorException $e ) { |
| 196 |
$body = $e->getJsonBody(); |
| 197 |
$update_billing_address_error = $body['error']['message']; |
| 198 |
} |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
ob_start(); |
| 203 |
|
| 204 |
if (!is_user_logged_in()) { |
| 205 |
echo do_leaky_paywall_login(array()); |
| 206 |
$content = ob_get_contents(); |
| 207 |
ob_end_clean(); |
| 208 |
return $content; |
| 209 |
} |
| 210 |
|
| 211 |
$user = wp_get_current_user(); |
| 212 |
leaky_paywall_sync_stripe_subscription( $user ); |
| 213 |
|
| 214 |
$status = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_status' . $site, true); |
| 215 |
|
| 216 |
if (leaky_paywall_user_has_access()) { |
| 217 |
$has_access = __('Yes', 'leaky-paywall'); |
| 218 |
} else { |
| 219 |
$has_access = __('No', 'leaky-paywall'); |
| 220 |
} |
| 221 |
|
| 222 |
$level_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id' . $site, true); |
| 223 |
$level_id = apply_filters('get_leaky_paywall_users_level_id', $level_id, $user, $mode, $site); |
| 224 |
$level_id = apply_filters('get_leaky_paywall_subscription_level_level_id', $level_id); |
| 225 |
if (false === $level_id || empty($settings['levels'][$level_id]['label'])) { |
| 226 |
$level_name = __('Undefined', 'leaky-paywall'); |
| 227 |
} else { |
| 228 |
$level_name = stripcslashes($settings['levels'][$level_id]['label']); |
| 229 |
} |
| 230 |
|
| 231 |
$payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); |
| 232 |
|
| 233 |
$expires = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires' . $site, true); |
| 234 |
$expires = apply_filters('do_leaky_paywall_profile_shortcode_expiration_column', $expires, $user, $mode, $site, $level_id); |
| 235 |
if (empty($expires) || '0000-00-00 00:00:00' === $expires) { |
| 236 |
$expires = __('Never', 'leaky-paywall'); |
| 237 |
} else { |
| 238 |
$date_format = 'F j, Y'; |
| 239 |
$expires = mysql2date($date_format, $expires); |
| 240 |
} |
| 241 |
|
| 242 |
$plan = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_plan' . $site, true); |
| 243 |
if (!empty($plan) && 'Canceled' !== $plan && 'Never' !== $expires) { |
| 244 |
|
| 245 |
if ('canceled' === $status) { |
| 246 |
/* Translators: %s - expiration date */ |
| 247 |
$expires = sprintf(__('Ends on %s', 'leaky-paywall'), $expires); |
| 248 |
} elseif ('pending_cancel' === $status) { |
| 249 |
/* Translators: %s - expiration date */ |
| 250 |
$expires = sprintf(__('Expires on %s', 'leaky-paywall'), $expires); |
| 251 |
} elseif (!leaky_paywall_user_has_access()) { |
| 252 |
/* Translators: %s - expiration date */ |
| 253 |
$expires = sprintf(__('Expired on %s', 'leaky-paywall'), $expires); |
| 254 |
} else { |
| 255 |
/* Translators: %s - recurrs on date */ |
| 256 |
$expires = sprintf(__('Recurs on %s', 'leaky-paywall'), $expires); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
$expiration = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_expires' . $site, true); |
| 261 |
$cancel = ''; |
| 262 |
|
| 263 |
if (empty($expires) || '0000-00-00 00:00:00' === $expiration) { |
| 264 |
$cancel = ''; |
| 265 |
} elseif (strcasecmp('active', $status) === 0 && $plan && 'Canceled' !== $plan) { |
| 266 |
$subscriber_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_subscriber_id' . $site, true); |
| 267 |
$payment_gateway = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true); |
| 268 |
|
| 269 |
if ('free_registration' === $payment_gateway) { |
| 270 |
$cancel = ''; |
| 271 |
} else { |
| 272 |
/* Translators: %s - cancel url */ |
| 273 |
$cancel = sprintf(__('<a href="%s">Cancel your subscription</a>', 'leaky-paywall'), '?cancel&payment_gateway=' . $payment_gateway . '&subscriber_id=' . $subscriber_id); |
| 274 |
} |
| 275 |
} elseif (!empty($plan) && 'Canceled' === $plan) { |
| 276 |
/* Translators: %s - subscription url */ |
| 277 |
$cancel .= '<p>' . sprintf(__('You have canceled your subscription, but your account will remain active until your expiration date. To reactivate your subscription, please visit our <a href="%s">Subscription page</a>.', 'leaky-paywall'), get_page_link($settings['page_for_subscription'])) . '</p>'; |
| 278 |
} |
| 279 |
|
| 280 |
if ('stripe' === $payment_gateway) { |
| 281 |
$profile_payment = __('Credit Card', 'leaky-paywall'); |
| 282 |
} else { |
| 283 |
$profile_payment = leaky_paywall_translate_payment_gateway_slug_to_name($payment_gateway); |
| 284 |
} |
| 285 |
|
| 286 |
if (strcasecmp('active', $status) === 0 && !leaky_paywall_user_has_access()) { |
| 287 |
$status_name = __('Expired', 'leaky-paywall'); |
| 288 |
} else { |
| 289 |
$status_name = ucfirst($status); |
| 290 |
|
| 291 |
if ('Active' === $status_name) { |
| 292 |
$status_name = esc_html__('Active', 'leaky-paywall'); |
| 293 |
} |
| 294 |
|
| 295 |
if ('Trial' === $status_name) { |
| 296 |
$status_name = esc_html__('Trial', 'leaky-paywall'); |
| 297 |
} |
| 298 |
|
| 299 |
if ('pending_cancel' === $status) { |
| 300 |
$status_name = esc_html__('Cancels Soon', 'leaky-paywall'); |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
/* Translators: %1$s - user login, %2$s - logout url */ |
| 305 |
echo '<p class="leaky-paywall-logout-link">' . sprintf(__('Welcome %1$s, you are currently logged in. <a href="%2$s">Click here to log out.</a>', 'leaky-paywall') . '</p>', esc_html($user->user_login), esc_url(wp_logout_url(get_page_link($settings['page_for_login'])))); |
| 306 |
|
| 307 |
echo '<h2 class="leaky-paywall-profile-subscription-title">' . esc_html__('Your Subscription', 'leaky-paywall') . '</h2>'; |
| 308 |
|
| 309 |
do_action('leaky_paywall_profile_your_subscription_start'); |
| 310 |
|
| 311 |
$profile_table = '<table class="leaky-paywall-profile-subscription-details">'; |
| 312 |
$profile_table .= '<thead>'; |
| 313 |
$profile_table .= '<tr>'; |
| 314 |
$profile_table .= ' <th>' . __('Have Access', 'leaky-paywall') . '</th>'; |
| 315 |
$profile_table .= ' <th>' . __('Status', 'leaky-paywall') . '</th>'; |
| 316 |
$profile_table .= ' <th>' . __('Type', 'leaky-paywall') . '</th>'; |
| 317 |
$profile_table .= ' <th>' . __('Payment Method', 'leaky-paywall') . '</th>'; |
| 318 |
$profile_table .= ' <th>' . __('Expiration', 'leaky-paywall') . '</th>'; |
| 319 |
$profile_table .= '</tr>'; |
| 320 |
$profile_table .= '</thead>'; |
| 321 |
|
| 322 |
if (!empty($status) && !empty($level_name) && !empty($payment_gateway) && !empty($expires)) { |
| 323 |
$profile_table .= '<tbody>'; |
| 324 |
$profile_table .= ' <td>' . $has_access . '</td>'; |
| 325 |
$profile_table .= ' <td>' . $status_name . '</td>'; |
| 326 |
$profile_table .= ' <td>' . $level_name . '</td>'; |
| 327 |
$profile_table .= ' <td>' . $profile_payment . '</td>'; |
| 328 |
$profile_table .= ' <td>' . $expires . '</td>'; |
| 329 |
$profile_table .= '</tbody>'; |
| 330 |
} |
| 331 |
|
| 332 |
$profile_table .= '</table>'; |
| 333 |
|
| 334 |
echo wp_kses_post(apply_filters('leaky_paywall_profile_table', $profile_table, $user, $site, $mode, $settings)); |
| 335 |
|
| 336 |
do_action('leaky_paywall_profile_your_subscription_end'); |
| 337 |
|
| 338 |
echo '<div class="leaky-paywall-subscriber-info">'; |
| 339 |
|
| 340 |
do_action('leaky_paywall_profile_your_payment_info_start'); |
| 341 |
|
| 342 |
if ( 'stripe' === $payment_gateway && 'on' === $settings['stripe_billing_address'] ) { |
| 343 |
|
| 344 |
$billing_address = get_user_meta( $user->ID, '_lp_billing_address', true ); |
| 345 |
if ( ! is_array( $billing_address ) ) { |
| 346 |
$billing_address = array(); |
| 347 |
} |
| 348 |
$billing_address = wp_parse_args( $billing_address, array( |
| 349 |
'name' => '', |
| 350 |
'line1' => '', |
| 351 |
'line2' => '', |
| 352 |
'city' => '', |
| 353 |
'state' => '', |
| 354 |
'postal_code' => '', |
| 355 |
'country' => '', |
| 356 |
) ); |
| 357 |
|
| 358 |
echo '<h2 class="leaky-paywall-your-billing-address-header">' . esc_html__( 'Billing Address', 'leaky-paywall' ) . '</h2>'; |
| 359 |
|
| 360 |
if ( $update_billing_address_success ) { |
| 361 |
echo '<div class="leaky_paywall_message success"><p>' . esc_html( $update_billing_address_success ) . '</p></div>'; |
| 362 |
} |
| 363 |
if ( $update_billing_address_error ) { |
| 364 |
echo '<div class="leaky_paywall_message error"><p>' . esc_html( $update_billing_address_error ) . '</p></div>'; |
| 365 |
} |
| 366 |
|
| 367 |
echo '<form id="leaky-paywall-billing-address-form" action="" method="post">'; |
| 368 |
|
| 369 |
echo '<p><label class="leaky-paywall-field-label" for="lp-billing-name">' . esc_html__( 'Name on Card', 'leaky-paywall' ) . '</label>'; |
| 370 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="lp-billing-name" name="lp_billing_name" value="' . esc_attr( $billing_address['name'] ) . '" /></p>'; |
| 371 |
|
| 372 |
echo '<p><label class="leaky-paywall-field-label" for="lp-billing-line1">' . esc_html__( 'Address Line 1', 'leaky-paywall' ) . '</label>'; |
| 373 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="lp-billing-line1" name="lp_billing_line1" value="' . esc_attr( $billing_address['line1'] ) . '" /></p>'; |
| 374 |
|
| 375 |
echo '<p><label class="leaky-paywall-field-label" for="lp-billing-line2">' . esc_html__( 'Address Line 2', 'leaky-paywall' ) . '</label>'; |
| 376 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="lp-billing-line2" name="lp_billing_line2" value="' . esc_attr( $billing_address['line2'] ) . '" /></p>'; |
| 377 |
|
| 378 |
echo '<p><label class="leaky-paywall-field-label" for="lp-billing-city">' . esc_html__( 'City', 'leaky-paywall' ) . '</label>'; |
| 379 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="lp-billing-city" name="lp_billing_city" value="' . esc_attr( $billing_address['city'] ) . '" /></p>'; |
| 380 |
|
| 381 |
echo '<p><label class="leaky-paywall-field-label" for="lp-billing-state">' . esc_html__( 'State / Province', 'leaky-paywall' ) . '</label>'; |
| 382 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="lp-billing-state" name="lp_billing_state" value="' . esc_attr( $billing_address['state'] ) . '" /></p>'; |
| 383 |
|
| 384 |
echo '<p><label class="leaky-paywall-field-label" for="lp-billing-postal-code">' . esc_html__( 'Postal Code', 'leaky-paywall' ) . '</label>'; |
| 385 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="lp-billing-postal-code" name="lp_billing_postal_code" value="' . esc_attr( $billing_address['postal_code'] ) . '" /></p>'; |
| 386 |
|
| 387 |
echo '<p><label class="leaky-paywall-field-label" for="lp-billing-country">' . esc_html__( 'Country (2-letter code)', 'leaky-paywall' ) . '</label>'; |
| 388 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="lp-billing-country" name="lp_billing_country" maxlength="2" value="' . esc_attr( $billing_address['country'] ) . '" placeholder="US" /></p>'; |
| 389 |
|
| 390 |
wp_nonce_field( 'lp_update_billing_address', 'lp_update_billing_address_nonce', true ); |
| 391 |
|
| 392 |
echo '<p class="submit"><input type="submit" class="button button-primary" value="' . esc_attr__( 'Update Billing Address', 'leaky-paywall' ) . '" /></p>'; |
| 393 |
echo '</form>'; |
| 394 |
|
| 395 |
echo '<hr>'; |
| 396 |
} |
| 397 |
|
| 398 |
do_action('leaky_paywall_subscriber_info_paid_subscriber_start'); |
| 399 |
|
| 400 |
echo '</div>'; |
| 401 |
|
| 402 |
do_action('leaky_paywall_profile_your_payment_info_end'); |
| 403 |
|
| 404 |
echo '<hr>'; |
| 405 |
|
| 406 |
do_action('leaky_paywall_profile_your_profile_start'); |
| 407 |
|
| 408 |
echo '<h2 class="leaky-paywall-your-profile-header">' . esc_html__('Your Profile', 'leaky-paywall') . '</h2>'; |
| 409 |
|
| 410 |
if (!empty($_POST['leaky-paywall-profile-nonce'])) { |
| 411 |
|
| 412 |
if (wp_verify_nonce(sanitize_key(wp_unslash($_POST['leaky-paywall-profile-nonce'])), 'leaky-paywall-profile')) { |
| 413 |
|
| 414 |
try { |
| 415 |
$userdata = get_userdata($user->ID); |
| 416 |
$args = array( |
| 417 |
'ID' => $user->ID, |
| 418 |
'user_login' => $userdata->user_login, |
| 419 |
'display_name' => $userdata->display_name, |
| 420 |
'user_email' => $userdata->user_email, |
| 421 |
); |
| 422 |
|
| 423 |
if (!empty($_POST['username'])) { |
| 424 |
$args['user_login'] = sanitize_text_field(wp_unslash($_POST['username'])); |
| 425 |
} |
| 426 |
|
| 427 |
if (!empty($_POST['displayname'])) { |
| 428 |
$args['display_name'] = sanitize_text_field(wp_unslash($_POST['displayname'])); |
| 429 |
} |
| 430 |
|
| 431 |
if (!empty($_POST['email'])) { |
| 432 |
if (is_email(wp_unslash($_POST['email']))) { |
| 433 |
$args['user_email'] = sanitize_email(wp_unslash($_POST['email'])); |
| 434 |
} else { |
| 435 |
throw new Exception(__('Invalid email address.', 'leaky-paywall')); |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
if (!empty($_POST['password1']) && !empty($_POST['password2'])) { |
| 440 |
if ($_POST['password1'] === $_POST['password2']) { |
| 441 |
wp_set_password(sanitize_text_field(wp_unslash(($_POST['password1']))), $user->ID); |
| 442 |
} else { |
| 443 |
throw new Exception(__('Passwords do not match.', 'leaky-paywall')); |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
$user_id = wp_update_user($args); |
| 448 |
|
| 449 |
if (is_wp_error($user_id)) { |
| 450 |
throw new Exception($user_id->get_error_message()); |
| 451 |
} else { |
| 452 |
$user = get_userdata($user_id); // Refresh the user object. |
| 453 |
echo '<div class="leaky_paywall_message success"><p>' . esc_html__('Profile Changes Saved.', 'leaky-paywall') . '</p></div>'; |
| 454 |
|
| 455 |
do_action('leaky_paywall_after_profile_changes_saved', $user_id, $args, $userdata); |
| 456 |
} |
| 457 |
} catch (Exception $e) { |
| 458 |
echo '<div class="leaky_paywall_message error"><p class="error">' . esc_html($e->getMessage()) . '</p></div>'; |
| 459 |
} |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
echo '<form id="leaky-paywall-profile" action="" method="post">'; |
| 464 |
|
| 465 |
echo '<p>'; |
| 466 |
echo '<label class="leaky-paywall-field-label" for="leaky-paywall-username">' . esc_html__('Username', 'leaky-paywall') . '</label>'; |
| 467 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-username" name="username" value="' . esc_attr($user->user_login) . '" disabled="disabled" readonly="readonly" />'; |
| 468 |
echo '</p>'; |
| 469 |
|
| 470 |
echo '<p>'; |
| 471 |
echo '<label class="leaky-paywall-field-label" for="leaky-paywall-display-name">' . esc_html__('Display Name', 'leaky-paywall') . '</label>'; |
| 472 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-display-name" name="displayname" value="' . esc_attr($user->display_name) . '" />'; |
| 473 |
echo '</p>'; |
| 474 |
|
| 475 |
echo '<p>'; |
| 476 |
echo '<label class="leaky-paywall-field-label" for="leaky-paywall-email">' . esc_html__('Email', 'leaky-paywall') . '</label>'; |
| 477 |
echo '<input type="text" class="issuem-leaky-paywall-field-input" id="leaky-paywall-email" name="email" value="' . esc_attr($user->user_email) . '" />'; |
| 478 |
echo '</p>'; |
| 479 |
|
| 480 |
echo '<p>'; |
| 481 |
echo '<label class="leaky-paywall-field-label" for="leaky-paywall-password1">' . esc_html__('New Password', 'leaky-paywall') . '</label>'; |
| 482 |
echo '<input type="password" class="issuem-leaky-paywall-field-input" id="leaky-paywall-password1" name="password1" value="" />'; |
| 483 |
echo '</p>'; |
| 484 |
|
| 485 |
echo '<p>'; |
| 486 |
echo '<label class="leaky-paywall-field-label" for="leaky-paywall-gift-subscription-password2">' . esc_html__('New Password (again)', 'leaky-paywall') . '</label>'; |
| 487 |
echo '<input type="password" class="issuem-leaky-paywall-field-input" id="leaky-paywall-gift-subscription-password2" name="password2" value="" />'; |
| 488 |
echo '</p>'; |
| 489 |
|
| 490 |
do_action('leaky_paywall_profile_your_profile_before_submit'); |
| 491 |
|
| 492 |
wp_nonce_field('leaky-paywall-profile', 'leaky-paywall-profile-nonce', true); |
| 493 |
|
| 494 |
echo '<p class="submit"><input type="submit" id="submit" class="button button-primary" value="' . esc_attr__('Save Profile Changes', 'leaky-paywall') . '" /></p>'; |
| 495 |
echo '</form>'; |
| 496 |
|
| 497 |
$_lp_delete_gateway = get_user_meta( $user->ID, '_issuem_leaky_paywall_' . $mode . '_payment_gateway' . $site, true ); |
| 498 |
if ( 'stripe' === $_lp_delete_gateway ) { |
| 499 |
$delete_message = esc_html__( 'Deleting your account will delete your access and all your information on this site. Your active subscription will be cancelled automatically. Are you sure you want to continue?', 'leaky-paywall' ); |
| 500 |
} else { |
| 501 |
$delete_message = esc_html__( 'Deleting your account will delete your access and all your information on this site. If you have a recurring subscription, you must cancel that separately to stop future payments. Are you sure you want to continue?', 'leaky-paywall' ); |
| 502 |
} |
| 503 |
|
| 504 |
if ('on' === $settings['enable_user_delete_account']) { |
| 505 |
echo '<form id="leaky-paywall-delete-account" action="" method="post">'; |
| 506 |
echo '<p><button type="submit" onclick="return confirm(\'' . $delete_message . '\')">' . esc_html__('Delete Account', 'leaky-paywall') . '</button></p>'; |
| 507 |
wp_nonce_field('leaky-paywall-delete-account', 'leaky-paywall-delete-account-nonce', true); |
| 508 |
echo '</form>'; |
| 509 |
} |
| 510 |
|
| 511 |
do_action('leaky_paywall_profile_your_profile_end'); |
| 512 |
|
| 513 |
$content = ob_get_contents(); |
| 514 |
ob_end_clean(); |
| 515 |
|
| 516 |
return $content; |
| 517 |
} |
| 518 |
add_shortcode('leaky_paywall_profile', 'do_leaky_paywall_profile'); |
| 519 |
|
| 520 |
|
| 521 |
/** |
| 522 |
* Outputs the default Leaky Paywall register form |
| 523 |
* |
| 524 |
* @since 3.7.0 |
| 525 |
* |
| 526 |
* @param array $atts Shortcode attributes. |
| 527 |
*/ |
| 528 |
function do_leaky_paywall_register_form($atts) |
| 529 |
{ |
| 530 |
$a = shortcode_atts( |
| 531 |
array( |
| 532 |
'level_id' => '', |
| 533 |
), |
| 534 |
$atts |
| 535 |
); |
| 536 |
|
| 537 |
$settings = get_leaky_paywall_settings(); |
| 538 |
|
| 539 |
if (is_numeric($a['level_id'])) { |
| 540 |
$level_id = $a['level_id']; |
| 541 |
} else { |
| 542 |
$level_id = isset($_GET['level_id']) ? sanitize_text_field(wp_unslash($_GET['level_id'])) : null; |
| 543 |
} |
| 544 |
|
| 545 |
$level = get_leaky_paywall_subscription_level($level_id); |
| 546 |
|
| 547 |
if (is_null($level_id) || !$level || is_level_deleted($level_id)) { |
| 548 |
$content = '<p>' . __('Please', 'leaky-paywall') . ' <a href="' . get_page_link($settings['page_for_subscription']) . '">' . __('go to the subscribe page', 'leaky-paywall') . '</a> ' . __('to choose a subscription level.', 'leaky-paywall') . '</p>'; |
| 549 |
return $content; |
| 550 |
} |
| 551 |
|
| 552 |
// Prevent duplicate subscriptions: if a logged-in user already has an active |
| 553 |
// subscription at the requested level, don't show the checkout form. |
| 554 |
if ( is_user_logged_in() && leaky_paywall_user_has_active_subscription_at_level( null, $level_id ) ) { |
| 555 |
$account_url = ! empty( $settings['page_for_profile'] ) ? get_page_link( $settings['page_for_profile'] ) : home_url(); |
| 556 |
$content = '<p>' . __( 'You are already subscribed to this level.', 'leaky-paywall' ) . ' '; |
| 557 |
$content .= '<a href="' . esc_url( $account_url ) . '">' . __( 'Visit your account', 'leaky-paywall' ) . '</a> '; |
| 558 |
$content .= __( 'to manage your subscription.', 'leaky-paywall' ) . '</p>'; |
| 559 |
|
| 560 |
/** |
| 561 |
* Filter the message shown when a logged-in user tries to subscribe to a |
| 562 |
* level they already have an active subscription on. Lets extensions render |
| 563 |
* alternative content — e.g. a "Resume Billing" CTA for pending_cancel |
| 564 |
* subscribers, where "already subscribed" is the wrong mental model. |
| 565 |
* |
| 566 |
* @since 5.1.0 |
| 567 |
* |
| 568 |
* @param string $content Default already-subscribed message HTML. |
| 569 |
* @param int $level_id Level ID the user is trying to subscribe to. |
| 570 |
* @param WP_User $user Current user. |
| 571 |
*/ |
| 572 |
return apply_filters( 'leaky_paywall_already_subscribed_at_level_content', $content, $level_id, wp_get_current_user() ); |
| 573 |
} |
| 574 |
|
| 575 |
if (is_level_hidden($level)) { |
| 576 |
$content = '<p>' . __('This level is not available. Please', 'leaky-paywall') . ' <a href="' . get_page_link($settings['page_for_subscription']) . '">' . __('go to the subscribe page', 'leaky-paywall') . '</a> ' . __('to choose a different subscription level.', 'leaky-paywall') . '</p>'; |
| 577 |
return $content; |
| 578 |
} |
| 579 |
|
| 580 |
$site = leaky_paywall_get_current_site(); |
| 581 |
$currency = leaky_paywall_get_currency(); |
| 582 |
$userdata = wp_get_current_user(); |
| 583 |
|
| 584 |
if (!empty($userdata)) { |
| 585 |
$email = $userdata->user_email; |
| 586 |
$username = $userdata->user_login; |
| 587 |
$first = $userdata->first_name ? $userdata->first_name : leaky_paywall_old_form_value('first_name', false); |
| 588 |
$last = $userdata->last_name ? $userdata->last_name : leaky_paywall_old_form_value('last_name', false); |
| 589 |
} else { |
| 590 |
$email = leaky_paywall_old_form_value('email_address', false); |
| 591 |
$username = leaky_paywall_old_form_value('username', false); |
| 592 |
$first = leaky_paywall_old_form_value('first_name', false); |
| 593 |
$last = leaky_paywall_old_form_value('last_name', false); |
| 594 |
} |
| 595 |
|
| 596 |
$gateways = leaky_paywall_get_enabled_payment_gateways($level_id); |
| 597 |
|
| 598 |
if (array_key_exists('stripe', $gateways) && !array_key_exists('stripe_checkout', $gateways)) { |
| 599 |
$one_page_form = false; |
| 600 |
} else { |
| 601 |
$one_page_form = true; |
| 602 |
} |
| 603 |
|
| 604 |
ob_start(); |
| 605 |
|
| 606 |
// show any error messages after form submission. |
| 607 |
leaky_paywall_show_error_messages('register'); |
| 608 |
?> |
| 609 |
|
| 610 |
<div class="leaky-paywall-subscription-details-wrapper"> |
| 611 |
|
| 612 |
<h3 class="leaky-paywall-subscription-details-title"><?php printf(esc_html__('Order Summary', 'leaky-paywall')); ?></h3> |
| 613 |
|
| 614 |
<?php if (!is_user_logged_in()) { |
| 615 |
?> |
| 616 |
<div class="leaky-paywall-form-login-toggle" style="background: #E4F8FF; border-top: 5px solid #016B83; padding: 10px 20px; margin-bottom: 20px;"> |
| 617 |
<p style="padding: 0; margin: 0; color: #000;"><?php esc_html_e('Already have an account?', 'leaky-paywall'); ?> <a style="color: #016B83;" href="#" class="lpshowlogin"><?php esc_html_e('Click here to login', 'leaky-paywall'); ?></a></p> |
| 618 |
</div> |
| 619 |
|
| 620 |
<div class="leaky-paywall-form-login" style="border: 1px solid #ddd; padding: 20px; margin-bottom: 20px;"> |
| 621 |
<p><?php esc_html_e('If you already have an account on this site, please login below. Otherwise, please proceed to the Details section.', 'leaky-paywall'); ?></p> |
| 622 |
<?php wp_login_form(); ?> |
| 623 |
|
| 624 |
<p><a href="<?php echo esc_url(wp_lostpassword_url()); ?>"><?php esc_html_e('Lost your password?', 'leaky-paywall'); ?></a></p> |
| 625 |
</div> |
| 626 |
|
| 627 |
<style> |
| 628 |
.leaky-paywall-form-login { |
| 629 |
display: none; |
| 630 |
} |
| 631 |
|
| 632 |
.leaky-paywall-form-login label { |
| 633 |
display: block; |
| 634 |
} |
| 635 |
</style> |
| 636 |
|
| 637 |
<?php |
| 638 |
} ?> |
| 639 |
|
| 640 |
<ul class="leaky-paywall-subscription-details"> |
| 641 |
<li class="leaky-paywall-subscription-details-subscription-name"><strong><?php printf(esc_attr__('Your Order:', 'leaky-paywall')); ?></strong> <?php echo wp_kses_post(apply_filters('leaky_paywall_registration_level_name', $level['label'])); ?></li> |
| 642 |
<li class="leaky-paywall-subscription-details-subscription-length"><strong><?php printf(esc_attr__('Subscription Length:', 'leaky-paywall')); ?></strong> <?php echo 'unlimited' === $level['subscription_length_type'] ? esc_attr__('Forever', 'leaky-paywall') : esc_attr($level['interval_count']) . ' ' . leaky_paywall_get_interval_text($level['interval'], $level['interval_count']); ?></li> |
| 643 |
<li class="leaky-paywall-subscription-details-recurring"><strong><?php printf(esc_attr__('Recurring:', 'leaky-paywall')); ?> </strong> <?php echo !empty($level['recurring']) && 'on' === $level['recurring'] ? esc_attr__('Yes', 'leaky-paywall') : esc_attr__('No', 'leaky-paywall'); ?></li> |
| 644 |
<li class="leaky-paywall-subscription-details-content-access"><strong><?php printf(esc_attr__('Content Access:', 'leaky-paywall')); ?></strong> |
| 645 |
|
| 646 |
<?php |
| 647 |
$content_access_description = ''; |
| 648 |
$i = 0; |
| 649 |
|
| 650 |
if (!empty($level['post_types']) && empty($level['registration_form_description'])) { |
| 651 |
foreach ($level['post_types'] as $type) { |
| 652 |
if ($i > 0) { |
| 653 |
$content_access_description .= ', '; |
| 654 |
} |
| 655 |
|
| 656 |
$post_type = get_post_type_object($type['post_type']); |
| 657 |
|
| 658 |
if (null == $post_type) { |
| 659 |
continue; |
| 660 |
} |
| 661 |
|
| 662 |
if ('unlimited' === $type['allowed']) { |
| 663 |
$content_access_description .= ucfirst($type['allowed']) . ' ' . $post_type->labels->name; |
| 664 |
} else { |
| 665 |
$post_type_label = '1' === $type['allowed_value'] ? $post_type->labels->singular_name : $post_type->labels->name; |
| 666 |
$content_access_description .= $type['allowed_value'] . ' ' . $post_type_label; |
| 667 |
} |
| 668 |
|
| 669 |
$i++; |
| 670 |
} |
| 671 |
} else { |
| 672 |
$content_access_description = stripslashes($level['registration_form_description'] ?? ''); |
| 673 |
} |
| 674 |
|
| 675 |
echo wp_kses_post(apply_filters('leaky_paywall_content_access_description', $content_access_description, $level, $level_id)); |
| 676 |
?> |
| 677 |
|
| 678 |
</li> |
| 679 |
|
| 680 |
</ul> |
| 681 |
|
| 682 |
<p class="leaky-paywall-subscription-total"> |
| 683 |
|
| 684 |
<?php $display_price = leaky_paywall_get_level_display_price($level); ?> |
| 685 |
|
| 686 |
<strong><?php echo esc_html__('Total:', 'leaky-paywall'); ?></strong> <?php echo esc_html(apply_filters('leaky_paywall_your_subscription_total', $display_price, $level)); ?> |
| 687 |
</p> |
| 688 |
|
| 689 |
</div> |
| 690 |
|
| 691 |
<?php |
| 692 |
// Show subscription change notice with proration preview for logged-in subscribers. |
| 693 |
if ( is_user_logged_in() ) { |
| 694 |
$lp_current_user = wp_get_current_user(); |
| 695 |
$lp_mode = leaky_paywall_get_current_mode(); |
| 696 |
$lp_site = leaky_paywall_get_current_site(); |
| 697 |
$lp_current_plan = get_user_meta( $lp_current_user->ID, '_issuem_leaky_paywall_' . $lp_mode . '_plan' . $lp_site, true ); |
| 698 |
$lp_current_status = get_user_meta( $lp_current_user->ID, '_issuem_leaky_paywall_' . $lp_mode . '_payment_status' . $lp_site, true ); |
| 699 |
$lp_subscriber_id = get_user_meta( $lp_current_user->ID, '_issuem_leaky_paywall_' . $lp_mode . '_subscriber_id' . $lp_site, true ); |
| 700 |
$lp_gateway = get_user_meta( $lp_current_user->ID, '_issuem_leaky_paywall_' . $lp_mode . '_payment_gateway' . $lp_site, true ); |
| 701 |
|
| 702 |
if ( ! empty( $lp_current_plan ) && ! empty( $lp_subscriber_id ) |
| 703 |
&& in_array( $lp_current_status, array( 'active', 'trial' ), true ) |
| 704 |
&& in_array( $lp_gateway, array( 'stripe', 'stripe_checkout' ), true ) |
| 705 |
&& isset( $level['recurring'] ) && 'on' === $level['recurring'] ) { |
| 706 |
|
| 707 |
$lp_current_level_id = leaky_paywall_subscriber_current_level_id(); |
| 708 |
$lp_current_level = get_leaky_paywall_subscription_level( $lp_current_level_id ); |
| 709 |
$lp_current_level_name = isset( $lp_current_level['label'] ) ? $lp_current_level['label'] : ''; |
| 710 |
|
| 711 |
// Get prorated cost and card on file from Stripe. |
| 712 |
$lp_proration_message = ''; |
| 713 |
$lp_card_message = ''; |
| 714 |
try { |
| 715 |
$lp_stripe = leaky_paywall_initialize_stripe_api(); |
| 716 |
$lp_subscriptions = $lp_stripe->subscriptions->all( |
| 717 |
array( 'customer' => $lp_subscriber_id, 'limit' => 1 ), |
| 718 |
leaky_paywall_get_stripe_connect_params() |
| 719 |
); |
| 720 |
|
| 721 |
// Get card on file. |
| 722 |
$lp_methods = $lp_stripe->paymentMethods->all( |
| 723 |
array( 'customer' => $lp_subscriber_id, 'type' => 'card' ), |
| 724 |
leaky_paywall_get_stripe_connect_params() |
| 725 |
); |
| 726 |
if ( ! empty( $lp_methods->data ) && isset( $lp_methods->data[0]->card ) ) { |
| 727 |
$lp_card = $lp_methods->data[0]->card; |
| 728 |
$lp_card_message = sprintf( |
| 729 |
/* translators: %1$s: card brand, %2$s: last 4 digits */ |
| 730 |
__( 'Your %1$s ending in %2$s will be used for payment.', 'leaky-paywall' ), |
| 731 |
'<strong>' . esc_html( ucwords( $lp_card->brand ) ) . '</strong>', |
| 732 |
'<strong>' . esc_html( $lp_card->last4 ) . '</strong>' |
| 733 |
); |
| 734 |
} |
| 735 |
|
| 736 |
if ( ! empty( $lp_subscriptions->data ) ) { |
| 737 |
$lp_current_sub = $lp_subscriptions->data[0]; |
| 738 |
|
| 739 |
$lp_stripe_price = number_format( (float) $level['price'], 2, '', '' ); |
| 740 |
$lp_plan_args = array( |
| 741 |
'stripe_price' => $lp_stripe_price, |
| 742 |
'currency' => leaky_paywall_get_currency(), |
| 743 |
'secret_key' => leaky_paywall_get_stripe_secret_key(), |
| 744 |
); |
| 745 |
$lp_new_plan = leaky_paywall_get_stripe_plan( $level, $level_id, $lp_plan_args ); |
| 746 |
|
| 747 |
if ( $lp_new_plan ) { |
| 748 |
$lp_upcoming = $lp_stripe->invoices->upcoming( |
| 749 |
array( |
| 750 |
'customer' => $lp_subscriber_id, |
| 751 |
'subscription' => $lp_current_sub->id, |
| 752 |
'subscription_items' => array( |
| 753 |
array( |
| 754 |
'id' => $lp_current_sub->items->data[0]->id, |
| 755 |
'price' => $lp_new_plan->id, |
| 756 |
), |
| 757 |
), |
| 758 |
'subscription_proration_behavior' => 'always_invoice', |
| 759 |
), |
| 760 |
leaky_paywall_get_stripe_connect_params() |
| 761 |
); |
| 762 |
|
| 763 |
$lp_proration_total = $lp_upcoming->amount_due; |
| 764 |
$lp_currency_symbol = html_entity_decode( leaky_paywall_get_current_currency_symbol() ); |
| 765 |
|
| 766 |
if ( $lp_proration_total > 0 ) { |
| 767 |
$lp_proration_message = sprintf( |
| 768 |
/* translators: %s: prorated charge amount */ |
| 769 |
__( 'A prorated charge of %s will be applied immediately.', 'leaky-paywall' ), |
| 770 |
'<strong>' . esc_html( $lp_currency_symbol . number_format( $lp_proration_total / 100, 2 ) ) . '</strong>' |
| 771 |
); |
| 772 |
} elseif ( $lp_proration_total < 0 ) { |
| 773 |
$lp_proration_message = sprintf( |
| 774 |
/* translators: %s: credit amount */ |
| 775 |
__( 'A credit of %s will be applied to your next billing cycle.', 'leaky-paywall' ), |
| 776 |
'<strong>' . esc_html( $lp_currency_symbol . number_format( abs( $lp_proration_total ) / 100, 2 ) ) . '</strong>' |
| 777 |
); |
| 778 |
} else { |
| 779 |
$lp_proration_message = __( 'No additional charges will apply.', 'leaky-paywall' ); |
| 780 |
} |
| 781 |
} |
| 782 |
} |
| 783 |
} catch ( \Throwable $th ) { |
| 784 |
leaky_paywall_log_error( $th->getMessage(), 'proration preview error' ); |
| 785 |
} |
| 786 |
?> |
| 787 |
<div class="leaky-paywall-subscription-change-notice" style="background: #FEF9E7; border-left: 4px solid #F0C929; padding: 12px 16px; margin-bottom: 20px; font-size: 14px;"> |
| 788 |
<p style="margin: 0 0 8px 0;"> |
| 789 |
<strong><?php esc_html_e( 'Subscription Change:', 'leaky-paywall' ); ?></strong> |
| 790 |
<?php |
| 791 |
printf( |
| 792 |
/* translators: %1$s: current level name, %2$s: new level name */ |
| 793 |
esc_html__( 'You currently have an active %1$s subscription. Completing this form will change your subscription to %2$s.', 'leaky-paywall' ), |
| 794 |
'<strong>' . esc_html( $lp_current_level_name ) . '</strong>', |
| 795 |
'<strong>' . esc_html( $level['label'] ) . '</strong>' |
| 796 |
); |
| 797 |
if ( $lp_proration_message ) { |
| 798 |
echo ' ' . wp_kses_post( $lp_proration_message ); |
| 799 |
} |
| 800 |
?> |
| 801 |
</p> |
| 802 |
<?php if ( $lp_card_message ) : ?> |
| 803 |
<p style="margin: 0; color: #666;"> |
| 804 |
<?php echo wp_kses_post( $lp_card_message ); ?> |
| 805 |
</p> |
| 806 |
<?php endif; ?> |
| 807 |
</div> |
| 808 |
<script> |
| 809 |
document.addEventListener('DOMContentLoaded', function() { |
| 810 |
var label = '<?php echo esc_js( __( 'Change Subscription', 'leaky-paywall' ) ); ?>'; |
| 811 |
var nextBtn = document.getElementById('leaky-paywall-registration-next'); |
| 812 |
if (nextBtn) nextBtn.textContent = label; |
| 813 |
var checkoutBtn = document.getElementById('checkout'); |
| 814 |
if (checkoutBtn) checkoutBtn.textContent = label; |
| 815 |
}); |
| 816 |
</script> |
| 817 |
<?php |
| 818 |
} |
| 819 |
} |
| 820 |
?> |
| 821 |
|
| 822 |
<?php do_action('leaky_paywall_before_registration_form', $level); ?> |
| 823 |
|
| 824 |
<?php |
| 825 |
if ($level['price'] > 0 && !$one_page_form) { |
| 826 |
?> |
| 827 |
<div class="leaky-paywall-form-steps"> |
| 828 |
<div class="leaky-paywall-form-account-setup-step leaky-paywall-form-step active"> |
| 829 |
<span class="step-number">1</span> |
| 830 |
<span class="step-title"><?php esc_html_e('Account Setup', 'leaky-paywall'); ?></span> |
| 831 |
</div> |
| 832 |
<div class="leaky-paywall-form-payment-setup-step leaky-paywall-form-step"> |
| 833 |
<span class="step-number">2</span> |
| 834 |
<span class="step-title"><?php esc_html_e('Payment', 'leaky-paywall'); ?></span> |
| 835 |
</div> |
| 836 |
</div> |
| 837 |
<?php |
| 838 |
} |
| 839 |
?> |
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
<form action="" method="POST" name="payment-form" id="leaky-paywall-payment-form" class="leaky-paywall-payment-form"> |
| 844 |
<span class="payment-errors"></span> |
| 845 |
|
| 846 |
<div id="leaky-paywall-registration-errors"></div> |
| 847 |
|
| 848 |
<div class="leaky-paywall-registration-user-container"> |
| 849 |
|
| 850 |
<?php do_action('leaky_paywall_before_registration_form_user_fields', $level); ?> |
| 851 |
|
| 852 |
<div class="leaky-paywall-user-fields"> |
| 853 |
|
| 854 |
<h3><?php printf(esc_attr__('Your Details', 'leaky-paywall')); ?></h3> |
| 855 |
|
| 856 |
<p class="form-row first-name"> |
| 857 |
<label for="first_name"><?php printf(esc_attr__('First Name', 'leaky-paywall')); ?> <i class="required">*</i></label> |
| 858 |
<input type="text" size="20" name="first_name" required value="<?php echo esc_attr($first); ?>" /> |
| 859 |
</p> |
| 860 |
|
| 861 |
<p class="form-row last-name"> |
| 862 |
<label for="last_name"><?php printf(esc_attr__('Last Name', 'leaky-paywall')); ?> <i class="required">*</i></label> |
| 863 |
<input type="text" size="20" name="last_name" required value="<?php echo esc_attr($last); ?>" /> |
| 864 |
</p> |
| 865 |
|
| 866 |
<p class="form-row email-address"> |
| 867 |
<label for="email_address"><?php printf(esc_attr__('Email Address', 'leaky-paywall')); ?> <i class="required">*</i></label> |
| 868 |
<input type="email" size="20" id="email_address" name="email_address" required value="<?php echo esc_attr($email); ?>" <?php echo !empty($email) && !empty($userdata) ? 'disabled="disabled"' : ''; ?> /> |
| 869 |
</p> |
| 870 |
|
| 871 |
</div> |
| 872 |
|
| 873 |
<?php do_action('leaky_paywall_before_registration_form_account_fields', $level); ?> |
| 874 |
|
| 875 |
<div class="leaky-paywall-account-fields"> |
| 876 |
|
| 877 |
<h3><?php printf(esc_attr__('Account Details', 'leaky-paywall')); ?></h3> |
| 878 |
|
| 879 |
<?php |
| 880 |
if ('off' === $settings['remove_username_field']) { |
| 881 |
?> |
| 882 |
<p class="form-row username"> |
| 883 |
<label for="username"><?php printf(esc_attr__('Username', 'leaky-paywall')); ?> <i class="required">*</i></label> |
| 884 |
<input type="text" size="20" name="username" id="username" required value="<?php echo esc_attr($username); ?>" <?php echo !empty($username) && !empty($userdata) ? 'disabled="disabled"' : ''; ?> /> |
| 885 |
</p> |
| 886 |
<?php |
| 887 |
} |
| 888 |
?> |
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
<?php if (!is_user_logged_in()) { ?> |
| 893 |
|
| 894 |
<p class="form-row password"> |
| 895 |
<label for="password"><?php printf(esc_attr__('Password', 'leaky-paywall')); ?> <i class="required">*</i></label> |
| 896 |
<input type="password" size="20" id="password" required name="password" /> |
| 897 |
</p> |
| 898 |
|
| 899 |
<p class="form-row confirm-password"> |
| 900 |
<label for="confirm_password"><?php printf(esc_attr__('Confirm Password', 'leaky-paywall')); ?> <i class="required">*</i></label> |
| 901 |
<input type="password" size="20" id="confirm_password" required name="confirm_password" /> |
| 902 |
</p> |
| 903 |
|
| 904 |
<?php } ?> |
| 905 |
|
| 906 |
</div> |
| 907 |
|
| 908 |
<?php do_action('leaky_paywall_after_password_registration_field', $level_id, $level); ?> |
| 909 |
|
| 910 |
<?php |
| 911 |
$tc_settings = get_leaky_paywall_settings(); |
| 912 |
if ( 'on' === $tc_settings['enable_terms_and_conditions'] && 0 != $level['price'] && ! $one_page_form ) : |
| 913 |
$tc_text = $tc_settings['terms_and_conditions_text']; |
| 914 |
$tc_page_id = $tc_settings['page_for_terms']; |
| 915 |
|
| 916 |
if ( $tc_page_id ) { |
| 917 |
$tc_url = get_permalink( $tc_page_id ); |
| 918 |
$tc_label = preg_replace( |
| 919 |
'/\[(.+?)\]/', |
| 920 |
'<a href="' . esc_url( $tc_url ) . '" target="_blank">$1</a>', |
| 921 |
esc_html( $tc_text ) |
| 922 |
); |
| 923 |
} else { |
| 924 |
$tc_label = esc_html( preg_replace( '/\[(.+?)\]/', '$1', $tc_text ) ); |
| 925 |
} |
| 926 |
?> |
| 927 |
<div class="leaky-paywall-terms-and-conditions"> |
| 928 |
<label> |
| 929 |
<input type="checkbox" name="terms_and_conditions" value="1" /> |
| 930 |
<?php echo wp_kses( $tc_label, array( 'a' => array( 'href' => array(), 'target' => array() ) ) ); ?> |
| 931 |
</label> |
| 932 |
</div> |
| 933 |
<?php endif; ?> |
| 934 |
|
| 935 |
<?php |
| 936 |
if (0 != $level['price'] && !$one_page_form) { |
| 937 |
?> |
| 938 |
<p> |
| 939 |
<button id="leaky-paywall-registration-next" type="button"><?php esc_html_e('Next', 'leaky-paywall'); ?></button> |
| 940 |
</p> |
| 941 |
<?php |
| 942 |
} |
| 943 |
?> |
| 944 |
|
| 945 |
|
| 946 |
</div> <!-- leaky-paywall-registration-user-container --> |
| 947 |
|
| 948 |
<div class="leaky-paywall-registration-payment-container"> |
| 949 |
|
| 950 |
<?php |
| 951 |
|
| 952 |
if ($gateways && 0 != $level['price']) { |
| 953 |
|
| 954 |
foreach ($gateways as $key => $gateway) { |
| 955 |
|
| 956 |
echo '<input type="hidden" name="gateway" value="' . esc_attr($key) . '" />'; |
| 957 |
} |
| 958 |
} else { |
| 959 |
echo '<input type="hidden" name="gateway" value="free_registration" />'; |
| 960 |
} |
| 961 |
|
| 962 |
?> |
| 963 |
|
| 964 |
<?php |
| 965 |
if ($level['price'] > 0) { |
| 966 |
$total_price = str_replace(',', '', number_format((float) $level['price'], 2)); |
| 967 |
} else { |
| 968 |
$total_price = 0; |
| 969 |
} |
| 970 |
|
| 971 |
if ($total_price > 0) { |
| 972 |
?> |
| 973 |
<h3><?php printf(esc_attr__('Payment Information', 'leaky-paywall')); ?></h3> |
| 974 |
<?php } ?> |
| 975 |
|
| 976 |
<?php |
| 977 |
if (leaky_paywall_get_current_mode() === 'test') { |
| 978 |
?> |
| 979 |
<div class="leaky-paywall-test-mode-wrapper"> |
| 980 |
<p class="leaky-paywall-test-mode-text">The site is currently in test mode.</p> |
| 981 |
<?php |
| 982 |
} |
| 983 |
?> |
| 984 |
|
| 985 |
<?php do_action('leaky_paywall_before_registration_submit_field', $gateways, $level_id); ?> |
| 986 |
|
| 987 |
<?php |
| 988 |
if (leaky_paywall_get_current_mode() === 'test') { |
| 989 |
?> |
| 990 |
</div> |
| 991 |
<?php } ?> |
| 992 |
|
| 993 |
<?php |
| 994 |
// Show terms here only for free levels or one-page forms (otherwise it's already in step 1). |
| 995 |
$tc_settings = get_leaky_paywall_settings(); |
| 996 |
if ( 'on' === $tc_settings['enable_terms_and_conditions'] && ( 0 == $level['price'] || $one_page_form ) ) : |
| 997 |
$tc_text = $tc_settings['terms_and_conditions_text']; |
| 998 |
$tc_page_id = $tc_settings['page_for_terms']; |
| 999 |
|
| 1000 |
if ( $tc_page_id ) { |
| 1001 |
$tc_url = get_permalink( $tc_page_id ); |
| 1002 |
$tc_label = preg_replace( |
| 1003 |
'/\[(.+?)\]/', |
| 1004 |
'<a href="' . esc_url( $tc_url ) . '" target="_blank">$1</a>', |
| 1005 |
esc_html( $tc_text ) |
| 1006 |
); |
| 1007 |
} else { |
| 1008 |
$tc_label = esc_html( preg_replace( '/\[(.+?)\]/', '$1', $tc_text ) ); |
| 1009 |
} |
| 1010 |
?> |
| 1011 |
<div class="leaky-paywall-terms-and-conditions"> |
| 1012 |
<label> |
| 1013 |
<input type="checkbox" name="terms_and_conditions" value="1" /> |
| 1014 |
<?php echo wp_kses( $tc_label, array( 'a' => array( 'href' => array(), 'target' => array() ) ) ); ?> |
| 1015 |
</label> |
| 1016 |
</div> |
| 1017 |
<?php endif; ?> |
| 1018 |
|
| 1019 |
<?php |
| 1020 |
$lp_settings = get_leaky_paywall_settings(); |
| 1021 |
if ( 'on' === $lp_settings['stripe_automatic_tax'] && 'on' === $lp_settings['stripe_billing_address'] ) : ?> |
| 1022 |
<div id="lp-order-summary" style="display: none;"> |
| 1023 |
<div class="lp-order-line lp-order-subtotal"> |
| 1024 |
<span><?php esc_html_e( 'Subtotal', 'leaky-paywall' ); ?></span> |
| 1025 |
<span id="lp-order-subtotal-amount"></span> |
| 1026 |
</div> |
| 1027 |
<div class="lp-order-line lp-order-tax"> |
| 1028 |
<span><?php esc_html_e( 'Tax', 'leaky-paywall' ); ?></span> |
| 1029 |
<span id="lp-order-tax-amount"></span> |
| 1030 |
</div> |
| 1031 |
<div class="lp-order-line lp-order-total"> |
| 1032 |
<span><?php esc_html_e( 'Total', 'leaky-paywall' ); ?></span> |
| 1033 |
<span id="lp-order-total-amount"></span> |
| 1034 |
</div> |
| 1035 |
</div> |
| 1036 |
<?php endif; ?> |
| 1037 |
|
| 1038 |
<div class="leaky-paywall-checkout-button"> |
| 1039 |
<button id="leaky-paywall-submit" type="submit"><?php echo esc_html(leaky_paywall_get_registration_checkout_button_text()); ?></button> |
| 1040 |
</div> |
| 1041 |
|
| 1042 |
<?php do_action('leaky_paywall_after_registration_submit_field', $gateways, $level_id); ?> |
| 1043 |
|
| 1044 |
</div> <!-- .leaky-paywall-registration-payment-container --> |
| 1045 |
|
| 1046 |
<input type="hidden" name="level_price" value="<?php echo esc_attr($total_price); ?>" /> |
| 1047 |
<input type="hidden" name="currency" value="<?php echo esc_attr($currency); ?>" /> |
| 1048 |
<input type="hidden" name="description" value="<?php echo esc_attr($level['label']); ?>" /> |
| 1049 |
<input type="hidden" name="level_id" id="level-id" value="<?php echo esc_attr($level_id); ?>" /> |
| 1050 |
<input type="hidden" name="interval" value="<?php echo esc_attr($level['interval']); ?>" /> |
| 1051 |
<input type="hidden" name="interval_count" value="<?php echo esc_attr($level['interval_count']); ?>" /> |
| 1052 |
<input type="hidden" name="recurring" value="<?php echo empty($level['recurring']) ? '' : esc_attr($level['recurring']); ?>" /> |
| 1053 |
<input type="hidden" name="site" value="<?php echo esc_attr($site); ?>" /> |
| 1054 |
<input type="hidden" name="idem_key" value="<?php echo esc_attr(uniqid()); ?>" /> |
| 1055 |
|
| 1056 |
<input type="hidden" name="leaky_paywall_register_nonce" value="<?php echo esc_attr(wp_create_nonce('leaky-paywall-register-nonce')); ?>" /> |
| 1057 |
|
| 1058 |
</form> |
| 1059 |
|
| 1060 |
<?php |
| 1061 |
if (0 != $level['price'] && !$one_page_form) { |
| 1062 |
?> |
| 1063 |
<style> |
| 1064 |
.leaky-paywall-registration-payment-container { |
| 1065 |
display: none; |
| 1066 |
} |
| 1067 |
</style> |
| 1068 |
<?php |
| 1069 |
} |
| 1070 |
?> |
| 1071 |
|
| 1072 |
<style> |
| 1073 |
#leaky-paywall-registration-errors { |
| 1074 |
display: none; |
| 1075 |
padding: .75rem 1.25rem; |
| 1076 |
margin: 1rem 0; |
| 1077 |
border-radius: .25rem; |
| 1078 |
color: #772b35; |
| 1079 |
background: #fadddd; |
| 1080 |
border: 1px solid #f8cfcf; |
| 1081 |
} |
| 1082 |
|
| 1083 |
#leaky-paywall-registration-errors p { |
| 1084 |
margin: 0; |
| 1085 |
font-size: .75em; |
| 1086 |
} |
| 1087 |
</style> |
| 1088 |
|
| 1089 |
<?php do_action('leaky_paywall_after_registration_form', $gateways); ?> |
| 1090 |
|
| 1091 |
<?php |
| 1092 |
|
| 1093 |
$content = ob_get_contents(); |
| 1094 |
ob_end_clean(); |
| 1095 |
|
| 1096 |
return $content; |
| 1097 |
} |
| 1098 |
add_shortcode('leaky_paywall_register_form', 'do_leaky_paywall_register_form'); |
| 1099 |
|
| 1100 |
/** |
| 1101 |
* Shortcode to show/hide content to an active user, optionally filtered by a comma separated list of level ids |
| 1102 |
* |
| 1103 |
* @since 4.14.6 |
| 1104 |
* |
| 1105 |
* @param array $atts Shortcode attributes. |
| 1106 |
* @param string $content The content. |
| 1107 |
*/ |
| 1108 |
function do_leaky_paywall_subscriber_shortcode($atts, $content = null) |
| 1109 |
{ |
| 1110 |
$a = shortcode_atts( |
| 1111 |
array( |
| 1112 |
'levels' => '', |
| 1113 |
), |
| 1114 |
$atts |
| 1115 |
); |
| 1116 |
|
| 1117 |
if (!is_user_logged_in()) { |
| 1118 |
$content = ''; |
| 1119 |
} |
| 1120 |
|
| 1121 |
$user = wp_get_current_user(); |
| 1122 |
$mode = leaky_paywall_get_current_mode(); |
| 1123 |
$site = leaky_paywall_get_current_site(); |
| 1124 |
|
| 1125 |
if (leaky_paywall_user_can_bypass_paywall_by_role($user)) { |
| 1126 |
return do_shortcode($content); |
| 1127 |
} |
| 1128 |
|
| 1129 |
$level_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id' . $site, true); |
| 1130 |
|
| 1131 |
if (!is_numeric($level_id)) { |
| 1132 |
$content = ''; |
| 1133 |
} |
| 1134 |
|
| 1135 |
if (!leaky_paywall_user_has_access($user)) { |
| 1136 |
$content = ''; |
| 1137 |
} |
| 1138 |
|
| 1139 |
if (!empty($a['levels'])) { |
| 1140 |
|
| 1141 |
$match = false; |
| 1142 |
$shortcode_levels = explode(',', $a['levels']); |
| 1143 |
|
| 1144 |
foreach ($shortcode_levels as $level) { |
| 1145 |
if ($level === $level_id) { |
| 1146 |
$match = true; |
| 1147 |
break; |
| 1148 |
} |
| 1149 |
} |
| 1150 |
|
| 1151 |
if (!$match) { |
| 1152 |
$content = ''; |
| 1153 |
} |
| 1154 |
} |
| 1155 |
|
| 1156 |
return do_shortcode($content); |
| 1157 |
} |
| 1158 |
add_shortcode('leaky_paywall_subscriber', 'do_leaky_paywall_subscriber_shortcode'); |
| 1159 |
|
| 1160 |
|
| 1161 |
/** |
| 1162 |
* Shortcode to show content to a user who isn't an active subscriber |
| 1163 |
* |
| 1164 |
* @param array $atts Shortcode attributes. |
| 1165 |
* @param string $content The content. |
| 1166 |
* @since 4.14.6 |
| 1167 |
* |
| 1168 |
* @return string new content |
| 1169 |
*/ |
| 1170 |
function do_leaky_paywall_not_subscriber_shortcode($atts, $content = null) |
| 1171 |
{ |
| 1172 |
$a = shortcode_atts( |
| 1173 |
array( |
| 1174 |
'levels' => '', |
| 1175 |
), |
| 1176 |
$atts |
| 1177 |
); |
| 1178 |
|
| 1179 |
if (!is_user_logged_in()) { |
| 1180 |
return do_shortcode( $content ); |
| 1181 |
} |
| 1182 |
|
| 1183 |
$user = wp_get_current_user(); |
| 1184 |
$mode = leaky_paywall_get_current_mode(); |
| 1185 |
$site = leaky_paywall_get_current_site(); |
| 1186 |
|
| 1187 |
$level_id = get_user_meta($user->ID, '_issuem_leaky_paywall_' . $mode . '_level_id' . $site, true); |
| 1188 |
|
| 1189 |
|
| 1190 |
if (leaky_paywall_user_can_bypass_paywall_by_role($user)) { |
| 1191 |
return; |
| 1192 |
} |
| 1193 |
|
| 1194 |
if (!is_numeric($level_id)) { |
| 1195 |
return do_shortcode( $content ); |
| 1196 |
} |
| 1197 |
|
| 1198 |
if (!leaky_paywall_user_has_access($user)) { |
| 1199 |
return do_shortcode( $content ); |
| 1200 |
} |
| 1201 |
|
| 1202 |
if (!empty($a['levels'])) { |
| 1203 |
|
| 1204 |
$match = false; |
| 1205 |
$shortcode_levels = explode(',', $a['levels']); |
| 1206 |
|
| 1207 |
foreach ($shortcode_levels as $level) { |
| 1208 |
if ($level === $level_id) { |
| 1209 |
$match = true; |
| 1210 |
break; |
| 1211 |
} |
| 1212 |
} |
| 1213 |
|
| 1214 |
if ($match) { |
| 1215 |
return do_shortcode($content); |
| 1216 |
} |
| 1217 |
} |
| 1218 |
} |
| 1219 |
|
| 1220 |
add_shortcode('leaky_paywall_not_subscriber', 'do_leaky_paywall_not_subscriber_shortcode'); |
| 1221 |
|
| 1222 |
/** |
| 1223 |
* Profile Editor Shortcode |
| 1224 |
* |
| 1225 |
* Outputs the Leaky Paywall Profile Editor to allow users to amend their details from the |
| 1226 |
* front-end. |
| 1227 |
* |
| 1228 |
* @since 4.14.5 |
| 1229 |
* |
| 1230 |
* @param array $atts Shortcode attributes. |
| 1231 |
* @param string $content The content. |
| 1232 |
* @return string Output generated from the profile editor |
| 1233 |
*/ |
| 1234 |
function leaky_paywall_account_shortcode($atts, $content = null) |
| 1235 |
{ |
| 1236 |
ob_start(); |
| 1237 |
|
| 1238 |
if (is_user_logged_in()) { |
| 1239 |
leaky_paywall_get_template('shortcode-account.php'); |
| 1240 |
} else { |
| 1241 |
echo do_shortcode('[leaky_paywall_login]'); |
| 1242 |
} |
| 1243 |
|
| 1244 |
$display = ob_get_clean(); |
| 1245 |
|
| 1246 |
return $display; |
| 1247 |
} |
| 1248 |
add_shortcode('leaky_paywall_account', 'leaky_paywall_account_shortcode'); |
| 1249 |
|
| 1250 |
|
| 1251 |
/** |
| 1252 |
* Process a user editing their profile |
| 1253 |
* |
| 1254 |
* @since 4.14.5 |
| 1255 |
* @throws Exception The exception message. |
| 1256 |
*/ |
| 1257 |
function leaky_paywall_process_profile_edit() |
| 1258 |
{ |
| 1259 |
if ( |
| 1260 |
!isset($_POST['leaky_paywall_profile_edit_nonce']) |
| 1261 |
|| !wp_verify_nonce(sanitize_key($_POST['leaky_paywall_profile_edit_nonce']), 'leaky_paywall_profile_edit') |
| 1262 |
) { |
| 1263 |
return; |
| 1264 |
} |
| 1265 |
|
| 1266 |
$user = wp_get_current_user(); |
| 1267 |
|
| 1268 |
try { |
| 1269 |
|
| 1270 |
$args = array( |
| 1271 |
'ID' => $user->ID, |
| 1272 |
'user_login' => $user->user_login, |
| 1273 |
'display_name' => $user->display_name, |
| 1274 |
'user_email' => $user->user_email, |
| 1275 |
); |
| 1276 |
|
| 1277 |
if (isset($_POST['displayname'])) { |
| 1278 |
$args['display_name'] = sanitize_text_field(wp_unslash($_POST['displayname'])); |
| 1279 |
} |
| 1280 |
|
| 1281 |
if (isset($_POST['firstname'])) { |
| 1282 |
$args['first_name'] = sanitize_text_field(wp_unslash($_POST['firstname'])); |
| 1283 |
} |
| 1284 |
|
| 1285 |
if (isset($_POST['lastname'])) { |
| 1286 |
$args['last_name'] = sanitize_text_field(wp_unslash($_POST['lastname'])); |
| 1287 |
} |
| 1288 |
|
| 1289 |
if (isset($_POST['email'])) { |
| 1290 |
if (is_email(wp_unslash($_POST['email']))) { |
| 1291 |
$args['user_email'] = sanitize_email(wp_unslash($_POST['email'])); |
| 1292 |
} else { |
| 1293 |
throw new Exception(__('Invalid email address.', 'leaky-paywall')); |
| 1294 |
} |
| 1295 |
} |
| 1296 |
|
| 1297 |
if (!empty($_POST['password1']) && !empty($_POST['password2'])) { |
| 1298 |
if ($_POST['password1'] === $_POST['password2']) { |
| 1299 |
wp_set_password(sanitize_text_field(wp_unslash($_POST['password1'])), $user->ID); |
| 1300 |
} else { |
| 1301 |
throw new Exception(__('Passwords do not match.', 'leaky-paywall')); |
| 1302 |
} |
| 1303 |
} |
| 1304 |
|
| 1305 |
$userdata = get_userdata($user->ID); |
| 1306 |
$user_id = wp_update_user($args); |
| 1307 |
|
| 1308 |
if (is_wp_error($user_id)) { |
| 1309 |
throw new Exception($user_id->get_error_message()); |
| 1310 |
} else { |
| 1311 |
$user = get_userdata($user_id); |
| 1312 |
do_action('leaky_paywall_after_profile_changes_saved', $user_id, $args, $userdata); |
| 1313 |
|
| 1314 |
if ( $userdata->user_email !== $args['user_email'] ) { |
| 1315 |
do_action( 'leaky_paywall_subscriber_email_changed', $user_id, $userdata->user_email, $args['user_email'] ); |
| 1316 |
} |
| 1317 |
} |
| 1318 |
} catch (Exception $e) { |
| 1319 |
$results = '<div class="leaky_paywall_message error"><p class="error">' . $e->getMessage() . '</p></div>'; |
| 1320 |
} |
| 1321 |
|
| 1322 |
$referrer = isset($_POST['_wp_http_referer']) ? esc_url_raw(wp_unslash($_POST['_wp_http_referer'])) : ''; |
| 1323 |
|
| 1324 |
wp_safe_redirect(home_url() . $referrer); |
| 1325 |
exit(); |
| 1326 |
} |
| 1327 |
add_action('init', 'leaky_paywall_process_profile_edit'); |
| 1328 |
|