_media_states()
Outputs the attachment media states as HTML.
Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.
No Hooks.
Returns
String. Media states string.
Usage
_media_states( $post, $display );
- $post(WP_Post) (required)
- The attachment post to retrieve states for.
- $display(true|false)
- Whether to display the post states as an HTML string.
Default:true
Changelog
| Since 3.2.0 | Introduced. |
| Since 5.6.0 | Added the $display parameter and a return value. |
_media_states() media states code WP 7.0
function _media_states( $post, $display = true ) {
$media_states = get_media_states( $post );
$media_states_string = '';
if ( ! empty( $media_states ) ) {
$state_count = count( $media_states );
$separator = wp_get_list_item_separator();
$i = 0;
$media_states_string .= ' — ';
foreach ( $media_states as $state ) {
++$i;
$suffix = ( $i < $state_count ) ? $separator : '';
$media_states_string .= "<span class='post-state'>{$state}{$suffix}</span>";
}
}
if ( $display ) {
echo $media_states_string;
}
return $media_states_string;
}