我正试图在wordpress上创建一个更好的登录和注册表单。我安装了杰夫的TML,它工作得很好。然而,我正在尝试进一步扩展注册表。我添加了wordpress显示的“first\\u name”和“last\\u name”,但由于某种原因,似乎update\\u user\\u meta没有保存任何内容。
这是我在这两个方面使用的代码fields Fname and Lname
<div class="tml-user-first-last-name-wrap" style="margin-bottom: 25px;">
<span style="width:50%; padding-left: 25px; padding-right: 1px; float:left;"><input type="text" placeholder="First Name" name="first_name" id="first_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( \'first_name\' ); ?>" size="20" />
<label for="first_name<?php $template->the_instance(); ?>"><?php _e( \'\', \'theme-my-login\' ) ?></label>
</span>
<span style="width:50%; padding-left: 1px; padding-right: 25px; float:right;"><input type="text" placeholder="Last Name" name="last_name" id="last_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( \'last_name\' ); ?>" size="20" />
<label for="last_name<?php $template->the_instance(); ?>"><?php _e( \'\', \'theme-my-login\' ) ?></label>
</span>
<br>
</div>
除此之外,我还必须将此文件添加到wp内容/插件/主题我的登录自定义中。php
function tml_registration_errors( $errors ) {
if ( empty( $_POST[\'first_name\'] ) )
$errors->add( \'empty_first_name\', \'<strong>ERROR</strong>: Please enter your first name.\' );
if ( empty( $_POST[\'last_name\'] ) )
$errors->add( \'empty_last_name\', \'<strong>ERROR</strong>: Please enter your last name.\' );
return $errors;
}
add_filter( \'registration_errors\', \'tml_registration_errors\' );
function tml_user_register( $user_id ) {
if ( !empty( $_POST[\'first_name\'] ) )
update_user_meta( $user_id, \'first_name\', $_POST[\'first_name\'] );
if ( !empty( $_POST[\'last_name\'] ) )
update_user_meta( $user_id, \'last_name\', $_POST[\'last_name\'] );
}
add_action( \'user_register\', \'tml_user_register\' );
除此之外,我还尝试了可用的wordpress默认表单
here.
我不知所措,因为我不知道自己做错了什么。。有什么想法吗?