Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Restrict Access filters for WordPress Blocks
<?php
function my_restrict_post_filter( $use_block_editor, $post ) {
$author = get_userdata( $post->post_author );
if ( 'pento' === $author->user_login ) {
return (bool) random_int( 0, 1 );
}
return $use_block_editor;
}
add_filter( 'use_block_editor_for_post', 'my_restrict_post_filter', 10, 2 );
function my_restrict_post_type_filter( $use_block_editor, $post_type ) {
if ( 'my_mystical_post_type' === $post_type ) {
return false;
}
return $use_block_editor;
}
add_filter( 'use_block_editor_for_post_type', 'my_restrict_post_type_filter', 10, 2 );
// Block Filter reference
// https://wordpress.stackexchange.com/questions/308021/add-custom-class-to-core-blocks-in-gutenberg?answertab=active#tab-top
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.