Skip to content

Instantly share code, notes, and snippets.

@maiconschmitz
Created April 21, 2012 21:39
Show Gist options
  • Save maiconschmitz/2439786 to your computer and use it in GitHub Desktop.
Save maiconschmitz/2439786 to your computer and use it in GitHub Desktop.
Adicionando campos extras ao profile do usuário no WordPress
<?php
add_action('show_user_profile', 'extra_fields_to_user');
add_action('edit_user_profile', 'extra_fields_to_user');
function extra_fields_to_user($user) {
?>
<h3>Redes Sociais</h3>
<table class="form-table">
<tr>
<th><label for="facebook">Facebook</label></th>
<td><input type="text" name="facebook" id="facebook" value="<?php echo esc_attr(get_the_author_meta('facebook', $user->ID)); ?>" class="regular-text" /> <span class="description">Entre com o link completo do seu Facebook, iniciando com http://</span></td>
</tr>
<tr>
<th><label for="twitter">Twitter</label></th>
<td><input type="text" name="twitter" id="twitter" value="<?php echo esc_attr(get_the_author_meta('twitter', $user->ID)); ?>" class="regular-text" /> <span class="description">Entre apenas com o usuário do seu Twitter, não utilize @</span></td>
</tr>
<tr>
<th><label for="linkedin">Linkedin</label></th>
<td><input type="text" name="linkedin" id="linkedin" value="<?php echo esc_attr(get_the_author_meta('linkedin', $user->ID)); ?>" class="regular-text" /> <span class="description">Entre com o link completo do seu Linkedin, iniciando com http://</span></td>
</tr>
</table>
<?php
}
add_action('personal_options_update', 'extra_fields_to_user_save');
add_action('edit_user_profile_update', 'extra_fields_to_user_save');
function extra_fields_to_user_save($user_id)
{
if (!current_user_can('edit_user', $user_id))
return false;
/* Campos a serem salvos */
update_usermeta($user_id, 'facebook', $_POST['facebook']);
update_usermeta($user_id, 'twitter', $_POST['twitter']);
update_usermeta($user_id, 'linkedin', $_POST['linkedin']);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment