_post_states()
Echoes or returns the post 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.
Hooks from the function
Returns
String. Post states string.
Usage
_post_states( $post, $display );
- $post(WP_Post) (required)
- The post to retrieve states for.
- $display(true|false)
- Whether to display the post states as an HTML string.
Default:true
Notes
- See: get_post_states()
Changelog
| Since 2.7.0 | Introduced. |
| Since 5.3.0 | Added the $display parameter and a return value. |
_post_states() post states code WP 7.0
function _post_states( $post, $display = true ) {
$post_states = get_post_states( $post );
$post_states_html = '';
if ( ! empty( $post_states ) ) {
$state_count = count( $post_states );
$separator = wp_get_list_item_separator();
$i = 0;
$post_states_html .= ' — ';
foreach ( $post_states as $state ) {
++$i;
$suffix = ( $i < $state_count ) ? $separator : '';
$post_states_html .= "<span class='post-state'>{$state}{$suffix}</span>";
}
}
/**
* Filters the HTML string of post states.
*
* @since 6.9.0
*
* @param string $post_states_html All relevant post states combined into an HTML string for display.
* E.g. `— <span class='post-state'>Draft, </span><span class='post-state'>Sticky</span>`.
* @param array<string, string> $post_states A mapping of post state slugs to translated post state labels.
* E.g. `array( 'draft' => __( 'Draft' ), 'sticky' => __( 'Sticky' ), ... )`.
* @param WP_Post $post The current post object.
*/
$post_states_html = apply_filters( 'post_states_html', $post_states_html, $post_states, $post );
if ( $display ) {
echo $post_states_html;
}
return $post_states_html;
}