I have found a article about this filter but I am supposed to pass a array of allowed blocks to it. This is what I got so far that ddd
is my debugging function from Kint Debugger it reveals that the $allowed_blocks
contains a bool true
value rather then a array of all blocks I expected. So where do I get a array of all blocks? What a horrible WP API.
add_filter( 'allowed_block_types', __NAMESPACE__ . '\remove_core_video_blocks' );
function remove_core_video_blocks( $allowed_blocks ) {
#ddd($allowed_blocks);
$allowed_blocks = array_diff( $allowed_blocks, [ 'core-embed/youtube' ] );
return $allowed_blocks;
}
I tried
return array(
'core/image',
'core/paragraph',
'core/heading',
'core/list'
);
and that disabled the Block UI but the YouTube block I already had in the post continues to work so I guess the filter does what I am looking for I just need a array of all blocks at that point.
I have found a article about this filter but I am supposed to pass a array of allowed blocks to it. This is what I got so far that ddd
is my debugging function from Kint Debugger it reveals that the $allowed_blocks
contains a bool true
value rather then a array of all blocks I expected. So where do I get a array of all blocks? What a horrible WP API.
add_filter( 'allowed_block_types', __NAMESPACE__ . '\remove_core_video_blocks' );
function remove_core_video_blocks( $allowed_blocks ) {
#ddd($allowed_blocks);
$allowed_blocks = array_diff( $allowed_blocks, [ 'core-embed/youtube' ] );
return $allowed_blocks;
}
I tried
return array(
'core/image',
'core/paragraph',
'core/heading',
'core/list'
);
and that disabled the Block UI but the YouTube block I already had in the post continues to work so I guess the filter does what I am looking for I just need a array of all blocks at that point.
Found a JavaScript solution. If I remember correctly there was some talk about temporary solution this or related Github issues so keep that in mind. But I guess this means only server side so for only UI hiding I guess this will be fine.
const wp = window.wp; // when using webpack
wp.data.dispatch( 'core/edit-post' ).hideBlockTypes( [
'core-embed/youtube',
'core-embed/vimeo',
'core-embed/dailymotion',
'core-embed/collegehumor',
'core-embed/ted',
] );
Also found some wrong PHP code that I fixed but its still not working correctly as the array does not contain all blocks.
add_filter( 'allowed_block_types', __NAMESPACE__ . '\remove_core_video_blocks' );
function remove_core_video_blocks( $allowed_blocks ) {
$guten_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered();
foreach ( $guten_blocks as $key => $value) {
$registered_blocks[] = $key;
}
$allowed_blocks = array_diff(
$registered_blocks, // NOTE registered blocks does NOT contains all blocks
array( 'wp-embed/youtube' )
);
return $allowed_blocks;
}