Skip to content

Commit 4f3c923

Browse files
committed
Posts, Post Types: Rename new post_states_string filter to post_states_html.
Add examples to the PHPDoc for the filter params. Developed in #10360 Follow-up to [60986]. Props dmsnell, westonruter. See #51403. git-svn-id: https://develop.svn.wordpress.org/trunk@60993 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 458daed commit 4f3c923

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/wp-admin/includes/template.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,22 +2246,22 @@ function iframe_footer() {
22462246
* @return string Post states string.
22472247
*/
22482248
function _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 ) ) {
22532253
$state_count = count( $post_states );
22542254

22552255
$i = 0;
22562256

2257-
$post_states_string .= ' — ';
2257+
$post_states_html .= ' — ';
22582258

22592259
foreach ( $post_states as $state ) {
22602260
++$i;
22612261

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
}
22672267

@@ -2270,17 +2270,19 @@ function _post_states( $post, $display = true ) {
22702270
*
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;
2282+
echo $post_states_html;
22812283
}
22822284

2283-
return $post_states_string;
2285+
return $post_states_html;
22842286
}
22852287

22862288
/**
@@ -2353,8 +2355,9 @@ function get_post_states( $post ) {
23532355
* are used within the filter, their existence should be checked
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 );
23602363
}

tests/phpunit/tests/post/getPostStatus.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,17 @@ public function data_get_post_status_after_trashing() {
166166
}
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
176176
*
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

182182
$original_output = _post_states( $post, false );
@@ -188,13 +188,13 @@ public function test_filter_post_states_string_should_enable_post_state_html_out
188188
}
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,
200200
3
@@ -206,13 +206,13 @@ function ( $post_states_string, $post_states, $filtered_post ) use ( $text_to_ap
206206
}
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[] {
212212
* @type string $post_state The post state to test.
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' ),
218218
array( 'future' ),

0 commit comments

Comments
 (0)