Last active
March 19, 2019 11:35
-
-
Save N-Molham/eec52b5ff2728eadd6c611d046d3e41b to your computer and use it in GitHub Desktop.
WordPress: Allow Gutenberg for specific user roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'use_block_editor_for_post', 'my_prefix_maybe_allow_block_editor', 20, 2 ); | |
/** | |
* @see https://core.trac.wordpress.org/browser/tags/5.1.1/src/wp-admin/includes/post.php#L2093 | |
* | |
* @param bool $use_block_editor | |
* @param string $post_type | |
* | |
* @return bool | |
*/ | |
function my_prefix_maybe_allow_block_editor( $use_block_editor, $post_type ) { | |
// if you want to disable block editor for specific post types | |
$use_block_editor = in_array( $post_type, [ 'post', 'custom-post-type', // .... ], true ); | |
// disable block editor if logged in user isn't an Administrator (user role) | |
// @see https://codex.wordpress.org/Function_Reference/current_user_can | |
$use_block_editor = current_user_can( 'administrator' ); | |
return $use_block_editor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment