diff --git a/includes/create-theme/theme-patterns.php b/includes/create-theme/theme-patterns.php index da826f68..05948bb6 100644 --- a/includes/create-theme/theme-patterns.php +++ b/includes/create-theme/theme-patterns.php @@ -29,7 +29,6 @@ public static function pattern_from_wp_block( $pattern_post ) { $pattern->slug = wp_get_theme()->get( 'TextDomain' ) . '/' . $pattern->name; $pattern_category_list = get_the_terms( $pattern->id, 'wp_pattern_category' ); $pattern->categories = ! empty( $pattern_category_list ) ? join( ', ', wp_list_pluck( $pattern_category_list, 'name' ) ) : ''; - $pattern->sync_status = get_post_meta( $pattern->id, 'wp_pattern_sync_status', true ); $pattern->content = <<'; } - public static function replace_local_pattern_references( $pattern ) { + public static function replace_local_pattern_references( $pattern, $options = null ) { // Find any references to pattern in templates $templates_to_update = array(); $args = array( @@ -89,7 +88,7 @@ public static function replace_local_pattern_references( $pattern ) { $templates_to_update = array_unique( $templates_to_update ); // Only update templates that reference the pattern - CBT_Theme_Templates::add_templates_to_local( 'all', null, null, null, $templates_to_update ); + CBT_Theme_Templates::add_templates_to_local( 'all', null, null, $options, $templates_to_update ); // List all template and pattern files in the theme $base_dir = get_stylesheet_directory(); @@ -160,41 +159,38 @@ public static function add_patterns_to_theme( $options = null ) { $pattern = self::prepare_pattern_for_export( $pattern, $options ); $pattern_exists = false; - // Check pattern is synced before adding to theme. - if ( 'unsynced' !== $pattern->sync_status ) { - // Check pattern name doesn't already exist before creating the file. - $existing_patterns = glob( $patterns_dir . DIRECTORY_SEPARATOR . '*.php' ); - foreach ( $existing_patterns as $existing_pattern ) { - if ( strpos( $existing_pattern, $pattern->name . '.php' ) !== false ) { - $pattern_exists = true; - } - } - - if ( $pattern_exists ) { - return new WP_Error( - 'pattern_already_exists', - sprintf( - /* Translators: Pattern name. */ - __( - 'A pattern with this name already exists: "%s".', - 'create-block-theme' - ), - $pattern->name - ) - ); + // Check pattern name doesn't already exist before creating the file. + $existing_patterns = glob( $patterns_dir . DIRECTORY_SEPARATOR . '*.php' ); + foreach ( $existing_patterns as $existing_pattern ) { + if ( strpos( $existing_pattern, $pattern->name . '.php' ) !== false ) { + $pattern_exists = true; } + } - // Create the pattern file. - file_put_contents( - $patterns_dir . DIRECTORY_SEPARATOR . $pattern->name . '.php', - $pattern->content + if ( $pattern_exists ) { + return new WP_Error( + 'pattern_already_exists', + sprintf( + /* Translators: Pattern name. */ + __( + 'A pattern with this name already exists: "%s".', + 'create-block-theme' + ), + $pattern->name + ) ); + } - self::replace_local_pattern_references( $pattern ); + // Create the pattern file. + file_put_contents( + $patterns_dir . DIRECTORY_SEPARATOR . $pattern->name . '.php', + $pattern->content + ); - // Remove it from the database to ensure that these patterns are loaded from the theme. - wp_delete_post( $pattern->id, true ); - } + self::replace_local_pattern_references( $pattern, $options ); + + // Remove it from the database to ensure that these patterns are loaded from the theme. + wp_delete_post( $pattern->id, true ); } } } diff --git a/src/editor-sidebar/save-panel.js b/src/editor-sidebar/save-panel.js index 15d316e0..d126a5d2 100644 --- a/src/editor-sidebar/save-panel.js +++ b/src/editor-sidebar/save-panel.js @@ -158,9 +158,9 @@ export const SaveThemePanel = () => { />