Skip to content

Commit a905d77

Browse files
Remove double code so we do not register blocks multiple times and no need to check if registered
1 parent 1c23010 commit a905d77

File tree

4 files changed

+7
-35
lines changed

4 files changed

+7
-35
lines changed

blocks/cta/build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => '57c7719cdb817101777b');
1+
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-i18n'), 'version' => 'cf68f46bdd87bb727410');

blocks/cta/build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blocks/cta/src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
55
*/
6-
import { registerBlockType } from '@wordpress/blocks';
6+
import { registerBlockType, getBlockType } from '@wordpress/blocks';
77

88
/**
99
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
@@ -27,13 +27,13 @@ import metadata from './block.json';
2727
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
2828
*/
2929
registerBlockType( metadata.name, {
30-
/**
30+
/**
3131
* @see ./edit.js
3232
*/
33-
edit: Edit,
33+
edit: Edit,
3434

35-
/**
35+
/**
3636
* @see ./save.js
3737
*/
38-
save,
38+
save,
3939
} );

inc/hooks/native-gutenberg-blocks.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,3 @@ function register_native_gutenberg_blocks() {
4545
}
4646
}
4747
add_action( 'init', __NAMESPACE__ . '\register_native_gutenberg_blocks' );
48-
49-
/**
50-
* Enqueue all native block assets
51-
*/
52-
function enqueue_block_editor_assets() {
53-
// Get all block asset files
54-
$blocks_dir = get_theme_file_path( '/blocks' );
55-
$block_folders = array_filter( glob( $blocks_dir . '/*' ), 'is_dir' );
56-
57-
foreach ( $block_folders as $block_folder ) {
58-
$block_name = basename( $block_folder );
59-
$asset_file = get_theme_file_path( "blocks/{$block_name}/build/index.asset.php" );
60-
61-
if ( file_exists( $asset_file ) ) {
62-
$asset = require $asset_file;
63-
64-
wp_enqueue_script(
65-
"air-light-{$block_name}",
66-
get_theme_file_uri( "blocks/{$block_name}/build/index.js" ),
67-
$asset['dependencies'] ?? [ 'wp-blocks', 'wp-element', 'wp-editor' ],
68-
$asset['version'] ?? filemtime( get_theme_file_path( "blocks/{$block_name}/build/index.js" ) ),
69-
true
70-
);
71-
}
72-
}
73-
}
74-
75-
add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_block_editor_assets' );

0 commit comments

Comments
 (0)