Make WordPress Core

Opened 10 days ago

Last modified 9 days ago

#46195 new defect (bug)

is_block_editor() returns false in the block editor

Reported by: Chouby Owned by:
Milestone: 5.1.1 Priority: normal
Severity: normal Version: 5.0
Component: Editor Keywords: has-patch needs-testing
Focuses: administration Cc:


The current_screen action is supposed to be fired after the necessary elements to identify a screen are set up. So I would expect that $screen->is_block_editor() returns the right value in a function hooked to current_screen. But in fact $screen->is_block_editor() always return false even if are in the block editor.

That's because the property is_block_editor is set much later, after current_screen action is fired.

This small code snippet allows to reproduce the issue:

add_action( 'current_screen', function( $screen ) {
  error_log( var_export( $screen->is_block_editor(), true ) );
} );

Attachments (2)

46195.diff (2.1 KB) - added by desrosj 10 days ago.
46195.2.diff (2.3 KB) - added by Chouby 9 days ago.

Download all attachments as: .zip

Change History (5)

#1 @desrosj
10 days ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.1.1

Thanks for this, @Chouby! I am going to milestone this for 5.1.1 as this would be too late in the 5.1 timeline with RC set for tomorrow.

I have a patch incoming that will fix the issue, but it needs to be well tested for any adverse effects.

10 days ago

#2 @desrosj
10 days ago

  • Focuses administration added
  • Keywords has-patch needs-testing added; needs-patch removed

46195.diff moves the logic that sets the is_block_editor property into the WP_Screen::get() method so it is properly set when the current_screen action is triggered.

I tested with the Classic Editor plugin active, and all the different combinations of plugin/user settings and user flows and each scenario worked correctly for me.

9 days ago

#3 @Chouby
9 days ago

I tested the patch and, for me, it doesn't work for new posts. Because the post ID is created later in post-new.php. 46195.2.diff aims to fix this.

However this is not fully backward compatible as use_block_editor_for_post_type won't honor the filter use_block_editor_for_post for new posts.

Note: See TracTickets for help on using tickets.