Support

Account

Home Forums Feature Requests Add extra fields to user_contactmethods

Solving

Add extra fields to user_contactmethods

  • Hi, it would be nice if it was possible to add extra fields to the user in the user_contactmethods section.
    https://developer.wordpress.org/reference/hooks/user_contactmethods/

  • You’re going to need to give more information. WP supplies a filter for adding more, the one that you linked to and a function for getting them https://developer.wordpress.org/reference/functions/wp_get_user_contact_methods/

  • Alright sure. For instance, I have this function I usually use on my sites:

    add_filter( 'user_contactmethods', function( $contactmethods ) {
    
    	$contactmethods['company_name'] = __( 'Company' );
    	$contactmethods['address'] = __( 'Address' );
    	$contactmethods['zip'] = __( 'Postal code' );
    	$contactmethods['city'] = __( 'City' );
    	$contactmethods['phone'] = __( 'Phone' );
    
    	return $contactmethods;
    
    }, 10, 1 );

    However, there was a website where I need a calendar for the birthday field. So I added such a field to the user edit page in the controlpanel with ACF. However, the birthday field was situated far down the page, all by itself. It would have been so much more user-friendly, if it was up the page, together with the other contact fields. Does that make sense? 🙂
    Please let me know if I should elaborate further 😉

    Regards Vayu

  • It is the difference between adding to existing WP fields and adding new fields. WP does not have any mechanism for adding additional fields anywhere except where the ACF field groups appear, at the bottom of the profile page.

    ACF adds fields on the show_user_profile or the edit_user_profile hook.

    The only way to add them elsewhere would be to edit the WP files themselves.

  • Okay, but it’s possible to do with the show_user_profile or the edit_user_profile and user_contactmethods hook. This is just a feature request. I thought maybe this would be a nice little enhancement to ACF 😉

  • Those are the hooks that ACF uses to show the fields on the page. They only allow the fields to be shown where they are shown. They cannot be use to put the fields in any other location. Those hooks happen at exactly one location.

    Yes, it would be great to put them somewhere else, but it is not possible to do so using what WP makes available. You can’t simply insert new fields anywhere on that page. See the file wp-admin/user-edit.php

  • Alright John no problem, maybe I am not quite understanding it, because it is obviously possible to do so. But if ACF does not work that way then that is fine. It was only a suggestion. Now I know. 😉

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.