Support » Plugin: WP-Members Membership Plugin » Hide WP-Members Additional Fields

  • Resolved svacontact

    (@svacontact)


    I’m using the WP_Members form for requesting new logins. I have specified some fields to be included using the Add a Field area which map back (through the meta tag) to existing custom user profile fields. This works great, but the fields get duplicated in the WP-Members Additional Fields section of User Profiles using the Field Label. This creates a field with duplicate data but a different label. Can this be prevented?

    Ideally, I would like to hide the entire WP-Members Additional Fields section of the User Profile if possible. Sorry if this has already been asked. I did search.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    It sounds like you’re talking about having integrated more than one plugin that applies custom fields to the user profile (such as WooCommerce) and you’ve got the WP-Members fields matched up with whatever that is so you need to eliminate that?

    If that’s the case, there currently not a great way to remove that. I am in the process of moving all action/filter hooks into the appropriate class files where they are loaded when the class initiates. However, the user profile piece is still part of the file (/admin/user-profile.php). Removing those actions with remove_action() does not currently do it.

    You could remove the following from /admin/user-profile.php to remove these fields from being added:

    add_action( 'show_user_profile', 'wpmem_admin_fields' );
    add_action( 'edit_user_profile', 'wpmem_admin_fields' );
    add_action( 'profile_update',    'wpmem_admin_update' );

    HOWEVER, it’s important to point out this is UNOFFICIAL and UNSUPPORTED!

    I never recommend editing the core files directly. In this case, I’m suggesting that might hold you over until the add_action() for these are added to the admin class, at which point you could remove them with this:

    add_action( 'wpmem_after_admin_init', function(){
    	remove_action( 'show_user_profile', 'wpmem_admin_fields' );
    	remove_action( 'edit_user_profile', 'wpmem_admin_fields' );
    	remove_action( 'profile_update',    'wpmem_admin_update' );
    });

    But all of that is speculative and untested.

    Thanks a lot. Your assessment is correct. I used a csv importer to import 20+ fields from existing user data. The importer adds additional metadata for each field name. One of those fields is the members Lot/Unit number which is linked back through a meta-tag to the ‘request new member login’ form. All of the fields included on the ‘request new member login’ form are also displayed in the Member’s profile page, so many fields are duplicated. What I don’t want to happen is to have two fields that reference the same metadata on the user’s Profile page! Since they can have different labels, this really confuses members regarding which one(s) to edit. What I ended up doing (which seems to work) is implementing filters for profile and user-edit as follows:

    add_action('admin_footer-profile.php', 'remove_profile_fields');
    function remove_profile_fields()
    {
        if(!current_user_can('administrator'))
        { ?>
            <script type="text/javascript">
                jQuery("h3:contains('WP-Members Additional Fields')").next('.form-table').remove();
                jQuery("h3:contains('WP-Members Additional Fields')").remove();
         	    jQuery("h3:contains('Additional Information')").next('.form-table').remove();
                jQuery("h3:contains('Additional Information')").remove();
            </script>
    <?php }
    }
    
    // Remove Extra Information from Edit User Profiles for non admin
    add_action('admin_footer-user-edit.php', 'remove_extra_profile_fields');
    function remove_extra_profile_fields()
    {
        if(!current_user_can('administrator'))
        { ?>
            <script type="text/javascript">
                jQuery("h3:contains('WP-Members Additional Fields')").next('.form-table').remove();
                jQuery("h3:contains('WP-Members Additional Fields')").remove();
         	    jQuery("h3:contains('Additional Information')").next('.form-table').remove();
                jQuery("h3:contains('Additional Information')").remove();
            </script>
    <?php }
    }

    Admins still see all fields in case any issues arise, but all other roles do not. This removes any confusion for members about which fields can/should be edited. I realize this might be somewhat brittle (use of h3), but it works. Do you see any other issues? Thanks again for the reply.

    • This reply was modified 1 year, 4 months ago by  svacontact.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide WP-Members Additional Fields’ is closed to new replies.