| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Bulk_Editor\Infrastructure\Posts; |
| 5 |
|
| 6 |
/** |
| 7 |
* Produces the display title shared by both post collectors. |
| 8 |
*/ |
| 9 |
trait Post_Title_Trait { |
| 10 |
|
| 11 |
/** |
| 12 |
* Returns the post title for display in the bulk editor. |
| 13 |
* |
| 14 |
* The `the_title` filter run by get_the_title() can return HTML-encoded entities; they are |
| 15 |
* decoded so the React table renders them as text. An empty title falls back to WordPress' own |
| 16 |
* untitled-post convention, so the table and its accessible names always have text content. |
| 17 |
* |
| 18 |
* @param int $post_id The post ID. |
| 19 |
* |
| 20 |
* @return string The display title. |
| 21 |
*/ |
| 22 |
protected function get_normalized_title( int $post_id ): string { |
| 23 |
$title = \html_entity_decode( \get_the_title( $post_id ), \ENT_QUOTES, 'UTF-8' ); |
| 24 |
if ( $title === '' ) { |
| 25 |
return \__( '(no title)', 'wordpress-seo' ); |
| 26 |
} |
| 27 |
|
| 28 |
return $title; |
| 29 |
} |
| 30 |
} |
| 31 |
|