When you add user fields to membership checkout, the checkout process is blocked until all required fields are completed. We handle user fields a bit differently on the frontend user profile screen, where PMPro does not block the form from updating if required fields are missed.

If you must require fields on the frontend profile screen, you need the custom code in this recipe. This code hooks into the form submission using the pmpro_user_profile_update_errors hook to require specific fields before saving. The code also adds to the error message shown on form submission failure.

Require User Fields on the Member Profile Edit Page

About the Code Recipe

If you must require fields on the frontend profile edit page, this code can be used to select certain fields to block the profile from updating.

We recommend membership sites use this code with caution. We made the decision to always allow profiles to update, regardless of field requirements, so that any other profile field the user may have changed would not be missed or lost on save.

Screenshot of the edit user frontend profile page with error message when the first name field is missing.

When using this code, the user profile will not be updated if there are any field errors. This means that all submission data is cleared out and the form, with error message, will instead show all previous form values.

Note: This code does not restrict profile or user update in the WordPress admin area (on the Edit User or Your Profile screen).

The Code Recipe (PHP)

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

Update or duplicate lines 19 to 22 to check for your specific user field names (meta key). You can also customize the error message shown when the field is empty.

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics
Was this article helpful?
YesNo