can you add custom profile fields ot the membership2 plugin?

I am just setting up a site to use the Membership2 Pro plugin and want to add sevearal custom profile fields - I added the Profile Fields add-on for this but it seems that this doesn't allow for creating new fields .... am I missing something?

  • Jude
    • DEV MAN

    Hey there @Michael

    Hope you are doing great !!

    The best way to this is

    1) Use a custom form during sign up and collect all the extra profile fields data. This gist shows you how to do this

    Simply put your shortcode / form code instead of the gravity forms one.

    2) To display the fields after the profile for your members, please use this filter.

    do_action( 'ms_view_frontend_profile_after_fields' );

    Simply echo the profile data after this point.


    • Kurt
      • Flash Drive

      Jude , thanks for sharing this action hook - exactly what I was looking for.

      I know there are a lot of threads on this -- in case anyone else is looking for a functions.php code solution to adding profile fields into both the wordpress registration form and the membership profile edit form, here is full code that is working for me. It's not ideal - the field shows up after the "Save Changes" button, and while there's validation for the field on the register page there isn't validation on the profile page. Sidebar - do you know what action hook would work for that a la registration_errors?

      But here it is in case it will help any one else. Adding to the wordpress registration is code from the wordpress codex, and the code for the profile page is adapted from this thread on the forum.

      //1. Add a new form element...
      add_action( 'register_form', 'myplugin_register_form' );
      function myplugin_register_form() {
          $kjorganization = ( ! empty( $_POST['kjorganization'] ) ) ? trim( $_POST['kjorganization'] ) : '';
                  <label for="kjorganization"><?php _e( 'Organization', 'mydomain' ) ?><br />
                      <input type="text" name="kjorganization" id="kjorganization" class="input" value="<?php echo esc_attr( wp_unslash( $kjorganization ) ); ?>" size="25" /></label>
          //2. Add validation. In this case, we make sure first_name is required.
          add_filter( 'registration_errors', 'myplugin_registration_errors', 10, 3 );
          function myplugin_registration_errors( $errors, $sanitized_user_login, $user_email ) {
              if ( empty( $_POST['kjorganization'] ) || ! empty( $_POST['kjorganization'] ) && trim( $_POST['kjorganization'] ) == '' ) {
                  $errors->add( 'kjorganization_error', __( '<strong>ERROR</strong>: You must include an organization.', 'mydomain' ) );
              return $errors;
          //3. Finally, save our extra registration user meta.
          add_action( 'user_register', 'myplugin_user_register' );
          function myplugin_user_register( $user_id ) {
              if ( ! empty( $_POST['kjorganization'] ) ) {
                  update_user_meta( $user_id, 'kjorganization', trim( $_POST['kjorganization'] ) );
      //add field to profile edit page
      add_action( 'ms_view_frontend_profile_after_fields', 'kj_custom_user_profile_fields' );
      function kj_custom_user_profile_fields() {
      	$kjorganization = isset($_POST['kjorganization']) ? $_POST['kjorganization'] : get_user_meta(get_current_user_id(), 'kjorganization', true);
                  <label for="kjorganization"><?php _e( 'Organization', 'mydomain' ); ?><br />
                      <input type="text" name="kjorganization" id="kjorganization" class="input" value="<?php echo $kjorganization ?>"/>
      //save profile update data
      add_action('profile_update', 'myplugin_profile_update');
      function myplugin_profile_update($user_id)
      	$kjorganization = isset($_POST['kjorganization']) ? $_POST['kjorganization'] : null;
          if (!empty($kjorganization))
              update_user_meta($user_id, 'kjorganization', $kjorganization);
  • Michael Bissett
    • Recruit

    Hey @Michael,

    Just so you're aware, if you're open to giving BuddyPress a shot, you can create custom fields via BuddyPress's Extended Profiles module, and have those displayed on Membership 2 Pro's registration form.

    As you create profile fields inside of:

    Users -> Profile Fields

    You'll be able to see & configure the display of them inside of the Profile Fields add-on in Membership 2 Pro.

    Anyhow, hope you're doing well today! :slight_smile:

    Kind Regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.