Make WordPress Core


Ignore:
Timestamp:
10/20/2025 09:43:10 PM (11 months ago)
Author:
westonruter
Message:

Posts, Post Types: Rename new post_states_string filter to post_states_html.

Add examples to the PHPDoc for the filter params.

Developed in https://github.com/WordPress/wordpress-develop/pull/10360

Follow-up to [60986].

Props dmsnell, westonruter.
See #51403.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/template.php

    r60986 r60993  
    22472247 */
    22482248function _post_states( $post, $display = true ) {
    2249         $post_states        = get_post_states( $post );
    2250         $post_states_string = '';
     2249        $post_states      = get_post_states( $post );
     2250        $post_states_html = '';
    22512251
    22522252        if ( ! empty( $post_states ) ) {
     
    22552255                $i = 0;
    22562256
    2257                 $post_states_string .= ' — ';
     2257                $post_states_html .= ' — ';
    22582258
    22592259                foreach ( $post_states as $state ) {
     
    22622262                        $separator = ( $i < $state_count ) ? ', ' : '';
    22632263
    2264                         $post_states_string .= "<span class='post-state'>{$state}{$separator}</span>";
     2264                        $post_states_html .= "<span class='post-state'>{$state}{$separator}</span>";
    22652265                }
    22662266        }
     
    22712271         * @since 6.9.0
    22722272         *
    2273          * @param string   $post_states_string The post states HTML string.
    2274          * @param string[] $post_states        The post states.
    2275          * @param WP_Post  $post               The current post object.
     2273         * @param string                 $post_states_html All relevant post states combined into an HTML string for display.
     2274         *                                                 E.g. `&mdash; <span class='post-state'>Draft, </span><span class='post-state'>Sticky</span>`.
     2275         * @param string<string, string> $post_states      A mapping of post state slugs to translated post state labels.
     2276         *                                                 E.g. `array( 'draft' => __( 'Draft' ), 'sticky' => __( 'Sticky' ), ... )`.
     2277         * @param WP_Post                $post             The current post object.
    22762278         */
    2277         $post_states_string = apply_filters( 'post_states_string', $post_states_string, $post_states, $post );
     2279        $post_states_html = apply_filters( 'post_states_html', $post_states_html, $post_states, $post );
    22782280
    22792281        if ( $display ) {
    2280                 echo $post_states_string;
    2281         }
    2282 
    2283         return $post_states_string;
     2282                echo $post_states_html;
     2283        }
     2284
     2285        return $post_states_html;
    22842286}
    22852287
     
    23542356         *              with `function_exists()` before being used.
    23552357         *
    2356          * @param string[] $post_states An array of post display states.
    2357          * @param WP_Post  $post        The current post object.
     2358         * @param string<string, string> $post_states A mapping of post state slugs to translated post state labels.
     2359         *                                            E.g. `array( 'draft' => __( 'Draft' ), 'sticky' => __( 'Sticky' ), ... )`.
     2360         * @param WP_Post                $post        The current post object.
    23582361         */
    23592362        return apply_filters( 'display_post_states', $post_states, $post );
Note: See TracChangeset for help on using the changeset viewer.