WordPress.org

Forums

amr users
[resolved] Unix timestamp to human date (7 posts)

  1. elurie
    Member
    Posted 1 year ago #

    hi anmari,
    The expire-users plugin I am using gives the User's renew date as a unix timestamp in mySql:
    _expire_user_date
    1403457801
    The expire-users Plugin translates this date into human date in Dashboard>Users>All Users. It also translates this unix date into human date in the Edit User Profile. But, your user lists show the date as the unix date. How can I show this date as a human date in amusers plugin?

    http://wordpress.org/extend/plugins/amr-users/

  2. anmari
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Eve,
    you could write a formatting function (plugin will pick it up it the naming standards are followed for the field) for that field.
    You could have it call the expire-users function (or use the same code if they don't have a callable function) so that it formats exactly the same.

    Or check my plugins pluggables file, there should be a formatting function you can call from the one that does the field.

    do not edit plugin files (will lose it when you upgrade), rather add it to site specific plugin as per instructions.

    instructions here
    http://wpusersplugin.com/2823/formatting-and-pluggable-functions/

  3. elurie
    Member
    Posted 1 year ago #

    hi anmari,
    I've tried something like this, but it does not seem to work:

    function ausers_format_expire_user_date ($expire_user) {
    return $expire_user->get_expire_date_display();
    }

    my question in particular is; what is the argument of the function supposed to be? Is it as I have it, $expire_user or something else?
    many thanks,
    eve

  4. elurie
    Member
    Posted 1 year ago #

    sorry,
    i did not mention:
    I am trying to reference the expir-users plugin's function called get_expire_date_display.

  5. anmari
    Member
    Plugin Author

    Posted 1 year ago #

    Hi eve,

    see here or any of the formatting functions in the pluggables file

    http://wpusersplugin.com/2645/format-any-field-any-way-you-wish/

    2 parameters, first is the value, second is the wp user being processed (if needed)
    I don't know whether your $expire_user is a wp user or not, you'd have to work that part out yourself.

    or do something like (untested)

    function ausers_format_timestamp_as_date($v) {
    		if (empty($v)) return ('');
    		$d = date('Y-m-d H:i:s e', (int) $v) ;
    		if (!$d) {
    			return($v);  // not a valid date just return the value
    			}
    		else return ($d->format('l, j M Y h:i a e' );	// or whatever format string you want
    	}
  6. elurie
    Member
    Posted 1 year ago #

    hi anmari,
    thank you, this worked! (there is a second underscore between format and expire.)

    function ausers_format__expire_user_date ($expire_user) {
    if (empty($expire_user)) return '';
    return date('m/d/Y',$expire_user);
    }

  7. anmari
    Member
    Plugin Author

    Posted 1 year ago #

    Glad it's working.
    Looks like your 'expire_user' is actually 'expiry_date' ?

    Good idea to name more meaningfully so when you come back to it later it will be less confusing.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • amr users
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic