-
Notifications
You must be signed in to change notification settings - Fork 18
/
block-experiments.php
119 lines (106 loc) · 2.57 KB
/
block-experiments.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Plugin Name: Block Experiments
* Plugin URI: https://github.com/automattic/block-experiments
* Description: A set of block experiments from the fine folks at Automattic
* Version: 1.0.0
* Author: Automattic
* Author URI: https://automattic.com
* Text Domain: block-experiments
* License: GPL v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// Auto-load any blocks in the block directory. These will behave like seperate plugins and will need to activate themselves
$blocks = glob( dirname( __FILE__ ) . '/blocks/*', GLOB_ONLYDIR );
foreach ( $blocks as $block ) {
if ( file_exists( $block . '/index.php' ) ) {
include_once( $block . '/index.php' );
}
}
add_action( 'init', function() {
add_filter( 'wp_kses_allowed_html', function( $tags ) {
$tags['svg'] = [
'xmlns' => [],
'fill' => [],
'role' => [],
'aria-hidden' => [],
'focusable' => [],
'style' => [],
'height' => [],
'width' => [],
'viewbox' => [],
'preserveaspectratio' => [],
];
$tags['path'] = [
'class' => [],
'd' => [],
'opacity' => [],
'fill' => [],
'fillrule' => [],
'fillopacity' => [],
'transform' => [],
'stroke' => [],
];
$tags['rect'] = [
'd' => [],
'opacity' => [],
'fill' => [],
'fillrule' => [],
'transform' => [],
'width' => [],
'height' => [],
'y' => [],
];
$tags['circle'] = [
'class' => [],
'cx' => [],
'cy' => [],
'r' => [],
];
$tags['polygon'] = [
'points' => [],
'fill' => [],
];
$tags['iframe'] = [
'title' => [],
'allowfullscreen' => [],
'frameborder' => [],
'width' => [],
'height' => [],
'src' => [],
];
return $tags;
}, 10, 2);
$asset_file = plugin_dir_path( __FILE__ ) . 'build/index.asset.php';
$asset = file_exists( $asset_file )
? require_once $asset_file
: null;
$dependencies = isset( $asset['dependencies'] ) ?
$asset['dependencies'] :
[];
$version = isset( $asset['version'] ) ?
$asset['version'] :
filemtime( plugin_dir_path( __FILE__ ) . 'build/index.js' );
// Block JS
wp_register_script(
'block-experiments',
plugins_url( 'build/index.js', __FILE__ ),
$dependencies,
$version,
true
);
// Block front end style
wp_register_style(
'block-experiments',
plugins_url( 'build/style.css', __FILE__ ),
[],
filemtime( plugin_dir_path( __FILE__ ) . 'build/style.css' )
);
// Block editor style
wp_register_style(
'block-experiments-editor',
plugins_url( 'build/editor.css', __FILE__ ),
[],
filemtime( plugin_dir_path( __FILE__ ) . 'build/editor.css' )
);
} );