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

Outputs the attachment media states as HTML.

Parameters

$post

(WP_Post) (Required) The attachment post to retrieve states for.

$echo

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

Default value: true

Return

(string) Media states string.

Source

File: wp-admin/includes/template.php

function _media_states( $post, $echo = true ) {
	$media_states        = get_media_states( $post );
	$media_states_string = '';

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

		$media_states_string .= ' — ';

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

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

	if ( $echo ) {
		echo $media_states_string;
	}

	return $media_states_string;
}

Changelog

Version Description
5.6.0 Added the $echo parameter and a return value.
3.2.0 Introduced.

© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/_media_states