Make WordPress Core

Changeset 60993


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.

Location:
trunk
Files:
2 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 );
  • trunk/tests/phpunit/tests/post/getPostStatus.php

    r60986 r60993  
    167167
    168168        /**
    169          * Ensure the `post_states_string` filter works to modify post state output.
     169         * Ensure the `post_states_html` filter works to modify post state output.
    170170         *
    171171         * @ticket 51403
    172172         *
    173          * @dataProvider data_filter_post_states_string_should_enable_post_state_html_output_modification
     173         * @dataProvider data_filter_post_states_html_should_enable_post_state_html_output_modification
    174174         *
    175175         * @covers ::_post_states
     
    177177         * @param string $post_state The post state to test.
    178178         */
    179         public function test_filter_post_states_string_should_enable_post_state_html_output_modification( $post_state ) {
     179        public function test_filter_post_states_html_should_enable_post_state_html_output_modification( $post_state ) {
    180180                $post = get_post( self::$post_ids[ $post_state ] );
    181181
     
    189189
    190190                add_filter(
    191                         'post_states_string',
    192                         function ( $post_states_string, $post_states, $filtered_post ) use ( $text_to_append, $post ) {
    193                                 $this->assertIsString( $post_states_string, 'Expected first filter arg to be a string.' );
     191                        'post_states_html',
     192                        function ( $post_states_html, $post_states, $filtered_post ) use ( $text_to_append, $post ) {
     193                                $this->assertIsString( $post_states_html, 'Expected first filter arg to be a string.' );
    194194                                $this->assertIsArray( $post_states, 'Expected second filter arg to be an array.' );
    195195                                $this->assertInstanceOf( WP_Post::class, $filtered_post, 'Expected third filter arg to be a WP_Post' );
    196196                                $this->assertSame( $post->ID, $filtered_post->ID, 'Expected the third filter arg to be the same as the current post.' );
    197                                 return $post_states_string . $text_to_append;
     197                                return $post_states_html . $text_to_append;
    198198                        },
    199199                        10,
     
    207207
    208208        /**
    209          * Data provider for test_filter_post_states_string_should_enable_post_state_html_output_modification().
     209         * Data provider for test_filter_post_states_html_should_enable_post_state_html_output_modification().
    210210         *
    211211         * @return array[] {
     
    213213         * }
    214214         */
    215         public static function data_filter_post_states_string_should_enable_post_state_html_output_modification() {
     215        public static function data_filter_post_states_html_should_enable_post_state_html_output_modification() {
    216216                return array(
    217217                        array( 'publish' ),
Note: See TracChangeset for help on using the changeset viewer.