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

Post types not marked as "Supported Post Types" are forced to use the Classic Editor #135

Closed
1 task done
stormrockwell opened this issue Sep 19, 2023 · 2 comments · Fixed by #136
Closed
1 task done
Assignees
Labels
help wanted Extra attention is needed type:bug Something isn't working.
Milestone

Comments

@stormrockwell
Copy link

stormrockwell commented Sep 19, 2023

Describe the bug

The enable_block_editor method will remove block editor support from all post types not added to the settings page as a classic editor post type, regardless of how it is registered.

Not positive if this was intentional. For my use case, I am using this plugin on a Gutenberg site to convert migrated blog content to Gutenberg blocks instead of displaying the content as a classic block. I can check support for the custom post type, but it took awhile to debug since I didn't think this plugin would remove block editor support.

Steps to Reproduce

  1. Register a post type with editor support and show_in_rest set to true
  2. Ensure that post type isn't checked off in the "Convert to Blocks" settings page.
  3. Edit a post in that custom post type

Screenshots, screen recording, code snippet

Disables the block editor if the post type isn't added as a supported post type.

includes/ConvertToBlocks/ClassicEditorSupport.php 

/**
 * Disables the block editor if classic parameter is specified
 *
 * @param bool    $enabled The enabled state
 * @param WP_Post $post The current post
 * @return bool
 */
public function enable_block_editor( $enabled, $post ) {
	if ( ! $this->container->post_supports_convert_to_blocks( $post ) ) {
		return false;
	}

	if ( $this->container->has_classic_param() ) {
		return false;
	}

	return true;
}

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@stormrockwell stormrockwell added the type:bug Something isn't working. label Sep 19, 2023
@jeffpaul jeffpaul added the help wanted Extra attention is needed label Sep 20, 2023
@jeffpaul jeffpaul moved this from Incoming to To Do in Open Source Practice Sep 20, 2023
@stormrockwell
Copy link
Author

stormrockwell commented Sep 20, 2023

Also, there isn't an option for the "wp_block" post type so I needed to add a hook to override this feature. I couldn't use the post_type_supports_convert_to_blocks hook since it adds a notice on the backend.

If this is the direction you want to go, I don't mind making a pull request.


/**
 * Prevent converting a post to use the classic editor
 * 
 * The convert to blocks plugin will force all posts that aren't added to supported post types to use the classic editor. 
 * This will check if the post type supports the block editor and enable it if so.
 *
 * @param bool   $supports  Whether or not to enable to block editor.
 * @param string $post_id   WP post id.
 * @return bool
 */
function wex_prevent_convert_classic_editor( $supports, $post_id ) {
	$post_type = get_post_type( $post_id );
	if ( post_type_supports( $post_type, 'editor' ) ) {
		return true;
	}

	return $supports;
}

add_filter( 'post_supports_convert_to_blocks', 'wex_prevent_convert_classic_editor', PHP_INT_MAX, 2 );

@jeffpaul
Copy link
Member

@stormrockwell I confirmed with @dsawardekar and your approach seems good, so if you're able to work on a PR that would be great (ensuring that tests pass will be important on this improvement)... thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed type:bug Something isn't working.
Projects
Archived in project
2 participants