Fix WP Bakery Disabling Gutenberg with Classic Editor Enabled

There’s currently a bug in WP Bakery (version 6.0.5) that enables or disables the block editor, Gutenberg, for an entire post type based on a single post on the various “All [Post Type]” admin screens.

You’ve probably noticed this if you’ve installed the Classic Editor plugin and have switching editors enabled. You’d expect to be able to select which editor to use for a post from the “All [Post Type]” screen when WP Bakery isn’t active for that post. Instead, you see that you can only use the classic editor, even though the WP Bakery page builder isn’t active on the post in question.

In such a situation, if you look at the first post in the list, it should be one that does have WP Bakery active. It has the block editor properly disabled, but unfortunately, has locked all the other posts in this list as well.

The opposite will also prove true. If the first post in the list has both editors available, then posts later in the list that are using WP Bakery and should only have the classic editor available will incorrectly show you the “Edit (Block Editor)” option.

The fix involves removing their post-specific check from the post-type specific filter, and re-implementing it back on the Classic Editor’s per-post filter, ensuring the proper editors are available on the proper posts. Code below.

<?php /** * WPBakery messed up this logic. * Remove and re-implement */ remove_filter( 'use_block_editor_for_post_type', 'vc_gutenberg_check_disabled' ); add_filter( 'use_block_editor_for_post_type', 'vc_gutenberg_check_post_type_disabled', 10, 2 ); add_filter( 'classic_editor_enabled_editors_for_post', 'vc_gutenberg_check_post_disabled', 10, 2 ); /** * WP Bakery uses `get_post` in their implementation of the below. * We'll be more explicit but use the same logic. * * @param $post A WP_Post object * * @return bool */ function vc_is_wpb_content_with_arg($post) { if ( ! empty( $post ) && isset( $post->post_content ) && preg_match( '/\[vc_row/', $post->post_content ) ) { return true; } return false; } /** * We've removed the per-post check from our implementation of this. * * @param $result Whether Gutenberg should be disabled for this post type * @param $postType The post type * * @return bool */ function vc_gutenberg_check_post_type_disabled( $result, $postType ) { if ( 'wpb_gutenberg_param' === $postType ) { return true; } if ( ! isset( $_GET['vcv-gutenberg-editor'] ) && ( get_option( 'wpb_js_gutenberg_disable' ) || isset( $_GET['classic-editor'] ) ) ) { return false; } return $result; } /** * We've moved the per-post check into this function, hooked to * a more appropriate filter. * * @param $editors An array of editors and whether they're enabled or disabled * @param $post A WP_Post * * @return array */ function vc_gutenberg_check_post_disabled( $editors, $post ) { if(vc_is_wpb_content_with_arg($post)) { $editors['block_editor'] = false; } return $editors; }
Code language: HTML, XML (xml)

Leave a Reply

Your email address will not be published. Required fields are marked *