Skip to content

Instantly share code, notes, and snippets.

@proweb
Created July 20, 2023 10:40
Show Gist options
  • Save proweb/c7419ea89e08ab595da8114485dcfdd0 to your computer and use it in GitHub Desktop.
Save proweb/c7419ea89e08ab595da8114485dcfdd0 to your computer and use it in GitHub Desktop.

Revisions

  1. proweb created this gist Jul 20, 2023.
    18 changes: 18 additions & 0 deletions plugin.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <?php

    /**
    * Automatically registers block types by scanning the build/blocks folder.
    *
    * This function searches for JSON files within each subfolder and registers
    * them as block types. It is triggered on WordPress 'init' action.
    */
    function auto_register_block_types() {
    if ( file_exists( __DIR__ . '/build/blocks/' ) ) {
    $block_json_files = glob( __DIR__ . '/build/blocks/*/block.json' );
    foreach ( $block_json_files as $filename ) {
    $block_folder = dirname( $filename );
    register_block_type( $block_folder );
    }
    }
    }
    add_action( 'init', 'auto_register_block_types' );