Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3120,39 +3120,44 @@
$(document).on(
"user_registration_frontend_validate_before_form_submit",
function (e, $form) {
var stripe_selected = false;
$('input[name="urm_payment_method"]:visible').each(
function () {
if (
$(this).val() === "stripe" &&
$(this).is(":checked")
) {
stripe_selected = true;
}
}
// Detect Stripe by presence of a visible card container — works
// even when there is only one payment method and no radio button.
var $stripeContainer = $form.find(
".stripe-input-container"
);
// console.log('[URM Stripe Debug] stripe_selected:', stripe_selected, '| stripe_mode_validated:', stripe_mode_validated, '| elements.card:', !!elements.card, '| elements.stripe:', !!elements.stripe);
if (!stripe_selected) return;
if (
!$stripeContainer.length ||
!$stripeContainer.is(":visible")
) {
return;
}

if (stripe_mode_validated) {
return;
}

if (stripe_mode_validated) return;
// Remove any stale error label from a previous attempt.
$form.find("#stripe-errors.user-registration-error").remove();

var stripeEmpty = $(".ur-frontend-form").find(
".stripe-input-container .StripeElement--empty"
var stripeEmpty = $stripeContainer.find(
".StripeElement--empty"
).length;
// console.log('[URM Stripe Debug] elements.card:', !!elements.card, '| StripeElement--empty found:', stripeEmpty);
if (
!elements ||
!elements.stripe ||
!elements.card ||
stripeEmpty
) {
// console.log('[URM Stripe Debug] Early return — skipping pre-validation');

if (stripeEmpty) {
// Show inline label directly in the form — no dependency on
// stripe_settings or $membership_registration_form.
$stripeContainer.append(
'<label id="stripe-errors" class="user-registration-error" role="alert">' +
urmf_data.labels.i18n_empty_card_details +
"</label>"
);
return;
}

stripe_settings.show_stripe_error(
urmf_data.labels.i18n_validating_stripe_card
);
// Card has content: run async API validation.
if (!elements || !elements.stripe || !elements.card) {
return;
}

elements.stripe
.createPaymentMethod({
Expand All @@ -3161,22 +3166,23 @@
})
.then(function (pmResult) {
if (pmResult.error) {
stripe_settings.show_stripe_error(
pmResult.error.message
);
$form
.find("#stripe-errors")
.text(pmResult.error.message);
return;
}

$.post(
urmf_data.ajax_url,
{
action: "user_registration_membership_validate_stripe_card_mode",
_nonce: urmf_data._nonce,
payment_method_id: pmResult.paymentMethod.id
security: urmf_data._nonce,
payment_method_id:
pmResult.paymentMethod.id
},
function (response) {
if (response.success) {
$membership_registration_form
$form
.find("#stripe-errors")
.remove();
validated_stripe_pm_id =
Expand All @@ -3189,13 +3195,15 @@
$form.submit();
}
} else {
stripe_settings.show_stripe_error(
response.data &&
response.data.message
? response.data.message
: urmf_data.labels
.i18n_stripe_mode_error
);
$form
.find("#stripe-errors")
.text(
response.data &&
response.data.message
? response.data.message
: urmf_data.labels
.i18n_stripe_mode_error
);
}
}
);
Expand Down Expand Up @@ -3853,6 +3861,16 @@
.not(seatInput)
.prop("disabled", true);
});

// If Stripe is already selected on page load, initialize it so elements.card
// is ready before the first submit attempt.
var $initialMethod = $('input[name="urm_payment_method"]:checked');
if ($initialMethod.length && $initialMethod.val() === "stripe") {
if (!elements || !elements.card) {
$(".stripe-container").removeClass("urm-d-none");
stripe_settings.init();
}
}
},
validateSwitchCurrency: function (paymentMethod) {
var $select = $("#ur-local-currency-switch-currency");
Expand Down
21 changes: 21 additions & 0 deletions modules/membership/includes/Frontend/Frontend.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

Check failure on line 1 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Class file names should be based on the class name with "class-" prepended. Expected class-frontend.php, but found Frontend.php.

Check failure on line 1 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Filenames should be all lowercase with hyphens as word separators. Expected frontend.php, but found Frontend.php.
/**
* URMembership Frontend.
*
* @class Frontend
* @package URMembership/Frontend
* @category Frontend

Check failure on line 7 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

@category is deprecated, use @Package instead
* @author WPEverest

Check failure on line 8 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

@author tags are prohibited
*/

namespace WPEverest\URMembership\Frontend;
Expand Down Expand Up @@ -37,12 +37,33 @@
*/
private function init_hooks() {
add_action( 'wp_enqueue_membership_scripts', array( $this, 'load_scripts' ), 10, 2 );
add_action( 'user_registration_enqueue_scripts', array( $this, 'maybe_load_scripts_for_form' ), 10, 2 );

add_action( 'template_redirect', array( $this, 'set_thank_you_transient' ) );
add_action( 'wp_loaded', array( $this, 'clear_upgrade_data' ) );
add_action( 'user_registration_before_register_user_action', array( $this, 'validate_stripe_card_before_register' ), 10, 2 );
}

public function maybe_load_scripts_for_form( $form_data_array, $form_id ) {

Check failure on line 47 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Missing doc comment for function maybe_load_scripts_for_form()
if ( wp_script_is( 'user-registration-membership-frontend-script', 'enqueued' ) ) {
return;
}
if ( empty( $form_data_array ) || ! is_iterable( $form_data_array ) ) {
return;
}
foreach ( $form_data_array as $row ) {
foreach ( $row as $grid ) {
foreach ( $grid as $field ) {
$field_key = isset( $field->field_key ) ? $field->field_key : '';
if ( 'membership' === $field_key ) {
$this->load_scripts();
return;
}
}
}
}
}

/**
* Delete Account insert after helper.
*
Expand All @@ -63,7 +84,7 @@
return $return_items;
}

/**

Check failure on line 87 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Doc comment for parameter "$membership_data" missing
* Membership tab content.
*/
public function user_registration_membership_tab_endpoint_content( $membership_data ) {
Expand All @@ -74,10 +95,10 @@

$current_page = 1;

if ( isset( $_GET['paged'] ) && intval( $_GET['paged'] ) > 0 ) {

Check warning on line 98 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Processing form data without nonce verification.

Check warning on line 98 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Processing form data without nonce verification.
$current_page = intval( $_GET['paged'] );

Check warning on line 99 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Processing form data without nonce verification.
} else {
$request_path = trim( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ), '/' );

Check failure on line 101 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Detected usage of a non-sanitized input variable: $_SERVER['REQUEST_URI']

Check failure on line 101 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar

Check failure on line 101 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Detected usage of a possibly undefined superglobal array index: $_SERVER['REQUEST_URI']. Use isset() or empty() to check the index exists before using it

Check warning on line 101 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

parse_url() is discouraged because of inconsistency in the output across PHP versions; use wp_parse_url() instead.
$segments = explode( '/', $request_path );

$page_index = array_search( 'page', $segments );
Expand Down Expand Up @@ -131,7 +152,7 @@
wp_enqueue_script( 'sweetalert2' );

wp_register_script( 'user-registration-membership-frontend-script', UR()->plugin_url() . '/assets/js/modules/membership/frontend/user-registration-membership-frontend' . $suffix . '.js', array( 'jquery' ), UR_VERSION, true );
wp_enqueue_script( 'user-registration-membership-stripe-v3', 'https://js.stripe.com/v3/', array() );

Check failure on line 155 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Resource version not set in call to wp_enqueue_script(). This means new versions of the script will not always be loaded due to browser caching.

Check warning on line 155 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

In footer ($in_footer) is not set explicitly wp_enqueue_script; It is recommended to load scripts in the footer. Please set this value to `true` to load it in the footer, or explicitly `false` if it should be loaded in the header.
wp_enqueue_script( 'user-registration-membership-frontend-script' );
// Enqueue frontend styles here.
wp_register_style( 'user-registration-membership-frontend-style', UR()->plugin_url() . '/assets/css/modules/membership/user-registration-membership-frontend.css', array(), UR_VERSION );
Expand Down Expand Up @@ -204,7 +225,7 @@
'membership_gateways' => get_option( 'ur_membership_payment_gateways', array() ),
'urm_hide_stripe_card_postal_code' => apply_filters( 'user_registration_membership_disable_stripe_card_postal_code', false ),
'gateways_configured' => urm_get_all_active_payment_gateways( 'paid' ),
'isEditor' => current_user_can( 'edit_post', get_the_ID() ) && isset( $_GET['action'] ) && 'edit' === $_GET['action'],

Check warning on line 228 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Processing form data without nonce verification.

Check warning on line 228 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Processing form data without nonce verification.
'membership_selection_message' => __( 'Please select at least one membership plan', 'user-registration' ),
'tax_calculation_method' => ur_string_to_bool( $tax_calculation_method ),
'regions_list' => $regions,
Expand Down Expand Up @@ -266,10 +287,10 @@
}

public function set_thank_you_transient() {
if ( ! isset( $_GET['urm_uuid'] ) || ! isset( $_GET['thank_you'] ) ) {

Check warning on line 290 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Processing form data without nonce verification.

Check warning on line 290 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Processing form data without nonce verification.
return;
}
$uuid = $_GET['urm_uuid'] ? sanitize_text_field( $_GET['urm_uuid'] ) : ur_get_random_number();

Check warning on line 293 in modules/membership/includes/Frontend/Frontend.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4, WP Latest)

Processing form data without nonce verification.
$transient_id = "uuid_{$uuid}_thank_you";
delete_transient( $transient_id );
$thank_you_page = get_permalink( absint( $_GET['thank_you'] ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,13 @@ class="ur_membership_frontend_input_container urm-d-none urm_hidden_payment_cont
</span>
</div>
<?php endif; ?>
<?php if ( $is_coupon_addon_activated || $is_tax_calculation_enabled ) :; ?>
<?php if ( $is_coupon_addon_activated || $is_tax_calculation_enabled ) : ?>
<hr class="ur_membership_divider urm-pre-total-divider" style="display:none;">
<?php endif; ?>
<div class="urm-membership-total-value">
<label class="ur_membership_input_label ur-label"
for="ur-membership-total"><?php echo apply_filters( 'user_registration_membership_subscription_payment_gateway_total', esc_html__( 'Total', 'user-registration' ) ); ?></label>
<span class="ur_membership_input_class"
id="ur-membership-total"
data-key-name="<?php echo apply_filters( 'user_registration_membership_subscription_payment_gateway_total', esc_html__( 'Total', 'user-registration' ) ); ?>"
disabled
Expand Down
Loading