Changeset 60993
- Timestamp:
- 10/20/2025 09:43:10 PM (11 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/wp-admin/includes/template.php (modified) (5 diffs)
-
tests/phpunit/tests/post/getPostStatus.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/template.php
r60986 r60993 2247 2247 */ 2248 2248 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 = ''; 2251 2251 2252 2252 if ( ! empty( $post_states ) ) { … … 2255 2255 $i = 0; 2256 2256 2257 $post_states_ string.= ' — ';2257 $post_states_html .= ' — '; 2258 2258 2259 2259 foreach ( $post_states as $state ) { … … 2262 2262 $separator = ( $i < $state_count ) ? ', ' : ''; 2263 2263 2264 $post_states_ string.= "<span class='post-state'>{$state}{$separator}</span>";2264 $post_states_html .= "<span class='post-state'>{$state}{$separator}</span>"; 2265 2265 } 2266 2266 } … … 2271 2271 * @since 6.9.0 2272 2272 * 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. `— <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. 2276 2278 */ 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 ); 2278 2280 2279 2281 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; 2284 2286 } 2285 2287 … … 2354 2356 * with `function_exists()` before being used. 2355 2357 * 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. 2358 2361 */ 2359 2362 return apply_filters( 'display_post_states', $post_states, $post ); -
trunk/tests/phpunit/tests/post/getPostStatus.php
r60986 r60993 167 167 168 168 /** 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. 170 170 * 171 171 * @ticket 51403 172 172 * 173 * @dataProvider data_filter_post_states_ string_should_enable_post_state_html_output_modification173 * @dataProvider data_filter_post_states_html_should_enable_post_state_html_output_modification 174 174 * 175 175 * @covers ::_post_states … … 177 177 * @param string $post_state The post state to test. 178 178 */ 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 ) { 180 180 $post = get_post( self::$post_ids[ $post_state ] ); 181 181 … … 189 189 190 190 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.' ); 194 194 $this->assertIsArray( $post_states, 'Expected second filter arg to be an array.' ); 195 195 $this->assertInstanceOf( WP_Post::class, $filtered_post, 'Expected third filter arg to be a WP_Post' ); 196 196 $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; 198 198 }, 199 199 10, … … 207 207 208 208 /** 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(). 210 210 * 211 211 * @return array[] { … … 213 213 * } 214 214 */ 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() { 216 216 return array( 217 217 array( 'publish' ),
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)