How to keep the capability of users and disable Gutenberg editor in WordPress?

The question:

I disabled Gutenberg web builder/ editor using the following code:

add_filter( 'use_block_editor_for_post', '__return_false' );

Somehow this impacted contributor’s capability to submit post for review, now contributor’s posts are not asking any approval. I tried to remove the capability manually, by writing this code,

$role->remove_cap( 'publish_posts' );

but this code also has no effect at all.

It seems a WordPress bug, any suggestion?? It’s showing the same results with https://wordpress.org/plugins/classic-editor/ plugin too.

How to keep the capability of users and disable Gutenberg editor in WordPress?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

add these lines in your ‘functions.php’, it will work

//if not gutenberg reapprove posts
add_filter( 'wp_insert_post_data', 're_aprove', '99', 2 );
function re_aprove( $data, $postarr ) {
    //check if current user is not admin
    if ( ! current_user_can( 'manage_options' ) ) {
        if ( 'publish' === $data['post_status'] ) {
            $data['post_status'] = 'pending';
        }
    }
    return $data;
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment