php – 在WordPress注册表单中添加名字和姓氏
发布时间:2020-12-13 16:59:35 所属栏目:PHP教程 来源:网络整理
导读:我在WP上的注册表只有用户名,电子邮件和密码选项. //1. firstname add_action(‘register_form’,’myplugin_register_form’); function myplugin_register_form(){ $first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : '
我在WP上的注册表只有用户名,电子邮件和密码选项.
//1. firstname add_action(‘register_form’,’myplugin_register_form’); $first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : ''; ?> <?php } //2. Add validation. In this case,we make sure first_name is required. add_filter( 'registration_errors','myplugin_registration_errors',10,3 ); function myplugin_registration_errors( $errors,$sanitized_user_login,$user_email ) { if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) == '' ) { $errors->add( 'first_name_error',__( '<strong>ERROR</strong>: You must include a first name.','mydomain' ) ); } return $errors; } //3. Finally,save our extra registration user meta. add_action( 'user_register','myplugin_user_register' ); function myplugin_user_register( $user_id ) { if ( ! empty( $_POST['first_name'] ) ) { update_user_meta( $user_id,'first_name',trim( $_POST['first_name'] ) ); } } 在我的注册表(模板)中,我放置了以下内容: <label><?php _e('First Name',APP_TD) ?></label> <input tabindex="3" type="text" name="first_name" class="text regular-text" id="display_name" value="<?php echo esc_attr( wp_unslash( $first_name ) ); ?>" maxlength="100" /> 它的工作原理应该如此.它抓取名字并将其放在用户配置文件中.但是我不知道如何将姓氏添加到它,我是一个初学者,由于某种原因我无法得到姓氏.非常感谢帮助. 解决方法
我从来没有在WP上做过类似的事情.你把这个代码放在哪里?
但是我会尝试执行这样的事情: //1. Fistname add_action( 'register_form','myplugin_register_form' ); function myplugin_register_form() { $first_name = ( ! empty( $_POST['first_name'] ) ) ? trim( $_POST['first_name'] ) : ''; $last_name = ( ! empty( $_POST['last_name'] ) ) ? trim( $_POST['last_name'] ) : ''; ?> <?php } //2. Add validation. In this case,$user_email ) { if ( empty( $_POST['first_name'] ) || ! empty( $_POST['first_name'] ) && trim( $_POST['first_name'] ) == '' ) { $errors->add( 'first_name_error','mydomain' ) ); } if ( empty( $_POST['last_name'] ) || ! empty( $_POST['last_name'] ) && trim( $_POST['last_name'] ) == '' ) { $errors->add( 'last_name_error',__( '<strong>ERROR</strong>: You must include a last name.',trim( $_POST['first_name'] )); } if ( ! empty( $_POST['last_name'] ) ) { update_user_meta( $user_id,'last_name',trim( $_POST['last_name'] ) ); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |