php – 如何使用wordpress上的自定义字段为前端用户创建编辑个人
发布时间:2020-12-13 18:08:33 所属栏目:PHP教程 来源:网络整理
导读:如何使用wordpress上的自定义字段为前端用户创建编辑个人资料页面?我尝试使用配置文件构建器插件,但无法插入自定义字段,如性别广播框等. 您可以在wp-admin中为用户添加额外的用户字段. 在functions.php或插件文件夹中使用它: //extra user info in wp-admi
如何使用wordpress上的自定义字段为前端用户创建编辑个人资料页面?我尝试使用配置文件构建器插件,但无法插入自定义字段,如性别广播框等.
您可以在wp-admin中为用户添加额外的用户字段.
在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();使用您创建的所有自定义字段注册和编辑用户. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |