Created
July 18, 2012 18:36
-
-
Save javifr/3137957 to your computer and use it in GitHub Desktop.
Theme My Login - Helpers!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
// Añadimos un campo llamado user_telephone | |
- ojo al if(!is_admin ) | |
- ojo en que fichero se meten las líneas de códigon ( tenemos tres ficheros ) | |
- dependencia del plugin Theme My Login | |
*/ | |
// ********************************************************* | |
// Para functions.php | |
// ********************************************************* | |
add_action( 'show_user_profile', 'my_show_extra_profile_fields' ); | |
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' ); | |
function my_show_extra_profile_fields( $user ) { ?> | |
<?php | |
// Está linea solo si hemos añadido ya los campos vía el profile-form de Theme-My-Login y queremos que no se vuelvan a añadir los campos | |
//if(!is_admin()) return; | |
?> | |
<h3>Extra profile information</h3> | |
<table class="form-table"> | |
<tr> | |
<th><label for="user_telephone">Telephone</label></th> | |
<td> | |
<input type="text" name="user_telephone" id="user_telephone" value="<?php echo esc_attr( get_the_author_meta( 'user_telephone', $user->ID ) ); ?>" class="regular-text" /><br /> | |
<span class="description">Please enter your telephone number.</span> | |
</td> | |
</tr> | |
</table> | |
<?php } | |
add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); | |
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); | |
function my_save_extra_profile_fields( $user_id ) { | |
if ( !current_user_can( 'edit_user', $user_id ) ) | |
return false; | |
// echo "UFCK!";exit; | |
//echo $_POST['user_telephone']; exit; | |
/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */ | |
update_user_meta( $user_id, 'user_telephone', $_POST['user_telephone'] ); | |
} | |
// ********************************************************* | |
// Para theme-my-login-custom.php ( en la raiz del plugin ) | |
// ********************************************************* | |
function tml_registration_errors( $errors ) { | |
if ( empty( $_POST['user_telephone'] ) ) | |
$errors->add( 'empty_user_telephone', '<strong>ERROR</strong>: Please enter your user_telephone.' ); | |
return $errors; | |
} | |
add_filter( 'registration_errors', 'tml_registration_errors' ); | |
function tml_user_register( $user_id ) { | |
if ( !empty( $_POST['user_telephone'] ) ) | |
update_user_meta( $user_id, 'user_telephone', $_POST['user_telephone'] ); | |
} | |
add_action( 'user_register', 'tml_user_register' ); | |
// ********************************************************* | |
// Para profile-form.php ( en el caso de que no queramos añadir el campo vía hooks ) | |
// ********************************************************* | |
?> | |
<p> | |
<label for="user_telephone<?php $template->the_instance(); ?>"><?php _e( 'Telephone', 'theme-my-login' ) ?></label> | |
<input type="text" name="user_telephone" id="user_telephone<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'user_telephone' ); ?>" size="20" tabindex="20" /> | |
</p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment