_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.
Return
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 6.5.2
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; $separator = ( $i < $state_count ) ? ', ' : ''; $media_states_string .= "<span class='post-state'>{$state}{$separator}</span>"; } } if ( $display ) { echo $media_states_string; } return $media_states_string; }