Skip to content

WDS BT v1.3.5 - Dynamic Block Pattern Category Registration

Latest
Compare
Choose a tag to compare
@khleomix khleomix released this 18 Jul 15:15
8d97f14

Release Notes: Dynamic Block Pattern Category Registration

New Features:

Automatic Pattern Category Registration

  • The theme now automatically registers block pattern categories based on subfolders in the patterns/ directory.
  • How it works:
    • Any subfolder you add to patterns/ (e.g., patterns/cards/, patterns/hero/) will be registered as a block pattern category.
    • The folder name is used as the category slug, and a human-friendly label is generated for the block editor.
    • Pattern files placed in these subfolders and using the correct Categories header (matching the folder name) will appear in the block editor under the appropriate category.
  • No manual code changes are needed to add new pattern categories—just add a subfolder to patterns/.
  • How to use:
    1. Create a new subfolder inside patterns/ (e.g., patterns/cards/).
    2. Place your pattern PHP files in that subfolder.
    3. In each pattern file, set the Categories header to the folder name (e.g., Categories: cards).
    4. The new category will appear in the block editor, and your patterns will be listed under it.

Flush Object Cache and Transients

  • Added a "Flush Object Cache and Transients" button to the Theme Options page (Tools > WDSBT Settings).
  • When used, this button:
    • Unregisters all custom block patterns and re-registers pattern categories.
      • This would not force a full rescan of the /patterns folder which would automatically show the new pattern category.
      • Switching themes is the only 100% reliable way to force a full re-scan of the /patterns folder.
      • Flushing all caches and transients, and hard refreshing, are the next best options.
      • There is no official WordPress function to force this without a theme switch.
    • Flushes the WordPress object cache and deletes all transients to help ensure new code and/or style changes appear as soon as possible in the block editor.
    • Injects a JavaScript event to notify open block editor tabs to refresh their pattern/category cache.
    • Displays a clear admin notice explaining WordPress’s caching limitations and that a theme switch or full cache clear may still be required for new categories to appear immediately.
  • How to use:
    1. Add or update patterns/categories in your theme’s /patterns folder.
    2. Go to Tools > WDSBT Settings in the WordPress admin.
    3. Click the "Flush Object Cache and Transients" button.
    4. Reload the block editor to see new patterns/categories, or follow the admin notice instructions if they do not appear immediately.

Important:
Due to WordPress core caching, new pattern categories may not appear immediately after a flush.
If you do not see your new categories:

  • Try switching to another theme and then back to your theme, or
  • Wait several minutes for caches to expire, or
  • Clear all object caches and browser caches.

This is a WordPress limitation and does not affect production sites where patterns/categories are set before launch.