Support » Plugins » Hacks » Custom add user fields

  • What I want is to add custom user fields in the add user screen in the administrator page. I don’t need to allow this information to be changed by the users as they are for control purposes, like for example suscription end date and similar.
    I found several ways of “Editing” the user’s information, but nothing solid for user creation.

    All i could remove/add from the “user add” page was the contact methods with this code that i found on a blog post and i can’t credit because i already lost the page:

    function remove_contact_method( $contact_method ) {
    	// Add Twitter
    	$contact_method['twitter'] = 'Twitter';
    	// Remove Yahoo IM
    	unset( $contact_method['yim'] );
    	unset( $contact_method['aim'] );
    	unset( $contact_method['jabber'] );
    	return $contact_method;
    add_filter( 'user_contactmethods', 'remove_contact_method', 10, 1 );

    Now, I found a way to “pseudo-hack” the “add user” page, i tried to use the code but i didn’t understand it very well:

    function adduser_new_fields() {
    	if ( !current_user_can( 'add_users' ) )
    		return true;
    	$html = '
    	<th><label for="user_address">Direcci&oacute;n</label></th>
    	<td><input type="text" name="user_address" id="company" value="" class="regular-text"></td>
    	echo "
    <script type='text/javascript'>
    jQuery( function() {
    	if ( jQuery( '#createuser #role' ).length) {
    		jQuery( '#role' ).parent().parent().parent().after('"; echo $html; echo "');
    add_action('admin_head', 'adduser_new_fields');
    function adduser_save( $user_id ) {
    	if ( !current_user_can( 'add_users' ) )
    		return false;
    	update_usermeta( $user_id, 'user_address', $_POST['user_address'] );
    add_action( 'user_register', 'adduser_save' );

    Well, I hope someone can understand what I want to do and probably give me a hand with it.

  • The topic ‘Custom add user fields’ is closed to new replies.