【问题标题】:WordPress $user-ID Return always 1WordPress $user-ID 总是返回 1
【发布时间】:2017-06-17 11:51:30
【问题描述】:

我使用此代码在 wp 中为管理员和订阅者提供支持的每个用户配置文件显示用户注册日期。

add_action( 'show_user_profile', 'display_user_custom' );
add_action( 'edit_user_profile', 'display_user_custom' );

function display_user_custom( $user ) { ?>
    <h3>Registration</h3>
    <table class="form-table">
        <tr>
            <th><label>Registered Since</label></th>
            <td><?php $udata = get_userdata( $user-ID );
$registered = $udata->user_registered; echo date( "d M Y", strtotime( $registered ) ); ?></td>
        </tr>
    </table>
    <?php
}

它可以工作,但日期始终来自用户 ID 1,$user-ID 始终为 1。我已经“在私人浏览器中”使用多个帐户登录进行了测试。

【问题讨论】:

    标签: wordpress date account


    【解决方案1】:

    固定为:

    <td><?php $udata = get_usermeta($user->ID, 'user_registered'); echo date( "d M Y", strtotime( $udata ) ); ?></td>
    

    【讨论】:

      猜你喜欢
      • 2013-12-15
      • 2016-02-28
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-21
      • 2019-10-10
      • 2014-04-13
      相关资源
      最近更新 更多