您可以在wp-admin中为用户添加额外的用户字段.
在functions.PHP或插件文件夹中使用它:
原文链接:https://www.f2er.com/php/134710.html在functions.PHP或插件文件夹中使用它:
//extra user info in wp-admin 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="company"><?PHP _e("Company"); ?></label></th> <td> <input type="text" name="company" id="company" class="regular-text" value="<?PHP echo esc_attr( get_the_author_Meta( 'company',$user->ID ) ); ?>" /><br /> </td> </tr> <tr> <th><label for="job"><?PHP _e("Job"); ?></label></th> <td> <input type="text" name="job" id="job" class="regular-text" value="<?PHP echo esc_attr( get_the_author_Meta( 'job',$user->ID ) ); ?>" /><br /> </td> </tr> <tr> <th><label for="country"><?PHP _e("Country"); ?></label></th> <td> <input type="text" name="country" id="country" class="regular-text" value="<?PHP echo esc_attr( get_the_author_Meta( 'country',$user->ID ) ); ?>" /><br /> </td> </tr> <tr> <th><label for="city"><?PHP _e("City"); ?></label></th> <td> <input type="text" name="city" id="city" class="regular-text" value="<?PHP echo esc_attr( get_the_author_Meta( 'city',$user->ID ) ); ?>" /><br /> </td> </tr> <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 /> </td> </tr> </table> <?PHP }
之后,您必须在wp-admin中进行编辑时保存字段
//Save our extra registration user Meta. add_action('user_register','myplugin_user_register'); function myplugin_user_register ($user_id) { if ( isset( $_POST['phone'] ) ) update_user_Meta($user_id,'phone',$_POST['phone']); if ( isset( $_POST['company'] ) ) update_user_Meta($user_id,'company',$_POST['company']); if ( isset( $_POST['job'] ) ) update_user_Meta($user_id,'job',$_POST['job']); if ( isset( $_POST['country'] ) ) update_user_Meta($user_id,'country',$_POST['country']); if ( isset( $_POST['city'] ) ) update_user_Meta($user_id,'city',$_POST['city']); if ( isset( $_POST['user_interest'] ) ) update_user_Meta($user_id,'user_interest',$_POST['user_interest']); }
在那之后,在前端,你当然可以使用wp_insert_user(); function和wp_update_user();使用您创建的所有自定义字段注册和编辑用户.