Skip to content

Stop deleting synced pattern #858

Open

Description

@nextgenthemes

Create Block Theme: 2.10.1
WP 7.0

I just learned that WP does not even have the ability to store synced pattern into a file. Why? Would be basically the same as a template part?

But you can not insert a template part into a page content area from the inserter UI right? Not sure what the reason is why a synced pattern can not be read from a file but apparently if AI is not hallucinating this is not a thing.

This plugin rudely deletes the synced patterns leaving behind a "Block has been deleted or is unavailable." in their place.

Instead, after saving the pattern to a file (fine), the database version should just NOT be deleted if the pattern is synced.

Activity

  1. jasalt commented on Jul 24, 2026

    @jasalt

    I had trouble with this also as I use Create Block Theme plugin to persist theme changes in filesystem for git based workflow.

    The plugin is not migrating the Block Pattern references in posts when saving, and as it removes the Block Pattern rows from database the posts are left to pointing missing IDs. Only the references in templates seem to be migrated, as also stated in the plugin UI.

    @nextgenthemes You can try avoid the issue in the first place by disabling the Save Patterns before saving:

    Image

    Would [Block Pattern] be basically the same as a template part?

    Template Parts are more tied to templating in block themes while Block Patterns are more general and can also be used in class posts, this makes Block Patterns somewhat more complicated. While block templates can be saved into files, posts cannot, and Block Patterns need to handle both cases.

  2. jasalt commented on Jul 24, 2026

    @jasalt

    To make workaround this and fix some broken Block Pattern references on a production site pages due to this, I made WP-CLI utility based on Create Block Theme https://github.com/jasalt/wpcli-create-block-theme.

    It should handle the Block Pattern reference re-mapping in posts when running save command, wp create-block-theme save being equivalent to the "Save Changes to Theme" with default options in the block editor plugin UI. You can try let your AI agent use it to diagnose and fix the situation in development environment, starting by making database backup and running wp create-block-theme pattern-refs check.

    Regarding fixing the underlying issue natively in the CBT plugin, I left Pi & gpt-5.6-sol generated root cause analysis of the issue here https://github.com/jasalt/wpcli-create-block-theme/blob/master/cbt-block-pattern-issue-rca.md. I don't have opportunity to dig deeper into it at the moment myself but will keep updating my workaround while working on sites.

  3. nextgenthemes commented on Jul 24, 2026

    @nextgenthemes
    Author

    @jasalt No, the entire purpose of this plugin for me and most people I guess is to save the pattern so they can then edit/ship them as files. This is what I am WANT. Disabling this core function is no solution at all for me. I stopped using this because if this.

    Like is said, because WordPress has no concept of synced pattern as files, and there or probably good technical reason for this, what I said was just my quick though, I have not really digged deep into that part of WP.

    It's not supposed to break content. For normal pattern is works fine as It's supposed to, delete, reload from file = same result.

    Should not be hard to figure out how to detect a synced pattern before the deletion happens. I just flew over your comments, do not really get your AI stuff. Why would I need some complex AI analytics for this?

    "How to detect a synced pattern on WordPress from code" on Brave Search Ask (free, no real 'agent')

    Untested!

    function is_pattern_synced( $pattern_id ) {
        // Ensure the post exists and is a wp_block type
        $post = get_post( $pattern_id );
        if ( ! $post || $post->post_type !== 'wp_block' ) {
            return false;
        }
    
        // Get the sync status meta
        $sync_status = get_post_meta( $pattern_id, 'wp_pattern_sync_status', true );
    
        // If the meta is 'unsynced', it is NOT synced. Otherwise, it is synced.
        if ( $sync_status === 'unsynced' ) {
            return false; // Not synced
        }
    
        return true; // Synced
    }
    
    // Usage Example
    $pattern_id = 123; // Replace with your pattern ID
    if ( is_pattern_synced( $pattern_id ) ) {
        echo "This is a synced pattern. Changes will update globally.";
    } else {
        echo "This is a non-synced pattern.";
    }   

    Something like this, should just prevent deletion if synced patterns. Needs no top AI agent. Could use one to put it in the right place for sure.

    CLI command is cool, maybe I try it out later. I am doing nushell stuff ATM

  4. nextgenthemes commented on Jul 24, 2026

    @nextgenthemes
    Author

    @jasalt Ahh you think I have a page with a lot of broken patterns now? I don't, thankfully I did this on my dev site only, so I do not need to find them.

  5. jasalt commented on Jul 24, 2026

    @jasalt

    @nextgenthemes A-ha. I see your different angle.

    I don't have much experience with WP patterns, mainly building site block themes using only template parts and custom blocks, but this issue came up on site with content editors having done stuff with patterns that my "Save to block theme" action broke. I was forced to move work without Site Editor as after having added some more ACF/SCF meta fields to already complex site opening The Site Editor effectively DOS'd the server down with 400+ requests.

    I've been on edge of moving all FSE projects to classic themes/Timber for a while for multiple reasons, but to me being able to use code editor and version control system with layout building while also allowing users do some template changes via WYSIWYG editor would be interesting middle ground for certain projects so I haven't given up on it yet.

    Glad you don't have sites broken due to it. Official CLI for saving should also be coming soon to this plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions