Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User Fields Incorrectly Marked as Required During Checkout Despite Being Unset Using pmpro_required_user_fields Filter #3165

Open
3 tasks done
oarie opened this issue Oct 15, 2024 · 1 comment

Comments

@oarie
Copy link

oarie commented Oct 15, 2024

Describe the bug
When using the pmpro_required_user_fields filter to unset required fields (such as username, password, and password2) on the checkout page, the corresponding pmpro_form_input-required class and the asterisk (pmpro_asterisk) indicating a required field are still applied in the HTML output. This behavior differs from the handling of billing fields (e.g., bphone, bzipcode), where the required status is correctly removed when using the pmpro_required_billing_fields filter.

To Reproduce
Steps to reproduce the behavior:

  1. Add the following code to your theme or plugin to unset username and password fields as required:

add_filter('pmpro_required_user_fields', 'custom_remove_required_user_fields', 10, 1);
function custom_remove_required_user_fields($required_fields) {
unset($pmpro_required_user_fields['username']);
unset($pmpro_required_user_fields['password']);
unset($pmpro_required_user_fields['password2']);
return $pmpro_required_user_fields;
}

  1. Go to the PMPro checkout page.
  2. Inspect the HTML output for the username and password fields.
  3. Despite the fields being unset as required, the pmpro_form_input-required class and asterisk are still present, marking the fields as required.
  4. Submitting the form with these fields empty results in successful submission, but the fields are falsely marked as required in the UI.

Expected behavior
When a field is unset using the pmpro_required_user_fields filter, the following should happen:

The pmpro_form_input-required class should be removed from the username and password fields.
The asterisk (pmpro_asterisk) indicating a required field should not appear.
The aria-required="true" attribute should be removed from these fields as well.
Currently, this works as expected for billing fields like bphone and bzipcode when using the pmpro_required_billing_fields filter, but not for user fields like username, password, and password2.

This block of code around line 152 in the file paid-memberships-pro/js/pmpro-checkout.js is responsible for incorrectly adding the required field asterisks to the fields which are no longer required:

    jQuery('.pmpro_form_field-required').each(function() {
            // Check if there's an asterisk already
            var $firstLabel = jQuery(this).find('.pmpro_form_label').first();
            var $hasAsterisk = $firstLabel.find('.pmpro_asterisk').length > 0;

            // If there's no asterisk, add one
            if ( ! $hasAsterisk ) {
                    $firstLabel.append('<span class="pmpro_asterisk"> <abbr title="Required Field">*</abbr></span>');
            }

            // Add the aria-required="true" attribute to the input.
            jQuery(this).find('.pmpro_form_input').attr('aria-required', 'true');
    });

Isolating the problem (mark completed items with an [x]):

  • I have deactivated other plugins and confirmed this bug occurs when only Paid Memberships Pro plugin is active.
  • This bug happens with a default WordPress theme active, or Memberlite.
  • I can reproduce this bug consistently using the steps above.

WordPress Environment
Wordpress 6.6.2
PHP 8.0
PMPro 3.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@oarie and others