WP_Posts_List_Table::column_date( WP_Post $post )

In this article

Handles the post date column output.

Parameters

$postWP_Postrequired
The current WP_Post object.

Source

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 );
}

Hooks

apply_filters( ‘post_date_column_status’, string $status, WP_Post $post, string $column_name, string $mode )

Filters the status text of the post.

apply_filters( ‘post_date_column_time’, string $t_time, WP_Post $post, string $column_name, string $mode )

Filters the published, scheduled, or unpublished time of the post.

Changelog

VersionDescription
4.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.