使用主题我的登录和自定义域更新用户元

时间:2018-05-14 作者:nateb2127

我正试图在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.

我不知所措,因为我不知道自己做错了什么。。有什么想法吗?

1 个回复
SO网友:nateb2127

好消息是它不是会员资格插件,好消息是它是W3总缓存。我已经强制该网站不缓存注册页面,但它似乎仍然不起作用。

更新:我知道它是什么:我忘了告诉w3tc不要缓存:主题我的登录自定义。php

结束

相关推荐

Using $variable in shortcode

我将使用函数外部的$变量。在shortcode函数中。这就是我要做的:function shortcodevariable( $atts ){ return \'echo $variable\'; } add_shortcode(\'variable\', \'shortcodevariable\'); 我想我们需要一个阵列,但我现在不需要,有人能帮忙吗?非常感谢你。