Skip to content

Commit

Permalink
Full Site Editing: Add the theme source to the templates wp-admin list (
Browse files Browse the repository at this point in the history
#27108)

* Add the theme to the templates wp-admin list

* Clear lint errors
  • Loading branch information
Copons authored Nov 20, 2020
1 parent 0cdd7ed commit 974906b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,13 @@ function gutenberg_register_wp_theme_taxonomy() {
* Automatically set the theme meta for templates.
*
* @param array $post_id Template ID.
* @param array $post Template Post.
* @param bool $update Is update.
*/
function gutenberg_set_template_and_template_part_post_theme( $post_id, $post, $update ) {
function gutenberg_set_template_and_template_part_post_theme( $post_id ) {
$themes = wp_get_post_terms( $post_id, 'wp_theme' );
if ( ! $themes ) {
wp_set_post_terms( $post_id, array( wp_get_theme()->get_stylesheet() ), 'wp_theme', true );
}
}

add_action( 'save_post_wp_template', 'gutenberg_set_template_and_template_part_post_theme', 10, 3 );
add_action( 'save_post_wp_template_part', 'gutenberg_set_template_and_template_part_post_theme', 10, 3 );

Expand Down Expand Up @@ -205,6 +202,7 @@ function gutenberg_filter_template_list_table_columns( array $columns ) {
$columns['slug'] = __( 'Slug', 'gutenberg' );
$columns['description'] = __( 'Description', 'gutenberg' );
$columns['status'] = __( 'Status', 'gutenberg' );
$columns['theme'] = __( 'Theme', 'gutenberg' );
if ( isset( $columns['date'] ) ) {
unset( $columns['date'] );
}
Expand Down Expand Up @@ -241,6 +239,24 @@ function gutenberg_render_template_list_table_column( $column_name, $post_id ) {
echo esc_html( $post_status_object->label );
return;
}

if ( 'theme' === $column_name ) {
$terms = get_the_terms( $post_id, 'wp_theme' );
$themes = array();
$is_file_based = false;
foreach ( $terms as $term ) {
if ( '_wp_file_based' === $term->slug ) {
$is_file_based = true;
} else {
$themes[] = esc_html( wp_get_theme( $term->slug ) );
}
}
echo implode( '<br />', $themes );
if ( $is_file_based ) {
echo '<br />' . __( '(Created from a template file)', 'gutenberg' );
}
return;
}
}
add_action( 'manage_wp_template_posts_custom_column', 'gutenberg_render_template_list_table_column', 10, 2 );

Expand Down

0 comments on commit 974906b

Please sign in to comment.