This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
wds-block-starter.php
92 lines (81 loc) · 2.42 KB
/
wds-block-starter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Plugin Name: WDS Block Starter
* Plugin URI: https://github.com/WebDevStudios/wds-block-starter
* Description: A block starter for WebDevStudios projects.
* Author: WebDevStudios
* Author URI: https://webdevstudios.com
* Version: 1.1.1
* License: GPLv3
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: wdsbs
* Domain Path: /languages
*
* @package WebDevStudios\BlockStarter
* @since 0.0.1
*/
namespace WebDevStudios\BlockStarter;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/**
* Register the block with WordPress.
*
* @author WebDevStudios
* @since 0.0.1
*/
function register_block() {
// Define our assets.
$editor_script = 'build/index.js';
$editor_style = 'build/index.css';
$frontend_style = 'build/style-index.css';
$frontend_script = 'build/frontend.js';
// Verify we have an editor script.
if ( ! file_exists( plugin_dir_path( __FILE__ ) . $editor_script ) ) {
wp_die( esc_html__( 'Whoops! You need to run `npm run build` for the WDS Block Starter first.', 'wdsbs' ) );
}
// Autoload dependencies and version.
$asset_file = require plugin_dir_path( __FILE__ ) . 'build/index.asset.php';
// Register editor script.
wp_register_script(
'wdsbs-editor-script',
plugins_url( $editor_script, __FILE__ ),
$asset_file['dependencies'],
$asset_file['version'],
true
);
// Register editor style.
if ( file_exists( plugin_dir_path( __FILE__ ) . $editor_style ) ) {
wp_register_style(
'wdsbs-editor-style',
plugins_url( $editor_style, __FILE__ ),
[ 'wp-edit-blocks' ],
filemtime( plugin_dir_path( __FILE__ ) . $editor_style )
);
}
// Register frontend style.
if ( file_exists( plugin_dir_path( __FILE__ ) . $frontend_style ) ) {
wp_register_style(
'wdsbs-style',
plugins_url( $frontend_style, __FILE__ ),
[],
filemtime( plugin_dir_path( __FILE__ ) . $frontend_style )
);
}
// Register block with WordPress.
register_block_type( 'wdsbs/rich-text-demo', array(
'editor_script' => 'wdsbs-editor-script',
'editor_style' => 'wdsbs-editor-style',
'style' => 'wdsbs-style',
) );
// Register frontend script.
if ( file_exists( plugin_dir_path( __FILE__ ) . $frontend_script ) ) {
wp_enqueue_script(
'wdsbs-frontend-script',
plugins_url( $frontend_script, __FILE__ ),
$asset_file['dependencies'],
$asset_file['version'],
true
);
}
}
add_action( 'init', __NAMESPACE__ . '\register_block' );