• Hey guys,
    I’ve been researching this for a while, and what I want to do is add some occupational fields into the About Yourself section of the edit profile form.

    Updating contact methods is a breeze as seen here..

    Is there something similar to this to modify or add fields to other sections of the edit profile form? I’ve only found hooks for “near the top of the profile page”, ‘before the name’, ‘after the toolbar’ etc.

    I’m looking for an easy and non-obstrusive way to add fields to the About Yourself Section, ideally before the ‘bio’, but definitely before the change password fields.

    Any amount of direction would be helpful at this point.

    Also, want to mention that I don’t want to use a plugin or JS if I don’t have to, but if I’m backed into a corner…well, I may have to.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I find it amazing that the documentation for this particular area is lacking so much. This is what I found out which I guess the same as you figured out based on your question.

    We can easily add fields to the contact info like so

    //modify contact info
    function modify_contact_methods($profile_fields) {
    
    	// Field addition and removal will be done here
                $profile_fields['facebook'] = 'Facebook Address';
    
    	    return $profile_fields;
    }
    add_filter('user_contactmethods', 'modify_contact_methods');

    If we want to add fields to the about yourself section and not in an additonal section we have to do dum hackery like:

    function move_shit_around() {
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function($) {
                field = $('#custom_user_field').remove();
                field.insertBefore('#password');
            });
        </script>
        <?php
    }
    add_action( 'admin_head', 'move_shit_around' );

    I found some action hooks but I have not been able to get them to work properly: https://codex.www.ads-software.com/Plugin_API/Action_Reference/show_user_profile

    also the section is incomplete. If you can make it work please share since I am on the lookout for the same solution as you. Filters and hooks no hacks!

    So my solution so far is this. NOTE that it uses jquery to move stuff around. And while it works the custom profile field is always empty, Even though the content is saved ??

    functions.php

    //modify about yourself
    function add_custom_user_profile_fields( $user ) {
    ?>
        <table id="custom_user_field_table" class="form-table">
            <tr id="custom_user_field_row">
                <th>
                    <label for="specs"><?php _e('Anl?gsspecifikationer', 'your_textdomain'); ?></label>
                </th>
                <td>
                    <textarea rows="5" name="specs" id="specs" value="<?php echo esc_attr( get_the_author_meta( 'specs', $user->ID ) ); ?>" class="regular-text" ></textarea><br />
                    <span class="description"><?php _e('Share your sound system specs here', 'your_textdomain'); ?></span>
                </td>
            </tr>
        </table>
    <?php
    }
    add_action( 'show_user_profile', 'add_custom_user_profile_fields' );
    add_action( 'edit_user_profile', 'add_custom_user_profile_fields' );
    
    function move_shit() {
        $screen = get_current_screen();
        if ( $screen->id != "profile" && $screen->id != "user-edit" )
            return;
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function($) {
                field = $('#custom_user_field_row').remove();
                field.insertBefore('#password');
            });
        </script>
        <?php
    }
    add_action( 'admin_head', 'move_shit' );
    
    add_action('edit_user_profile', 'add_extra_profile_fields');
    
    add_action('show_user_profile', 'add_extra_profile_fields');
    
    //////////
    function fb_save_custom_user_profile_fields( $user_id ) {
    
    	if ( !current_user_can( 'edit_user', $user_id ) )
    		return FALSE;
    
    	update_usermeta( $user_id, 'specs', $_POST['specs'] );
    }
    
    add_action( 'show_user_profile', 'fb_add_custom_user_profile_fields' );
    add_action( 'edit_user_profile', 'fb_add_custom_user_profile_fields' );
    
    add_action( 'personal_options_update', 'fb_save_custom_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'fb_save_custom_user_profile_fields' );
    ////////////

    then in the theme add (ie. author.php)

    <?php $profileStuff = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); ?>
    <?php echo $profileStuff->specs; ?>

    Change this

    <textarea rows="5" name="specs" id="specs" value="<?php echo esc_attr( get_the_author_meta( 'specs', $user->ID ) ); ?>" class="regular-text" ></textarea><br />

    to this

    <textarea rows="5" name="specs" id="specs" class="regular-text" ><?php echo esc_attr( get_the_author_meta( 'specs', $user->ID ) ); ?></textarea><br />

    because textarea does not have a value field. It is held between the <textarea></textarea>

    Now it all works but yeah, still with the minor jquery hack to move it to the right location

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hook in custom fields in 'about yourself' for edit user profile page’ is closed to new replies.