Adding custom user meta to the user profile

<?php
class ee_user_meta {

function ee_user_meta() {
if ( is_admin() )
{
add_action('show_user_profile', array(&$this,'action_show_user_profile'));
add_action('edit_user_profile', array(&$this,'action_show_user_profile'));
add_action('personal_options_update', array(&$this,'action_process_option_update'));
add_action('edit_user_profile_update', array(&$this,'action_process_option_update'));
}

}

function action_show_user_profile($user)
{
?>
<h3><?php _e('Other Contact Info') ?></h3>

<table>
<tr>
<th><label for="something"><?php _e('Something else'); ?></label></th>
<td>
<input type="checkbox" name="guest_author" value="guest_author" <?php if(get_the_author_meta('guest_author', $user->ID)=='guest_author') echo 'checked'; ?> /> Guest Author<br />
<input type="text" name="something" id="something" value="<?php echo esc_attr(get_the_author_meta('something', $user->ID) ); ?>" />
</td>
</tr>
</table>
<?php
}

function action_process_option_update($user_id)
{
update_usermeta($user_id, 'guest_author', ( isset($_POST['guest_author']) ? $_POST['guest_author'] : '' ) );
update_usermeta($user_id, 'something', ( isset($_POST['something']) ? $_POST['something'] : '' ) );
}
}
/* Initialise outselves */
add_action('plugins_loaded', create_function('','global $ee_user_meta_instance; $ee_user_meta_instance = new ee_user_meta();'));
?>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s