heading. * @return array */ public function add_column( $columns ) { $columns[ self::COLUMN ] = __( 'Registered', 'adminkeep' ); return $columns; } /** * Sort through the orderby WP_User_Query already understands. * * The second element is the first-click direction: descending, because the newest accounts * are the ones worth looking at. * * @param array $sortable Column key => sort definition. * @return array */ public function make_sortable( $sortable ) { $sortable[ self::COLUMN ] = array( 'registered', true ); return $sortable; } /** * The cell: the date, with the full moment on hover. * * @param string $output Output so far. * @param string $column Column key. * @param int $user_id User id. * @return string */ public function render_cell( $output, $column, $user_id ) { if ( self::COLUMN !== $column ) { return $output; } $user = get_userdata( $user_id ); // user_registered is stored in UTC. Some importers leave a zero date behind. $timestamp = $user ? strtotime( $user->user_registered . ' UTC' ) : false; if ( false === $timestamp || $timestamp <= 0 ) { return '—'; } $date_format = get_option( 'date_format' ); return sprintf( '%2$s', esc_attr( wp_date( $date_format . ' ' . get_option( 'time_format' ), $timestamp ) ), esc_html( wp_date( self::short_date_format( $date_format ), $timestamp ) ) ); } /** * Keep the column as wide as a date. * * The users table is table-layout: fixed, so a column with no width takes an equal share of * what is left, and max-width does nothing there. Attached to a stylesheet core already * prints on this screen rather than shipping a file for one rule. * * @param string $hook_suffix Current admin page. * @return void */ public function enqueue_style( $hook_suffix ) { if ( 'users.php' !== $hook_suffix ) { return; } wp_add_inline_style( 'list-tables', '.fixed .column-' . self::COLUMN . '{width:120px}' ); } /** * The site's date format with the month name shortened. * * Swapping the one character rather than imposing a format keeps a site's chosen order, * d/m/Y included. A backslash-escaped F is a literal letter, not a month, and is left alone. * * @param string $format A PHP date format. * @return string */ public static function short_date_format( $format ) { return (string) preg_replace( '/(?