WP_Posts_List_Table::get_no_title_excerpt │ protected │ WP 7.1.0

Gets a trimmed excerpt to display in place of a missing post title.

Only returns text in the Compact list view for posts that have no title, do not require a password, and that the current user is allowed to read.

Method of the class: WP_Posts_List_Table{}

No Hooks.

Returns

string. The escaped, trimmed excerpt, or an empty string.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_no_title_excerpt( $post );
$post(WP_Post) (required)
The current WP_Post object.

Notes

Global. String. $mode List table view mode.

Changelog

Since 7.1.0 Introduced.

WP_Posts_List_Table::get_no_title_excerpt() code WP 7.1.2

protected function get_no_title_excerpt( $post ) {
	global $mode;

	if ( 'excerpt' === $mode
		|| '' !== get_the_title( $post )
		|| post_password_required( $post )
		|| ! current_user_can( 'read_post', $post->ID )
	) {
		return '';
	}

	$excerpt = get_the_excerpt( $post );

	if ( '' === $excerpt || ! is_string( $excerpt ) ) {
		return '';
	}

	return esc_html( wp_trim_words( $excerpt, 15 ) );
}