MCPcopy Create free account
hub / github.com/WebDevStudios/wds-blocks / register_block

Function register_block

wds-blocks.php:29–103  ·  view source on GitHub ↗

* Register the block with WordPress. * * @author WebDevStudios * @since 2.0.0 */

()

Source from the content-addressed store, hash-verified

27 * @since 2.0.0
28 */
29function register_block() {
30
31 // Define our assets.
32 $editor_script = 'build/index.js';
33 $editor_style = 'build/index.css';
34 $frontend_style = 'build/style-index.css';
35 $frontend_script = 'build/frontend.js';
36
37 // Verify we have an editor script.
38 if ( ! file_exists( plugin_dir_path( __FILE__ ) . $editor_script ) ) {
39 wp_die( esc_html__( 'Whoops! You need to run `npm run build` for the WDS Block Starter first.', 'wdsblocks' ) );
40 }
41
42 // Autoload dependencies and version.
43 $asset_file = require plugin_dir_path( __FILE__ ) . 'build/index.asset.php';
44
45 // Register editor script.
46 wp_register_script(
47 'wdsblocks-editor-script',
48 plugins_url( $editor_script, __FILE__ ),
49 $asset_file['dependencies'],
50 $asset_file['version'],
51 true
52 );
53
54 // Register editor style.
55 if ( file_exists( plugin_dir_path( __FILE__ ) . $editor_style ) ) {
56 wp_register_style(
57 'wdsblocks-editor-style',
58 plugins_url( $editor_style, __FILE__ ),
59 [ 'wp-edit-blocks' ],
60 filemtime( plugin_dir_path( __FILE__ ) . $editor_style )
61 );
62 }
63
64 // Register frontend style.
65 if ( file_exists( plugin_dir_path( __FILE__ ) . $frontend_style ) ) {
66 wp_register_style(
67 'wdsblocks-style',
68 plugins_url( $frontend_style, __FILE__ ),
69 [],
70 filemtime( plugin_dir_path( __FILE__ ) . $frontend_style )
71 );
72 }
73
74 // Register blocks with WordPress.
75 register_block_type(
76 'wdsblocks/carousel',
77 [
78 'editor_script' => 'wdsblocks-editor-script',
79 'editor_style' => 'wdsblocks-editor-style',
80 'style' => 'wdsblocks-style',
81 ]
82 );
83
84 register_block_type(
85 'wdsblocks/carousel-slide',
86 [

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected