Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Created April 27, 2019 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/d6dfcf2770872669628a7343665c0bff to your computer and use it in GitHub Desktop.
Save pbrocks/d6dfcf2770872669628a7343665c0bff to your computer and use it in GitHub Desktop.
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