diff --git a/lib/full-site-editing/block-templates.php b/lib/full-site-editing/block-templates.php index 5d67b13eb4edab..def0af66b9f2f9 100644 --- a/lib/full-site-editing/block-templates.php +++ b/lib/full-site-editing/block-templates.php @@ -280,27 +280,29 @@ function _gutenberg_build_template_result_from_file( $template_file, $template_t * @return WP_Block_Template|WP_Error Template. */ function _gutenberg_build_template_result_from_post( $post ) { - $default_template_types = gutenberg_get_default_template_types(); - $terms = get_the_terms( $post, 'wp_theme' ); - - if ( is_wp_error( $terms ) ) { - return $terms; + if ( ! in_array( $post->post_type, array( 'wp_template', 'wp_template_part' ), true ) ) { + return new WP_Error( 'template_wrong_post_type', __( 'An invalid post was provided for this template.', 'gutenberg' ) ); } - if ( ! $terms ) { + $default_template_types = gutenberg_get_default_template_types(); + $ids = get_theme_mod( $post->post_type, array() ); + $active = in_array( $post->ID, $ids, true ); + + // Temporarily disable inactive access for 5.8 version. + if ( ! $active ) { return new WP_Error( 'template_missing_theme', __( 'No theme is defined for this template.', 'gutenberg' ) ); } - $theme = $terms[0]->name; - $has_theme_file = wp_get_theme()->get_stylesheet() === $theme && - null !== _gutenberg_get_template_file( $post->post_type, $post->post_name ); + $theme = wp_get_theme()->get_stylesheet(); + $slug = array_search( $post->ID, $ids, true ); + $has_theme_file = null !== _gutenberg_get_template_file( $post->post_type, $slug ); $template = new WP_Block_Template(); $template->wp_id = $post->ID; - $template->id = $theme . '//' . $post->post_name; + $template->id = $theme . '//' . $slug; $template->theme = $theme; $template->content = $post->post_content; - $template->slug = $post->post_name; + $template->slug = $slug; $template->source = 'custom'; $template->type = $post->post_type; $template->description = $post->post_excerpt; @@ -326,7 +328,7 @@ function _gutenberg_build_template_result_from_post( $post ) { /** * Retrieves a list of unified template objects based on a query. * - * @param array $query { + * @param array $query { * Optional. Arguments to retrieve templates. * * @type array $slug__in List of slugs to include. @@ -334,7 +336,7 @@ function _gutenberg_build_template_result_from_post( $post ) { * @type string $area A 'wp_template_part_area' taxonomy value to filter by (for wp_template_part template type only). * @type string $post_type Post type to get the templates for. * } - * @param array $template_type wp_template or wp_template_part. + * @param string $template_type wp_template or wp_template_part. * * @return array Templates. */ @@ -362,22 +364,20 @@ function gutenberg_get_block_templates( $query = array(), $template_type = 'wp_t return $templates; } + $ids = get_theme_mod( $template_type, array() ); + $post__in = 'post__in'; + $post_type = isset( $query['post_type'] ) ? $query['post_type'] : ''; $wp_query_args = array( 'post_status' => array( 'auto-draft', 'draft', 'publish' ), 'post_type' => $template_type, 'posts_per_page' => -1, 'no_found_rows' => true, - 'tax_query' => array( - array( - 'taxonomy' => 'wp_theme', - 'field' => 'name', - 'terms' => wp_get_theme()->get_stylesheet(), - ), - ), + $post__in => array_values( $ids ), ); if ( 'wp_template_part' === $template_type && isset( $query['area'] ) ) { + $wp_query_args['tax_query'] = array(); $wp_query_args['tax_query'][] = array( 'taxonomy' => 'wp_template_part_area', 'field' => 'name', @@ -387,7 +387,12 @@ function gutenberg_get_block_templates( $query = array(), $template_type = 'wp_t } if ( isset( $query['slug__in'] ) ) { - $wp_query_args['post_name__in'] = $query['slug__in']; + $wp_query_args['post__in'] = array(); + foreach ( $query['slug__in'] as $slug ) { + if ( ! empty( $ids[ $slug ] ) ) { + $wp_query_args['post__in'][] = $ids[ $slug ]; + } + } } // This is only needed for the regular templates/template parts CPT listing and editor. @@ -397,20 +402,24 @@ function gutenberg_get_block_templates( $query = array(), $template_type = 'wp_t $wp_query_args['post_status'] = 'publish'; } - $template_query = new WP_Query( $wp_query_args ); - $query_result = array(); - foreach ( $template_query->posts as $post ) { - $template = _gutenberg_build_template_result_from_post( $post ); + $query_result = array(); - if ( is_wp_error( $template ) ) { - continue; - } + // See https://core.trac.wordpress.org/ticket/28099 for context. + if ( ! isset( $wp_query_args['post__in'] ) || array() !== $wp_query_args['post__in'] ) { + $template_query = new WP_Query( $wp_query_args ); + foreach ( $template_query->posts as $post ) { + $template = _gutenberg_build_template_result_from_post( $post ); - if ( $post_type && ! $template->is_custom ) { - continue; - } + if ( is_wp_error( $template ) ) { + continue; + } + + if ( $post_type && ! $template->is_custom ) { + continue; + } - $query_result[] = $template; + $query_result[] = $template; + } } if ( ! isset( $query['wp_id'] ) ) { @@ -465,8 +474,8 @@ function gutenberg_get_block_templates( $query = array(), $template_type = 'wp_t /** * Retrieves a single unified template object using its id. * - * @param string $id Template unique identifier (example: theme_slug//template_slug). - * @param array $template_type wp_template or wp_template_part. + * @param string $id Template unique identifier (example: theme_slug//template_slug). + * @param string $template_type wp_template or wp_template_part. * * @return WP_Block_Template|null Template. */ @@ -493,25 +502,22 @@ function gutenberg_get_block_template( $id, $template_type = 'wp_template' ) { return null; } list( $theme, $slug ) = $parts; - $wp_query_args = array( - 'post_name__in' => array( $slug ), - 'post_type' => $template_type, - 'post_status' => array( 'auto-draft', 'draft', 'publish', 'trash' ), - 'posts_per_page' => 1, - 'no_found_rows' => true, - 'tax_query' => array( - array( - 'taxonomy' => 'wp_theme', - 'field' => 'name', - 'terms' => $theme, - ), - ), - ); - $template_query = new WP_Query( $wp_query_args ); - $posts = $template_query->posts; - if ( count( $posts ) > 0 ) { - $template = _gutenberg_build_template_result_from_post( $posts[0] ); + $active = wp_get_theme()->get_stylesheet() === $theme; + + // Temporarily disable inactive access for 5.8 version. + if ( ! $active ) { + return null; + } + + $ids = get_theme_mod( $template_type, array() ); + + if ( ! empty( $ids[ $slug ] ) ) { + $post = get_post( $ids[ $slug ] ); + } + + if ( $post && $template_type === $post->post_type ) { + $template = _gutenberg_build_template_result_from_post( $post ); if ( ! is_wp_error( $template ) ) { return $template; @@ -590,67 +596,3 @@ function gutenberg_get_block_file_template( $id, $template_type = 'wp_template' */ return apply_filters( 'get_block_file_template', $block_template, $id, $template_type ); } - -/** - * Generates a unique slug for templates or template parts. - * - * @param string $override_slug The filtered value of the slug (starts as `null` from apply_filter). - * @param string $slug The original/un-filtered slug (post_name). - * @param int $post_ID Post ID. - * @param string $post_status No uniqueness checks are made if the post is still draft or pending. - * @param string $post_type Post type. - * @return string The original, desired slug. - */ -function gutenberg_filter_wp_template_unique_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type ) { - if ( 'wp_template' !== $post_type && 'wp_template_part' !== $post_type ) { - return $override_slug; - } - - if ( ! $override_slug ) { - $override_slug = $slug; - } - - // Template slugs must be unique within the same theme. - // TODO - Figure out how to update this to work for a multi-theme - // environment. Unfortunately using `get_the_terms` for the 'wp-theme' - // term does not work in the case of new entities since is too early in - // the process to have been saved to the entity. So for now we use the - // currently activated theme for creation. - $theme = wp_get_theme()->get_stylesheet(); - $terms = get_the_terms( $post_ID, 'wp_theme' ); - if ( $terms && ! is_wp_error( $terms ) ) { - $theme = $terms[0]->name; - } - - $check_query_args = array( - 'post_name__in' => array( $override_slug ), - 'post_type' => $post_type, - 'posts_per_page' => 1, - 'no_found_rows' => true, - 'post__not_in' => array( $post_ID ), - 'tax_query' => array( - array( - 'taxonomy' => 'wp_theme', - 'field' => 'name', - 'terms' => $theme, - ), - ), - ); - $check_query = new WP_Query( $check_query_args ); - $posts = $check_query->posts; - - if ( count( $posts ) > 0 ) { - $suffix = 2; - do { - $query_args = $check_query_args; - $alt_post_name = _truncate_post_slug( $override_slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; - $query_args['post_name__in'] = array( $alt_post_name ); - $query = new WP_Query( $query_args ); - $suffix++; - } while ( count( $query->posts ) > 0 ); - $override_slug = $alt_post_name; - } - - return $override_slug; -} -add_filter( 'pre_wp_unique_post_slug', 'gutenberg_filter_wp_template_unique_post_slug', 10, 5 ); diff --git a/lib/full-site-editing/class-gutenberg-rest-templates-controller.php b/lib/full-site-editing/class-gutenberg-rest-templates-controller.php index dafb15509bd012..619e834ce5b318 100644 --- a/lib/full-site-editing/class-gutenberg-rest-templates-controller.php +++ b/lib/full-site-editing/class-gutenberg-rest-templates-controller.php @@ -223,6 +223,10 @@ public function update_item( $request ) { return $result; } + if ( 'custom' !== $template->source ) { + gutenberg_customize_template( $template->slug, $result ); + } + $template = gutenberg_get_block_template( $request['id'], $this->post_type ); $fields_update = $this->update_additional_fields_for_object( $template, $request ); if ( is_wp_error( $fields_update ) ) { @@ -258,6 +262,9 @@ public function create_item( $request ) { if ( is_wp_error( $result ) ) { return $result; } + + gutenberg_customize_template( $request['slug'], $result, false ); + $posts = gutenberg_get_block_templates( array( 'wp_id' => $result ), $this->post_type ); if ( ! count( $posts ) ) { return new WP_Error( 'rest_template_insert_error', __( 'No templates exist with that id.', 'gutenberg' ) ); @@ -341,21 +348,10 @@ public function delete_item( $request ) { protected function prepare_item_for_database( $request ) { $template = $request['id'] ? gutenberg_get_block_template( $request['id'], $this->post_type ) : null; $changes = new stdClass(); - if ( null === $template ) { + if ( null === $template || 'custom' !== $template->source ) { $changes->post_type = $this->post_type; $changes->post_status = 'publish'; - $changes->tax_input = array( - 'wp_theme' => isset( $request['theme'] ) ? $request['theme'] : wp_get_theme()->get_stylesheet(), - ); - } elseif ( 'custom' !== $template->source ) { - $changes->post_name = $template->slug; - $changes->post_type = $this->post_type; - $changes->post_status = 'publish'; - $changes->tax_input = array( - 'wp_theme' => $template->theme, - ); } else { - $changes->post_name = $template->slug; $changes->ID = $template->wp_id; $changes->post_status = 'publish'; } @@ -377,11 +373,11 @@ protected function prepare_item_for_database( $request ) { if ( 'wp_template_part' === $this->post_type ) { if ( isset( $request['area'] ) ) { - $changes->tax_input['wp_template_part_area'] = gutenberg_filter_template_part_area( $request['area'] ); + $changes->tax_input = array( 'wp_template_part_area' => gutenberg_filter_template_part_area( $request['area'] ) ); } elseif ( null !== $template && 'custom' !== $template->source && $template->area ) { - $changes->tax_input['wp_template_part_area'] = gutenberg_filter_template_part_area( $template->area ); + $changes->tax_input = array( 'wp_template_part_area' => gutenberg_filter_template_part_area( $template->area ) ); } elseif ( ! $template->area ) { - $changes->tax_input['wp_template_part_area'] = WP_TEMPLATE_PART_AREA_UNCATEGORIZED; + $changes->tax_input = array( 'wp_template_part_area' => WP_TEMPLATE_PART_AREA_UNCATEGORIZED ); } } diff --git a/lib/full-site-editing/template-parts.php b/lib/full-site-editing/template-parts.php index 2693821d03ace9..c1bd7492a08dcc 100644 --- a/lib/full-site-editing/template-parts.php +++ b/lib/full-site-editing/template-parts.php @@ -131,36 +131,6 @@ function gutenberg_fix_template_part_admin_menu_entry() { // Customize the `wp_template` admin list. add_filter( 'manage_wp_template_part_posts_columns', 'gutenberg_templates_lists_custom_columns' ); add_action( 'manage_wp_template_part_posts_custom_column', 'gutenberg_render_templates_lists_custom_column', 10, 2 ); -add_filter( 'views_edit-wp_template_part', 'gutenberg_filter_templates_edit_views' ); - -/** - * Sets a custom slug when creating auto-draft template parts. - * This is only needed for auto-drafts created by the regular WP editor. - * If this page is to be removed, this won't be necessary. - * - * @param int $post_id Post ID. - */ -function set_unique_slug_on_create_template_part( $post_id ) { - $post = get_post( $post_id ); - if ( 'auto-draft' !== $post->post_status ) { - return; - } - - if ( ! $post->post_name ) { - wp_update_post( - array( - 'ID' => $post_id, - 'post_name' => 'custom_slug_' . uniqid(), - ) - ); - } - - $terms = get_the_terms( $post_id, 'wp_theme' ); - if ( ! $terms || ! count( $terms ) ) { - wp_set_post_terms( $post_id, wp_get_theme()->get_stylesheet(), 'wp_theme' ); - } -} -add_action( 'save_post_wp_template_part', 'set_unique_slug_on_create_template_part' ); /** * Returns a filtered list of allowed area values for template parts. diff --git a/lib/full-site-editing/templates-utils.php b/lib/full-site-editing/templates-utils.php index bc270a738d9677..6ee2cdb99f6a82 100644 --- a/lib/full-site-editing/templates-utils.php +++ b/lib/full-site-editing/templates-utils.php @@ -12,10 +12,8 @@ * @return array Filtered $columns. */ function gutenberg_templates_lists_custom_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'] ); } @@ -29,85 +27,22 @@ function gutenberg_templates_lists_custom_columns( array $columns ) { * @param int $post_id Post ID. */ function gutenberg_render_templates_lists_custom_column( $column_name, $post_id ) { - if ( 'slug' === $column_name ) { - $post = get_post( $post_id ); - echo esc_html( $post->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 ); + echo in_array( + $post_id, + array_values( + get_theme_mod( + get_post_type( $post_id ), + array() + ) + ), + true + ) ? 'Active' : ''; 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; -} diff --git a/lib/full-site-editing/templates.php b/lib/full-site-editing/templates.php index 85cb8ce47a77aa..55f56d01c15e63 100644 --- a/lib/full-site-editing/templates.php +++ b/lib/full-site-editing/templates.php @@ -71,7 +71,7 @@ function gutenberg_register_wp_theme_taxonomy() { register_taxonomy( 'wp_theme', - array( 'wp_template', 'wp_template_part', 'wp_global_styles' ), + array( 'wp_global_styles' ), array( 'public' => false, 'hierarchical' => false, @@ -143,36 +143,73 @@ function gutenberg_fix_template_admin_menu_entry() { // Customize the `wp_template` admin list. add_filter( 'manage_wp_template_posts_columns', 'gutenberg_templates_lists_custom_columns' ); add_action( 'manage_wp_template_posts_custom_column', 'gutenberg_render_templates_lists_custom_column', 10, 2 ); -add_filter( 'views_edit-wp_template', 'gutenberg_filter_templates_edit_views' ); /** - * Sets a custom slug when creating auto-draft templates. - * This is only needed for auto-drafts created by the regular WP editor. - * If this page is to be removed, this won't be necessary. + * Finds whether a template or template part slug is customized for the currently active theme. * - * @param int $post_id Post ID. + * @param string $slug Template or template part slug. + * @param string $template_type wp_template or wp_template_part. + * + * @return bool Whether the template is customized for the currently active theme. */ -function set_unique_slug_on_create_template( $post_id ) { - $post = get_post( $post_id ); - if ( 'auto-draft' !== $post->post_status ) { - return; +function gutenberg_is_template_customized( $slug, $template_type = 'wp_template' ) { + $templates = get_theme_mod( $template_type, array() ); + + if ( ! isset( $templates[ $slug ] ) ) { + return false; } - if ( ! $post->post_name ) { - wp_update_post( - array( - 'ID' => $post_id, - 'post_name' => 'custom_slug_' . uniqid(), - ) - ); + $customized = get_post( $templates[ $slug ] ); + if ( $customized && $customized->post_type === $template_type ) { + return true; + } else { + return false; } +} - $terms = get_the_terms( $post_id, 'wp_theme' ); - if ( ! $terms || ! count( $terms ) ) { - wp_set_post_terms( $post_id, wp_get_theme()->get_stylesheet(), 'wp_theme' ); +/** + * Customizes a template or template part for the currently active theme. + * + * @param string $slug Template or template part identifier. + * @param int|WP_Post $post Post ID or object of customized template. + * @param bool $overwrite_slug Whether to overwrite existing slug. Default true. + * @param bool $overwrite_post Whether to overwrite existing post. Default true. + * + * @return string|null The identifier of the customized template, or null if the post is an invalid type. + */ +function gutenberg_customize_template( $slug, $post, $overwrite_slug = true, $overwrite_post = true ) { + $post = get_post( $post ); + if ( ! in_array( $post->post_type, array( 'wp_template', 'wp_template_part' ), true ) ) { + return null; } + + $templates = get_theme_mod( $post->post_type, array() ); + + while ( in_array( $post->ID, $templates, true ) ) { + $existing_slug = array_search( $post->ID, $templates, true ); + + if ( ! $overwrite_post || $existing_slug === $slug ) { + return $existing_slug; + } else { + unset( $templates[ $existing_slug ] ); + set_theme_mod( $post->post_type, $templates ); + } + } + + if ( ! $overwrite_slug && gutenberg_is_template_customized( $slug, $post->post_type ) ) { + $original_slug = $slug; + $suffix = 2; + do { + $slug = _truncate_post_slug( $original_slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix"; + $suffix++; + } while ( gutenberg_is_template_customized( $slug, $post->post_type ) ); + } + + $templates[ $slug ] = $post->ID; + set_theme_mod( $post->post_type, $templates ); + + return $slug; } -add_action( 'save_post_wp_template', 'set_unique_slug_on_create_template' ); /** * Print the skip-link script & styles. diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php index 8e1621f59cb54d..deb21556c96779 100644 --- a/packages/block-library/src/template-part/index.php +++ b/packages/block-library/src/template-part/index.php @@ -24,25 +24,14 @@ function render_block_core_template_part( $attributes ) { isset( $attributes['theme'] ) && wp_get_theme()->get_stylesheet() === $attributes['theme'] ) { - $template_part_id = $attributes['theme'] . '//' . $attributes['slug']; - $template_part_query = new WP_Query( - array( - 'post_type' => 'wp_template_part', - 'post_status' => 'publish', - 'post_name__in' => array( $attributes['slug'] ), - 'tax_query' => array( - array( - 'taxonomy' => 'wp_theme', - 'field' => 'slug', - 'terms' => $attributes['theme'], - ), - ), - 'posts_per_page' => 1, - 'no_found_rows' => true, - ) - ); - $template_part_post = $template_part_query->have_posts() ? $template_part_query->next_post() : null; - if ( $template_part_post ) { + $template_part_id = $attributes['theme'] . '//' . $attributes['slug']; + $ids = get_theme_mod( 'wp_template_part', array() ); + + if ( ! empty( $ids[ $attributes['slug'] ] ) ) { + $template_part_post = get_post( $ids[ $attributes['slug'] ] ); + } + + if ( $template_part_post && 'wp_template_part' === $template_part_post->post_type && 'publish' === $template_part_post->post_status ) { // A published post might already exist if this template part was customized elsewhere // or if it's part of a customized template. $content = $template_part_post->post_content; diff --git a/phpunit/class-block-templates-test.php b/phpunit/class-block-templates-test.php index f0ec20b7bd7b4a..634aa632d56115 100644 --- a/phpunit/class-block-templates-test.php +++ b/phpunit/class-block-templates-test.php @@ -17,54 +17,39 @@ public static function wpSetUpBeforeClass() { switch_theme( 'tt1-blocks' ); gutenberg_register_template_post_type(); gutenberg_register_template_part_post_type(); - gutenberg_register_wp_theme_taxonomy(); gutenberg_register_wp_template_part_area_taxonomy(); // Set up a template post corresponding to a different theme. // We do this to ensure resolution and slug creation works as expected, // even with another post of that same name present for another theme. + switch_theme( 'test-theme' ); $args = array( 'post_type' => 'wp_template', - 'post_name' => 'my_template', 'post_title' => 'My Template', 'post_content' => 'Content', 'post_excerpt' => 'Description of my template', - 'tax_input' => array( - 'wp_theme' => array( - 'this-theme-should-not-resolve', - ), - ), ); self::$post = self::factory()->post->create_and_get( $args ); - wp_set_post_terms( self::$post->ID, 'this-theme-should-not-resolve', 'wp_theme' ); + gutenberg_customize_template( 'my_template', self::$post, false ); // Set up template post. + switch_theme( 'tt1-blocks' ); $args = array( 'post_type' => 'wp_template', - 'post_name' => 'my_template', 'post_title' => 'My Template', 'post_content' => 'Content', 'post_excerpt' => 'Description of my template', - 'tax_input' => array( - 'wp_theme' => array( - get_stylesheet(), - ), - ), ); self::$post = self::factory()->post->create_and_get( $args ); - wp_set_post_terms( self::$post->ID, get_stylesheet(), 'wp_theme' ); + gutenberg_customize_template( 'my_template', self::$post, false ); // Set up template part post. $template_part_args = array( 'post_type' => 'wp_template_part', - 'post_name' => 'my_template_part', 'post_title' => 'My Template Part', 'post_content' => 'Content', 'post_excerpt' => 'Description of my template part', 'tax_input' => array( - 'wp_theme' => array( - get_stylesheet(), - ), 'wp_template_part_area' => array( WP_TEMPLATE_PART_AREA_HEADER, ), @@ -72,7 +57,7 @@ public static function wpSetUpBeforeClass() { ); self::$template_part_post = self::factory()->post->create_and_get( $template_part_args ); wp_set_post_terms( self::$template_part_post->ID, WP_TEMPLATE_PART_AREA_HEADER, 'wp_template_part_area' ); - wp_set_post_terms( self::$template_part_post->ID, get_stylesheet(), 'wp_theme' ); + gutenberg_customize_template( 'my_template_part', self::$template_part_post, false ); } public static function wpTearDownAfterClass() { diff --git a/phpunit/class-template-loader-test.php b/phpunit/class-template-loader-test.php index 5532c97015403d..288c6c9f45b540 100644 --- a/phpunit/class-template-loader-test.php +++ b/phpunit/class-template-loader-test.php @@ -29,18 +29,12 @@ public static function wpSetUpBeforeClass() { // Set up custom template post. $args = array( 'post_type' => 'wp_template', - 'post_name' => 'wp-custom-template-my-block-template', 'post_title' => 'My Custom Block Template', 'post_content' => 'Content', 'post_excerpt' => 'Description of my block template', - 'tax_input' => array( - 'wp_theme' => array( - get_stylesheet(), - ), - ), ); self::$post = self::factory()->post->create_and_get( $args ); - wp_set_post_terms( self::$post->ID, get_stylesheet(), 'wp_theme' ); + gutenberg_customize_template( 'wp-custom-template-my-block-template', self::$post, false ); } public static function wpTearDownAfterClass() {