微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Wordpress中保存前端用户注册表单中的所有字段

如何解决在Wordpress中保存前端用户注册表单中的所有字段

我在 functions.PHP 中具有以下代码,该代码用于注册用户用户名和电子邮件地址,但是我似乎无法获得将后端中的其他字段保存到用户配置文件中的表格的wordpress(因为我添加了城市,电话和访问权限的字段在后端中存在)。

有人建议我使用以下URL来帮助我:https://wordpress.stackexchange.com/questions/261387/how-to-add-first-name-last-name-to-default-registration-form,但我希望获得有关该代码内容的指导。我已经尝试过使用代码,但是它不起作用,因此我必须做错了什么。

我还希望获得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>   

仅供参考,使用以下代码将额外的字段添加到WP Admin> Users中:

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'] );
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?