Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,17 @@ public function column_title( $post ) {
echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
}

$pad = str_repeat( '&#8212; ', $this->current_level );
/**
* Filters the string used to indicate hierarchy level in the posts list table.
*
* The string is repeated once per level, so a child two levels deep will
* have the separator string prepended twice.
*
* @param string $separator The string used to indicate hierarchy level. Default '&#8212; '.
* @param WP_Post $post The current post object.
*/
$separator = apply_filters( 'post_title_child_separator', '&#8212; ', $post );
$pad = str_repeat( $separator, $this->current_level );
echo '<strong>';

$title = _draft_or_post_title();
Expand Down
82 changes: 82 additions & 0 deletions tests/phpunit/tests/admin/wpPostsListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,88 @@ public function test_empty_trash_button_should_not_be_shown_if_there_are_no_post
$this->assertStringNotContainsString( 'id="delete_all"', $output );
}

/**
* Tests that the default em-dash separator is output for child pages.
*
* @ticket 39106
*
* @covers WP_Posts_List_Table::column_title
*/
public function test_column_title_uses_default_separator_for_child_pages() {
// A child page has post_parent > 0, so column_title() will auto-calculate current_level.
$child = self::$children[1][1];

$this->table->set_hierarchical_display( true );

ob_start();
$this->table->column_title( $child );
$output = ob_get_clean();

$this->assertStringContainsString( '&#8212; ', $output );
}

/**
* Tests that the post_title_child_separator filter replaces the separator.
*
* @ticket 39106
*
* @covers WP_Posts_List_Table::column_title
*/
public function test_post_title_child_separator_filter_changes_separator() {
$child = self::$children[1][1];

$this->table->set_hierarchical_display( true );

add_filter(
'post_title_child_separator',
static function () {
return '> ';
}
);

ob_start();
$this->table->column_title( $child );
$output = ob_get_clean();

remove_all_filters( 'post_title_child_separator' );

$this->assertStringContainsString( '> ', $output );
$this->assertStringNotContainsString( '&#8212; ', $output );
}

/**
* Tests that the post_title_child_separator filter receives the current WP_Post object.
*
* @ticket 39106
*
* @covers WP_Posts_List_Table::column_title
*/
public function test_post_title_child_separator_filter_receives_post_object() {
$child = self::$children[1][1];

$this->table->set_hierarchical_display( true );

$received_post = null;
add_filter(
'post_title_child_separator',
static function ( $separator, $post ) use ( &$received_post ) {
$received_post = $post;
return $separator;
},
10,
2
);

ob_start();
$this->table->column_title( $child );
ob_get_clean();

remove_all_filters( 'post_title_child_separator' );

$this->assertInstanceOf( WP_Post::class, $received_post );
$this->assertSame( $child->ID, $received_post->ID );
}

/**
* @ticket 42066
*
Expand Down
Loading