_post_states

Advertisement

Summery Summery

Function to echo or return the post states as HTML.

Syntax Syntax

_post_states( WP_Post $post, bool $echo = true )

Parameters Parameters

$post

(Required) The post to retrieve states for.

$echo

(Optional) Whether to echo the post states as an HTML string.

Default value: true

Return Return

(string) Post states string.

Source Source

File: wp-admin/includes/template.php

function _post_states( $post, $echo = true ) {
	$post_states        = get_post_states( $post );
	$post_states_string = '';

	if ( ! empty( $post_states ) ) {
		$state_count = count( $post_states );
		$i           = 0;

		$post_states_string .= ' — ';

		foreach ( $post_states as $state ) {
			$sep = ( ++$i === $state_count ) ? '' : ', ';

			$post_states_string .= "<span class='post-state'>$state$sep</span>";
		}
	}

	if ( $echo ) {
		echo $post_states_string;
	}

	return $post_states_string;
}

Advertisement

Changelog Changelog

Changelog
Version Description
5.3.0 Added the $echo parameter and a return value.
2.7.0 Introduced.

See also See also

Advertisement

Leave a Reply