Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full Site Editing: Add the theme source to the templates wp-admin list #27108

Merged
merged 2 commits into from
Nov 20, 2020
Merged
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
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