Php 在Wordpress中保存前端用户注册表中的所有字段
我在functions.php中有下面的代码,它注册了用户的用户名和电子邮件地址,但我似乎无法在Wordpress的后端获得保存用户配置文件中其他字段的表单(城市、电话和访问字段存在于后端,因为我添加了它们) 有人向我推荐了这个URL来帮助我:但是我想要一些关于这段代码放在哪里的指导。我试过自己的代码,但它不工作,所以我一定是做错了什么 我还希望获得在WP Admin>Users中添加的名为“access”的额外字段的帮助,这是一个复选框-即使我手动进入后端并勾选它并保存页面,该框也会恢复为未选中状态Php 在Wordpress中保存前端用户注册表中的所有字段,php,wordpress,frontend,user-registration,Php,Wordpress,Frontend,User Registration,我在functions.php中有下面的代码,它注册了用户的用户名和电子邮件地址,但我似乎无法在Wordpress的后端获得保存用户配置文件中其他字段的表单(城市、电话和访问字段存在于后端,因为我添加了它们) 有人向我推荐了这个URL来帮助我:但是我想要一些关于这段代码放在哪里的指导。我试过自己的代码,但它不工作,所以我一定是做错了什么 我还希望获得在WP Admin>Users中添加的名为“access”的额外字段的帮助,这是一个复选框-即使我手动进入后端并勾选它并保存页面,该框也会恢复为未选
<form method="post" action="<?php echo wp_registration_url(); ?>">
<div class="firstname">
<label for="first_name"><?php _e( 'First Name', 'mydomain' ) ?></label>
<input type="text" name="first_name" id="first_name" class="input" value=""/>
</div>
<div class="lastname">
<label for="last_name"><?php _e( 'Last Name', 'mydomain' ) ?></label>
<input type="text" name="last_name" id="last_name" class="input" value=""/>
</div>
<div class="username">
<label for="user_login_register"><?php esc_html_e('Username', 'mydomain'); ?></label>
<input name="user_login" id="user_login_register" type="text" value="">
</div>
<div class="password">
<label for="user_email"><?php esc_html_e('Your Email', 'mydomain'); ?></label>
<input name="user_email" id="user_email" type="text" value="">
</div>
<div class="city">
<label for="city"><?php _e( 'City', 'mydomain' ) ?></label>
<input type="text" name="city" id="city" class="input" value=""/>
</div>
<div class="phone">
<label for="phone"><?php _e( 'Phone Number', 'mydomain' ) ?></label>
<input type="text" name="phone" id="phone" class="input" value=""/>
</div>
<div class="access">
<label for="access"><?php _e( 'Give access', 'mydomain' ) ?></label>
<input type="checkbox" name="access" id="access" class="input" value=""/>
</div>
<div class="login_fields">
<input type="submit" name="user-submit" value="Sign up!" class="user-submit">
<input type="hidden" name="redirect_to" value="<?php echo $redirect_register; ?>">
<input type="hidden" name="user-cookie" value="1">
<?php do_action('register_form'); ?>
</div>
</form>
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) { ?>
<h3><?php _e("Dream journal user information", "blank"); ?></h3>
<table class="form-table">
<tr>
<th><label for="city"><?php _e("City"); ?></label></th>
<td>
<input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
<tr>
<th><label for="phone"><?php _e("Phone number"); ?></label></th>
<td>
<input type="text" name="phone" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
<tr>
<th><label for="access"><?php _e("Grant access"); ?></label></th>
<td>
<input type="checkbox" name="access" id="access" value="<?php echo esc_attr( get_the_author_meta( 'access', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_user_meta( $user_id, 'city', $_POST['city'] );
update_user_meta( $user_id, 'phone', $_POST['phone'] );
update_user_meta( $user_id, 'access', $_POST['access'] );
}