post_name );
return;
}
if ( 'description' === $column_name && has_excerpt( $post_id ) ) {
the_excerpt( $post_id );
return;
}
if ( 'status' === $column_name ) {
$post_status = get_post_status( $post_id );
// The auto-draft status doesn't have localized labels.
if ( 'auto-draft' === $post_status ) {
echo esc_html_x( 'Auto-Draft', 'Post status', 'gutenberg' );
return;
}
$post_status_object = get_post_status_object( $post_status );
echo esc_html( $post_status_object->label );
return;
}
if ( 'theme' === $column_name ) {
$terms = get_the_terms( $post_id, 'wp_theme' );
if ( empty( $terms ) || is_wp_error( $terms ) ) {
return;
}
$themes = array();
foreach ( $terms as $term ) {
$themes[] = esc_html( wp_get_theme( $term->slug ) );
}
echo implode( '
', $themes );
return;
}
}
/**
* Adds the auto-draft view to the templates and template parts admin lists.
*
* @param array $views The edit views to filter.
*/
function gutenberg_filter_templates_edit_views( $views ) {
$post_type = get_current_screen()->post_type;
$url = add_query_arg(
array(
'post_type' => $post_type,
'post_status' => 'auto-draft',
),
'edit.php'
);
$is_auto_draft_view = isset( $_REQUEST['post_status'] ) && 'auto-draft' === $_REQUEST['post_status'];
$class_html = $is_auto_draft_view ? ' class="current"' : '';
$aria_current = $is_auto_draft_view ? ' aria-current="page"' : '';
$post_count = wp_count_posts( $post_type, 'readable' );
$label = sprintf(
// The auto-draft status doesn't have localized labels.
translate_nooped_plural(
/* translators: %s: Number of auto-draft posts. */
_nx_noop(
'Auto-Draft (%s)',
'Auto-Drafts (%s)',
'Post status',
'gutenberg'
),
$post_count->{'auto-draft'}
),
number_format_i18n( $post_count->{'auto-draft'} )
);
$auto_draft_view = sprintf(
'%s',
esc_url( $url ),
$class_html,
$aria_current,
$label
);
array_splice( $views, 1, 0, array( 'auto-draft' => $auto_draft_view ) );
return $views;
}