Search code examples
wordpressdateaccount

WordPress $user-ID Return always 1


Im use this code to show user registration date for each user profile in wp backed for admin and subscriber.

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
}

And it work but the date is always from user ID 1 and $user-ID its always 1. I have tested with multiples account login "in private browser".


Solution

  • Fixed with:

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