Adding Properties to User Profile and Displaying in List

To answer the first part of your question, I have just put my class TTT_User_Profile_Addon on GitHub. The class offers a simple interface to add a field to a profile page. I have added an example for a checkbox subclass and some code to initialize it per functions.php. This works in a plugin too, of course.

There are some build in placeholders, but you can add your own. Separate filters for the markup and input values make extending the class easier.

You can set custom capabilities for showing and saving the fields per constructor call. The whole work is reduced to a simple init function:

add_action( 'init', 'ttt_init_profile_addons' );

/**
 * Registers the extra fields for the user profile editor.
 */
function ttt_init_profile_addons()
{
    $GLOBALS['ttt_show_profile'] = new TTT_User_Profile_Checkbox(
        array (
            'name' => 'ttt_show_profile'
        ,   'label' => 'Show a short profile box on my posts.'
        ,   'th' => ''
        ,   'td' => '<input type="checkbox" name="%name%" id="%id%" %checked% /> %label%'
        ,   'cap_show' => 'edit_posts'
        ,   'cap_save' => 'edit_users'
        )
    );
    // add more fields here …
}

Adding the values to the member table is something I still have on my todo list …

Oh, and I should probably mention another class to replace or extend the default contact fields: TTT_Contactfields. This may be a case of OOP overdone. 🙂

Leave a Comment