WP_Posts_List_Table::column_date()publicWP 4.3.0

Handles the post date column output.

Method of the class: WP_Posts_List_Table{}

Return

null. Nothing (null).

Usage

$WP_Posts_List_Table = new WP_Posts_List_Table();
$WP_Posts_List_Table->column_date( $post );
$post(WP_Post) (required)
The current WP_Post object.

Notes

  • Global. String. $mode List table view mode.

Changelog

Since 4.3.0 Introduced.

WP_Posts_List_Table::column_date() code WP 6.4.3

public function column_date( $post ) {
	global $mode;

	if ( '0000-00-00 00:00:00' === $post->post_date ) {
		$t_time    = __( 'Unpublished' );
		$time_diff = 0;
	} else {
		$t_time = sprintf(
			/* translators: 1: Post date, 2: Post time. */
			__( '%1$s at %2$s' ),
			/* translators: Post date format. See https://www.php.net/manual/datetime.format.php */
			get_the_time( __( 'Y/m/d' ), $post ),
			/* translators: Post time format. See https://www.php.net/manual/datetime.format.php */
			get_the_time( __( 'g:i a' ), $post )
		);

		$time      = get_post_timestamp( $post );
		$time_diff = time() - $time;
	}

	if ( 'publish' === $post->post_status ) {
		$status = __( 'Published' );
	} elseif ( 'future' === $post->post_status ) {
		if ( $time_diff > 0 ) {
			$status = '<strong class="error-message">' . __( 'Missed schedule' ) . '</strong>';
		} else {
			$status = __( 'Scheduled' );
		}
	} else {
		$status = __( 'Last Modified' );
	}

	/**
	 * Filters the status text of the post.
	 *
	 * @since 4.8.0
	 *
	 * @param string  $status      The status text.
	 * @param WP_Post $post        Post object.
	 * @param string  $column_name The column name.
	 * @param string  $mode        The list display mode ('excerpt' or 'list').
	 */
	$status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );

	if ( $status ) {
		echo $status . '<br />';
	}

	/**
	 * Filters the published, scheduled, or unpublished time of the post.
	 *
	 * @since 2.5.1
	 * @since 5.5.0 Removed the difference between 'excerpt' and 'list' modes.
	 *              The published time and date are both displayed now,
	 *              which is equivalent to the previous 'excerpt' mode.
	 *
	 * @param string  $t_time      The published time.
	 * @param WP_Post $post        Post object.
	 * @param string  $column_name The column name.
	 * @param string  $mode        The list display mode ('excerpt' or 'list').
	 */
	echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
}