_media_states() WordPress Function

The media states function allows you to add custom states to your media attachment post type. This is useful for indicating the status of an attachment, such as if it's been approved or rejected.

_media_states( WP_Post $post, bool $display = true ) #

Outputs the attachment media states as HTML.


Parameters

$post

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

$display

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

Default value: true


Top ↑

Return

(string) Media states string.


Top ↑

Source

File: wp-admin/includes/template.php

function _media_states( $post, $display = 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 ) {
			++$i;

			$sep = ( $i < $state_count ) ? ', ' : '';

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

	if ( $display ) {
		echo $media_states_string;
	}

	return $media_states_string;
}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Added the $display parameter and a return value.
3.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.