-
Notifications
You must be signed in to change notification settings - Fork 0
/
EPFL_block_white_list.php
65 lines (58 loc) · 2.42 KB
/
EPFL_block_white_list.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
<?php
/*
* Plugin Name: EPFL block white list
* Plugin URI:
* Description: Must-use plugin for the EPFL website to define allowed blocks coming from Gutenberg or installed plugins.
* Version: 1.0.9
* Author: wwp-admin@epfl.ch
*/
function epfl_allowed_block_types( $allowed_block_types, $block_editor_context ) {
if ($allowed_block_types === false) {
// Look like we don't want any post, respect that
return $allowed_block_types;
}
/* List of blocks allowed only in Posts
NOTES:
- A block cannot be in both list at the same time.
- For EPFL blocks allowed in Posts, please have a look a wp-epfl-gutenberg plugin (plugin.php) file*/
$post_only_blocks = array(
'core/heading',
'core/image',
'core/file',
'core/list',
'core/spacer',
'core/separator',
'tadv/classic-paragraph');
$rest_of_allowed_blocks = array(
'core/classic',
'core/rss',
'core/shortcode',
'core/freeform',
'enlighter/codeblock',
// When WPForms is present, this allows to use it in the code block lookup UI (Tested in 5.7)
'wpforms/form-selector'
);
// In all cases post only blocks are allowed
if (is_array($allowed_block_types)) {
$allowed_block_types = array_merge($allowed_block_types, $post_only_blocks);
} else {
// case when it's the boolean one
$allowed_block_types = $post_only_blocks;
}
// If we're not editing a post, we all rest of allowed blocks.
if($block_editor_context->post->post_type != 'post')
{
$allowed_block_types = array_merge($allowed_block_types, $rest_of_allowed_blocks);
}
/* NOTE: Don't do an "array_unique()" to avoid duplicates. For an unknown reason, even if the array content seems to be correctly
filtered, the result will be that all blocks will be allowed, but ONLY on pages... not on posts... it's like the return of
"array_unique" function is "different" when the number of elements in the array is more than X ... */
return $allowed_block_types;
// return True; // if you want all natifs blocks.
}
// Gutenberg is on ?
if (function_exists( 'register_block_type' ) ) {
// We register this filter with priority 99 to ensure it will be called after the one (if present) added in Gutenberg plugin to
// register epfl blocks
add_filter( 'allowed_block_types_all', 'epfl_allowed_block_types', 99, 2 );
}