Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'gutenberg_can_edit_post' filter #6974

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,20 +257,32 @@ function gutenberg_collect_meta_box_data() {
*/
function gutenberg_can_edit_post( $post ) {
$post = get_post( $post );
$can_edit = true;

if ( ! $post ) {
return false;
$can_edit = false;
}

if ( 'trash' === $post->post_status ) {
return false;
$can_edit = false;
}

if ( ! gutenberg_can_edit_post_type( $post->post_type ) ) {
return false;
$can_edit = false;
}

return current_user_can( 'edit_post', $post->ID );
if( ! current_user_can( 'edit_post', $post->ID ) ) {
$can_edit = false;
}

/**
* Filter to allow plugins to enable/disable Gutenberg for particular posts.
*
*
* @param bool $can_edit Whether the post can be edited or not.
* @param string $post The post being checked.
*/
return apply_filters( 'gutenberg_can_edit_post', $can_edit, $post );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is a duplicate of the replace_editor filter since Gutenberg is supposed to be used in all posts by default which means if you need to provide an alternative editor, you'd use the existing filter for that replace_editor instead of using a new filter with the same purpose.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, noted. I wasn't aware of that.

}

/**
Expand Down