Comment ajouter des champs de formulaire personnalisés à la page de profil utilisateur?
2 réponses
- votes
-
- 2010-11-14
Vous devez utiliser le
'show_user_profile'
,'edit_user_profile'
,'personal_options_update'
et'edit_user_profile_update'
crochets.Voici un codepour ajouter unnuméro detéléphone :
add_action ('show_user_profile','yoursite_extra_user_profile_fields'); add_action ('edit_user_profile','yoursite_extra_user_profile_fields'); function yoursite_extra_user_profile_fields ($ user) { ? > & lt; h3 > & lt;?php _e ("Informations supplémentaires sur leprofil","vide");? > & lt;/h3 > & lt;table class="formulaire-table" > & lt;tr > & lt;th > & lt; labelfor="phone" > & lt;?php _e ("Phone");? > & lt;/étiquette > & lt;/th > & lt;td > & lt;inputtype="text"name="phone"id="phone" class="regular-text" value="& lt;?phpechoesc_attr (get_the_author_meta ('phone',$ user- > ID));? >"/> & lt;br/> & lt; span class="description" > & lt;?php _e ("Veuillezentrer votretéléphone.");? > & lt;/span > & lt;/td > & lt;/tr > & lt;/table > & lt;?php } add_action ('personal_options_update','yoursite_save_extra_user_profile_fields'); add_action ('edit_user_profile_update','yoursite_save_extra_user_profile_fields'); function yoursite_save_extra_user_profile_fields ($ user_id) { $ sauvé=faux; if (current_user_can ('edit_user',$ user_id)) { update_user_meta ($ user_id,'phone',$ _POST ['phone']); $ sauvé=vrai; } retourne vrai; }
Ce code ajoutera un champ à votre écran utilisateur qui ressemble à ceci:
Ilexiste égalementplusieurs articles deblog disponibles sur le sujet quipourraient être utiles:
- Ajoutet utilisation champs deprofil utilisateurpersonnalisés
- Ajout de champs supplémentaires à WordPress Profil utilisateur
Ou si vouspréférezne pas rouler vous-même,ilexiste desplugins qui ajoutent desfonctionnalitéstelles que les suivantes (même sije suis sûr qu'il yen a d'autres):
You need to use the
'show_user_profile'
,'edit_user_profile'
,'personal_options_update'
and'edit_user_profile_update'
hooks.Here's some code to add a Phone number:
add_action( 'show_user_profile', 'yoursite_extra_user_profile_fields' ); add_action( 'edit_user_profile', 'yoursite_extra_user_profile_fields' ); function yoursite_extra_user_profile_fields( $user ) { ?> <h3><?php _e("Extra profile information", "blank"); ?></h3> <table class="form-table"> <tr> <th><label for="phone"><?php _e("Phone"); ?></label></th> <td> <input type="text" name="phone" id="phone" class="regular-text" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" /><br /> <span class="description"><?php _e("Please enter your phone."); ?></span> </td> </tr> </table> <?php } add_action( 'personal_options_update', 'yoursite_save_extra_user_profile_fields' ); add_action( 'edit_user_profile_update', 'yoursite_save_extra_user_profile_fields' ); function yoursite_save_extra_user_profile_fields( $user_id ) { $saved = false; if ( current_user_can( 'edit_user', $user_id ) ) { update_user_meta( $user_id, 'phone', $_POST['phone'] ); $saved = true; } return true; }
That code will add a field to your user screen that looks something like this:
There are also several blog posts available on the subject that might be helpful:
Or if you prefer not to roll-your-own there are plugins that add said features such as the following (although I'm sure there are others):
-
Mike,j'ai rencontré untas deproblèmespourenregistrermesmodifications.Je l'aifinalement cloué quandj'aifait un "find and replace" complet.Pourmafuture référence,les champs «nom»et «titre» doivent-ils correspondreexactement?Mike, I ran into a bunch of trouble get my modifications to save. I finally nailed it when I did a complete "find and replace". For my future reference, are the "name" and "title" fields required to be an exact match?
- 0
- 2011-03-28
- Jonathan Wold
-
@Jonathan Wold - * "Les champs"nom "et"titre "sont-ils obligatoirespour correspondreexactement?" * Vousne m'avezpas donné suffisamment de contextepour queje sache comment répondre.Et vous voudrezpeut-être créer [unenouvelle question complète] (http://wordpress.stackexchange.com/questions/ask).@Jonathan Wold - *"are the "name" and "title" fields required to be an exact match?"* You didn't give me enough context for me to know how to aswer. And you may want to create [a complete new question](http://wordpress.stackexchange.com/questions/ask).
- 0
- 2011-03-29
- MikeSchinkel
-
@MikeSchinkel Cimy User Extra Fieldsn'estpas unebonne recommandation.Le supportn'estpas vraiment làet le codeest ... hm.@MikeSchinkel Cimy User Extra Fields is imo no good recommendation. Support isn't really there and the code is ... hm.
- 1
- 2011-08-25
- kaiser
-
- 2010-12-01
// remove aim, jabber, yim function hide_profile_fields( $contactmethods ) { unset($contactmethods['aim']); unset($contactmethods['jabber']); unset($contactmethods['yim']); return $contactmethods; } // add anything else function my_new_contactmethods( $contactmethods ) { //add Birthday $contactmethods['birthday'] = 'Birthday'; //add Address $contactmethods['address'] = 'Address'; //add City $contactmethods['city'] = 'City'; //add State $contactmethods['state'] = 'State'; //add Postcode $contactmethods['postcode'] = 'Postcode'; //add Phone $contactmethods['phone'] = 'Phone'; //add Mobilphone $contactmethods['mphone'] = 'Mobilphone'; return $contactmethods; } add_filter('user_contactmethods','my_new_contactmethods',10,1); add_filter('user_contactmethods','hide_profile_fields',10,1);
J'espère que cela vous aidera.
Source: WPBeginner
// remove aim, jabber, yim function hide_profile_fields( $contactmethods ) { unset($contactmethods['aim']); unset($contactmethods['jabber']); unset($contactmethods['yim']); return $contactmethods; } // add anything else function my_new_contactmethods( $contactmethods ) { //add Birthday $contactmethods['birthday'] = 'Birthday'; //add Address $contactmethods['address'] = 'Address'; //add City $contactmethods['city'] = 'City'; //add State $contactmethods['state'] = 'State'; //add Postcode $contactmethods['postcode'] = 'Postcode'; //add Phone $contactmethods['phone'] = 'Phone'; //add Mobilphone $contactmethods['mphone'] = 'Mobilphone'; return $contactmethods; } add_filter('user_contactmethods','my_new_contactmethods',10,1); add_filter('user_contactmethods','hide_profile_fields',10,1);
Hope this helps.
Source: WPBeginner
Lapage deprofil utilisateur contient les champs suivants:
Nom d'utilisateur
Prénom
Nom
Surnom Afficher unnom Informations de contact Email Site Internet OBJECTIF Yahoo IM
Jabber/Google Talk
Comment ajouter d'autres champs à cette section.Champtel quenuméro detéléphone,adresse ou autre.