WP_Posts_List_Table::column_titlepublicWP 4.3.0

Handles the title column output.

Method of the class: WP_Posts_List_Table{}

Returns

null. Nothing (null).

Usage

$WP_Posts_List_Table = new WP_Posts_List_Table();
$WP_Posts_List_Table->column_title( $post );
$post(WP_Post) (required)
The current WP_Post object.

Notes

Global. String. $mode List table view mode.

Changelog

Since 4.3.0 Introduced.
Since 7.1.0 Includes a trimmed excerpt for untitled posts in Compact view.

WP_Posts_List_Table::column_title() code WP 7.1

public function column_title( $post ) {
	global $mode;

	if ( $this->hierarchical_display ) {
		if ( 0 === $this->current_level && (int) $post->post_parent > 0 ) {
			// Sent level 0 by accident, by default, or because we don't know the actual level.
			$find_main_page = (int) $post->post_parent;

			while ( $find_main_page > 0 ) {
				$parent = get_post( $find_main_page );

				if ( is_null( $parent ) ) {
					break;
				}

				++$this->current_level;
				$find_main_page = (int) $parent->post_parent;

				if ( ! isset( $parent_name ) ) {
					/** This filter is documented in wp-includes/post-template.php */
					$parent_name = apply_filters( 'the_title', $parent->post_title, $parent->ID );
				}
			}
		}
	}

	$can_edit_post = current_user_can( 'edit_post', $post->ID );

	if ( $can_edit_post && 'trash' !== $post->post_status ) {
		$lock_holder = wp_check_post_lock( $post->ID );

		if ( $lock_holder ) {
			$lock_holder   = get_userdata( $lock_holder );
			$locked_avatar = get_avatar( $lock_holder->ID, 18 );
			/* translators: %s: User's display name. */
			$locked_text = esc_html( sprintf( __( '%s is currently editing' ), $lock_holder->display_name ) );
		} else {
			$locked_avatar = '';
			$locked_text   = '';
		}

		echo '<div class="locked-info"><span class="locked-avatar">' . $locked_avatar . '</span> <span class="locked-text">' . $locked_text . "</span></div>\n";
	}

	$pad               = str_repeat(
		'<span aria-hidden="true">&#8212;</span> ',
		$this->current_level
	);
	$described_by_attr = '';
	$hierarchy_linked  = '';
	$hierarchy_nolink  = '';

	if ( $post->post_parent ) {
		$parent = get_post( $post->post_parent );

		if ( $parent ) {
			/** This filter is documented in wp-includes/post-template.php */
			$parent_title = apply_filters( 'the_title', $parent->post_title, $parent->ID );

			$hierarchy_id      = 'post-hierarchy-' . $post->ID;
			$described_by_attr = sprintf( ' aria-describedby="%s"', esc_attr( $hierarchy_id ) );
			$hierarchy_linked  = sprintf(
				'<span id="%1$s" class="hidden">%2$s</span>',
				esc_attr( $hierarchy_id ),
				/* translators: %s: Parent post title. */
				esc_html( sprintf( __( 'Child of %s' ), wp_strip_all_tags( $parent_title ) ) )
			);
			$hierarchy_nolink = sprintf(
				'<span id="%1$s" class="screen-reader-text"> (%2$s)</span>',
				esc_attr( $hierarchy_id ),
				/* translators: %s: Parent post title. */
				esc_html( sprintf( __( 'Child of %s' ), wp_strip_all_tags( $parent_title ) ) )
			);
		}
	}

	echo '<strong>';

	$title = _draft_or_post_title();

	// If the post has no title, try adding part of the excerpt.
	$no_title_excerpt = $this->get_no_title_excerpt( $post );
	if ( '' !== $no_title_excerpt ) {
		$title .= ' <span class="trimmed-post-excerpt">' . $no_title_excerpt . '</span>';
	}

	if ( $can_edit_post && 'trash' !== $post->post_status ) {
		printf(
			'%1$s<a class="row-title" href="%2$s"%3$s>%4$s</a>%5$s',
			$pad,
			get_edit_post_link( $post->ID ),
			$described_by_attr,
			$title,
			$hierarchy_linked
		);
	} else {
		printf(
			'%1$s<span>%2$s%3$s</span>',
			$pad,
			$title,
			$hierarchy_nolink
		);
	}
	_post_states( $post );

	if ( isset( $parent_name ) ) {
		$post_type_object = get_post_type_object( $post->post_type );
		echo ' | ' . $post_type_object->labels->parent_item_colon . ' ' . esc_html( $parent_name );
	}

	echo "</strong>\n";

	if ( 'excerpt' === $mode
		&& ! is_post_type_hierarchical( $this->screen->post_type )
		&& current_user_can( 'read_post', $post->ID )
	) {
		if ( post_password_required( $post ) ) {
			echo '<span class="protected-post-excerpt">' . esc_html( get_the_excerpt() ) . '</span>';
		} else {
			echo esc_html( get_the_excerpt() );
		}
	}

	/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
	$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_post_type', true, $post->post_type );

	if ( $quick_edit_enabled ) {
		get_inline_data( $post );
	}
}