<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[45224] trunk: Administration: Improve the accuracy of `is_block_editor()`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/45224">45224</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/45224","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>desrosj</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2019-04-17 01:55:21 +0000 (Wed, 17 Apr 2019)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Administration: Improve the accuracy of `is_block_editor()`.

Currently, there are a number of scenarios where `is_block_editor()` (and `WP_Screen::is_block_editor`) would incorrectly indicate block editor support at different points of the loading process. Most notably, checking `is_block_editor` when hooking into the `current_screen` action will always result in `false`, even when the block editor is being loaded. This is because `is_block_editor` is not set to `true` until `edit-form-blocks.php` is included.

This change adds logic to `WP_Screen` to ensure the accuracy of `is_block_editor` on block editor pages earlier in the load process.

While edit screens will now be accurate 100% of the time from `current_screen` on, there are still a few edge cases where `is_block_editor` could contain an incorrect value when creating a new post.

Because a `WP_Post` object is a required parameter for the `replace_editor` filter and `use_block_editor_for_post()` function, `WP_Screen` will fall back to the value returned by `use_block_editor_for_post_type()` for the post being created. To eliminate these edge cases, the `use_block_editor_for_post_type` filter can be used to return the appropriate boolean value to indicate support.

Props Chouby, desrosj, aduth, johnbillion.
Fixes <a href="https://core.trac.wordpress.org/ticket/46195">#46195</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmineditformadvancedphp">trunk/src/wp-admin/edit-form-advanced.php</a></li>
<li><a href="#trunksrcwpadminincludesclasswpscreenphp">trunk/src/wp-admin/includes/class-wp-screen.php</a></li>
<li><a href="#trunksrcwpadminpostnewphp">trunk/src/wp-admin/post-new.php</a></li>
<li><a href="#trunktestsphpunittestsadminincludesScreenphp">trunk/tests/phpunit/tests/admin/includesScreen.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmineditformadvancedphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/edit-form-advanced.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/edit-form-advanced.php 2019-04-17 01:09:30 UTC (rev 45223)
+++ trunk/src/wp-admin/edit-form-advanced.php   2019-04-17 01:55:21 UTC (rev 45224)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -18,6 +18,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> global $post_type, $post_type_object, $post;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Flag that we're not loading the block editor.
+$current_screen = get_current_screen();
+$current_screen->is_block_editor( false );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_multisite() ) {
</span><span class="cx" style="display: block; padding: 0 10px">        add_action( 'admin_footer', '_admin_notice_post_locked' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span></span></pre></div>
<a id="trunksrcwpadminincludesclasswpscreenphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/class-wp-screen.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/class-wp-screen.php   2019-04-17 01:09:30 UTC (rev 45223)
+++ trunk/src/wp-admin/includes/class-wp-screen.php     2019-04-17 01:55:21 UTC (rev 45224)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -202,9 +202,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return $hook_name;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $post_type = $taxonomy = null;
-               $in_admin  = false;
-               $action    = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $post_type       = $taxonomy = null;
+               $in_admin        = false;
+               $action          = '';
+               $is_block_editor = false;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $hook_name ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $id = $hook_name;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -294,6 +295,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                $post = get_post( $post_id );
</span><span class="cx" style="display: block; padding: 0 10px">                                                if ( $post ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $post_type = $post->post_type;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                                                       /** This filter is documented in wp-admin/post.php */
+                                                       $replace_editor = apply_filters( 'replace_editor', false, $post );
+
+                                                       if ( ! $replace_editor ) {
+                                                               $is_block_editor = use_block_editor_for_post( $post );
+                                                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 }
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px">                                        break;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -314,6 +322,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( null === $post_type ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        $post_type = 'post';
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               // When creating a new post, use the default block editor support value for the post type.
+                               if ( empty( $post_id ) ) {
+                                       $is_block_editor = use_block_editor_for_post_type( $post_type );
+                               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $id = $post_type;
</span><span class="cx" style="display: block; padding: 0 10px">                                break;
</span><span class="cx" style="display: block; padding: 0 10px">                        case 'edit':
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -357,13 +371,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $screen->id = $id;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $screen->base       = $base;
-               $screen->action     = $action;
-               $screen->post_type  = (string) $post_type;
-               $screen->taxonomy   = (string) $taxonomy;
-               $screen->is_user    = ( 'user' == $in_admin );
-               $screen->is_network = ( 'network' == $in_admin );
-               $screen->in_admin   = $in_admin;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $screen->base            = $base;
+               $screen->action          = $action;
+               $screen->post_type       = (string) $post_type;
+               $screen->taxonomy        = (string) $taxonomy;
+               $screen->is_user         = ( 'user' == $in_admin );
+               $screen->is_network      = ( 'network' == $in_admin );
+               $screen->in_admin        = $in_admin;
+               $screen->is_block_editor = $is_block_editor;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                self::$_registry[ $id ] = $screen;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunksrcwpadminpostnewphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/post-new.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/post-new.php   2019-04-17 01:09:30 UTC (rev 45223)
+++ trunk/src/wp-admin/post-new.php     2019-04-17 01:55:21 UTC (rev 45224)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -74,6 +74,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                wp_enqueue_script( 'autosave' );
</span><span class="cx" style="display: block; padding: 0 10px">                include( ABSPATH . 'wp-admin/edit-form-advanced.php' );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+} else {
+       // Flag that we're not loading the block editor.
+       $current_screen = get_current_screen();
+       $current_screen->is_block_editor( false );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> include( ABSPATH . 'wp-admin/admin-footer.php' );
</span></span></pre></div>
<a id="trunktestsphpunittestsadminincludesScreenphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/admin/includesScreen.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/admin/includesScreen.php        2019-04-17 01:09:30 UTC (rev 45223)
+++ trunk/tests/phpunit/tests/admin/includesScreen.php  2019-04-17 01:55:21 UTC (rev 45224)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -7,120 +7,151 @@
</span><span class="cx" style="display: block; padding: 0 10px"> class Tests_Admin_includesScreen extends WP_UnitTestCase {
</span><span class="cx" style="display: block; padding: 0 10px">        var $core_screens = array(
</span><span class="cx" style="display: block; padding: 0 10px">                'index.php'                            => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'dashboard',
-                       'id'   => 'dashboard',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'dashboard',
+                       'id'              => 'dashboard',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'edit.php'                             => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base'      => 'edit',
-                       'id'        => 'edit-post',
-                       'post_type' => 'post',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'edit',
+                       'id'              => 'edit-post',
+                       'post_type'       => 'post',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'post-new.php'                         => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'action'    => 'add',
-                       'base'      => 'post',
-                       'id'        => 'post',
-                       'post_type' => 'post',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'action'          => 'add',
+                       'base'            => 'post',
+                       'id'              => 'post',
+                       'post_type'       => 'post',
+                       'is_block_editor' => true,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                'post.php'                             => array(
+                       'base'            => 'post',
+                       'id'              => 'post',
+                       'post_type'       => 'post',
+                       'is_block_editor' => true,
+               ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 'edit-tags.php'                        => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base'      => 'edit-tags',
-                       'id'        => 'edit-post_tag',
-                       'post_type' => 'post',
-                       'taxonomy'  => 'post_tag',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'edit-tags',
+                       'id'              => 'edit-post_tag',
+                       'post_type'       => 'post',
+                       'taxonomy'        => 'post_tag',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'edit-tags.php?taxonomy=post_tag'      => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base'      => 'edit-tags',
-                       'id'        => 'edit-post_tag',
-                       'post_type' => 'post',
-                       'taxonomy'  => 'post_tag',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'edit-tags',
+                       'id'              => 'edit-post_tag',
+                       'post_type'       => 'post',
+                       'taxonomy'        => 'post_tag',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'edit-tags.php?taxonomy=category'      => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base'      => 'edit-tags',
-                       'id'        => 'edit-category',
-                       'post_type' => 'post',
-                       'taxonomy'  => 'category',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'edit-tags',
+                       'id'              => 'edit-category',
+                       'post_type'       => 'post',
+                       'taxonomy'        => 'category',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'upload.php'                           => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base'      => 'upload',
-                       'id'        => 'upload',
-                       'post_type' => 'attachment',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'upload',
+                       'id'              => 'upload',
+                       'post_type'       => 'attachment',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'media-new.php'                        => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'action' => 'add',
-                       'base'   => 'media',
-                       'id'     => 'media',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'action'          => 'add',
+                       'base'            => 'media',
+                       'id'              => 'media',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'edit.php?post_type=page'              => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base'      => 'edit',
-                       'id'        => 'edit-page',
-                       'post_type' => 'page',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'edit',
+                       'id'              => 'edit-page',
+                       'post_type'       => 'page',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'link-manager.php'                     => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'link-manager',
-                       'id'   => 'link-manager',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'link-manager',
+                       'id'              => 'link-manager',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'link-add.php'                         => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'action' => 'add',
-                       'base'   => 'link',
-                       'id'     => 'link',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'action'          => 'add',
+                       'base'            => 'link',
+                       'id'              => 'link',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'edit-tags.php?taxonomy=link_category' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base'      => 'edit-tags',
-                       'id'        => 'edit-link_category',
-                       'taxonomy'  => 'link_category',
-                       'post_type' => '',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'edit-tags',
+                       'id'              => 'edit-link_category',
+                       'taxonomy'        => 'link_category',
+                       'post_type'       => '',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'edit-comments.php'                    => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'edit-comments',
-                       'id'   => 'edit-comments',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'edit-comments',
+                       'id'              => 'edit-comments',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'themes.php'                           => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'themes',
-                       'id'   => 'themes',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'themes',
+                       'id'              => 'themes',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'widgets.php'                          => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'widgets',
-                       'id'   => 'widgets',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'widgets',
+                       'id'              => 'widgets',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'nav-menus.php'                        => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'nav-menus',
-                       'id'   => 'nav-menus',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'nav-menus',
+                       'id'              => 'nav-menus',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'plugins.php'                          => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'plugins',
-                       'id'   => 'plugins',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'plugins',
+                       'id'              => 'plugins',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'users.php'                            => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'users',
-                       'id'   => 'users',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'users',
+                       'id'              => 'users',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'user-new.php'                         => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'action' => 'add',
-                       'base'   => 'user',
-                       'id'     => 'user',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'action'          => 'add',
+                       'base'            => 'user',
+                       'id'              => 'user',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'profile.php'                          => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'profile',
-                       'id'   => 'profile',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'profile',
+                       'id'              => 'profile',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'tools.php'                            => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'tools',
-                       'id'   => 'tools',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'tools',
+                       'id'              => 'tools',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'import.php'                           => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'import',
-                       'id'   => 'import',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'import',
+                       'id'              => 'import',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'export.php'                           => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'export',
-                       'id'   => 'export',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'export',
+                       'id'              => 'export',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'options-general.php'                  => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'options-general',
-                       'id'   => 'options-general',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'options-general',
+                       'id'              => 'options-general',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'options-writing.php'                  => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'base' => 'options-writing',
-                       'id'   => 'options-writing',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'base'            => 'options-writing',
+                       'id'              => 'options-writing',
+                       'is_block_editor' => false,
</ins><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -132,6 +163,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        function tearDown() {
</span><span class="cx" style="display: block; padding: 0 10px">                unset( $GLOBALS['wp_taxonomies']['old-or-new'] );
</span><span class="cx" style="display: block; padding: 0 10px">                unset( $GLOBALS['screen'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                unset( $GLOBALS['current_screen'] );
</ins><span class="cx" style="display: block; padding: 0 10px">                 parent::tearDown();
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -178,6 +210,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertFalse( $current_screen->in_admin( 'network' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertFalse( $current_screen->in_admin( 'user' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertFalse( $current_screen->in_admin( 'garbage' ) );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $this->assertSame( $screen->is_block_editor, $current_screen->is_block_editor );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        // With convert_to_screen(), the same ID should return the exact $current_screen.
</span><span class="cx" style="display: block; padding: 0 10px">                        $this->assertSame( $current_screen, convert_to_screen( $screen->id ), $hook_name );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -195,6 +228,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->post_type, 'page' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->base, 'post' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->id, 'page' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertTrue( $screen->is_block_editor );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        function test_post_type_with_special_suffix_as_hookname() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -203,11 +237,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->post_type, 'value-add' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->base, 'post' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->id, 'value-add' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default.
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $screen = convert_to_screen( 'edit-value-add' ); // the -add part is key.
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->post_type, 'value-add' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->base, 'edit' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->id, 'edit-value-add' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default.
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        function test_taxonomy_with_special_suffix_as_hookname() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -216,6 +252,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->taxonomy, 'old-or-new' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->base, 'edit-tags' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->id, 'edit-old-or-new' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertFalse( $screen->is_block_editor );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        function test_post_type_with_edit_prefix() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -224,11 +261,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->post_type, 'edit-some-thing' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->base, 'post' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->id, 'edit-some-thing' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default.
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $screen = convert_to_screen( 'edit-edit-some-thing' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->post_type, 'edit-some-thing' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->base, 'edit' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertEquals( $screen->id, 'edit-edit-some-thing' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default.
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        function test_post_type_edit_collisions() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -433,4 +472,142 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $GLOBALS['current_screen'] = $screen;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * Sets up a method for testing is_block_editor for a custom post type.
+        *
+        * @since 5.2.0
+        *
+        * @param string $hook Admin page hook.
+        * @return WP_Screen Screen object.
+        */
+       public function setup_block_editor_test( $hook = 'post.php' ) {
+               register_post_type( 'type_shows_in_rest', array( 'show_in_rest' => true ) );
+
+               $GLOBALS['typenow']     = $_GET['post_type'] = $_POST['post_type'] = $_REQUEST['post_type'] = 'type_shows_in_rest';
+               $GLOBALS['hook_suffix'] = $hook;
+
+               if ( 'post.php' === $hook ) {
+                       $post_id      = $this->factory->post->create(
+                               array(
+                                       'post_type' => 'type_shows_in_rest',
+                               )
+                       );
+                       $_GET['post'] = $post_id;
+               }
+
+               set_current_screen();
+
+               return get_current_screen();
+       }
+
+       /**
+        * Data provider for testing is_block_editor.
+        */
+       public function data_is_block_editor() {
+               return array(
+                       array(
+                               // Edit post: Post type supports `show_in_rest`, no filters.
+                               'hook'     => 'post.php',
+                               'filter'   => array(),
+                               'expected' => true,
+                       ),
+                       array(
+                               // Edit post: Support is disabled using post specific filter.
+                               'hook'     => 'post.php',
+                               'filter'   => array(
+                                       'name'     => 'use_block_editor_for_post',
+                                       'function' => '__return_false',
+                               ),
+                               'expected' => false,
+                       ),
+                       array(
+                               // Edit post: Support is disabled using post type specific filter.
+                               'hook'     => 'post.php',
+                               'filter'   => array(
+                                       'name'     => 'use_block_editor_for_post_type',
+                                       'function' => '__return_false',
+                               ),
+                               'expected' => false,
+                       ),
+                       array(
+                               // Edit post: Support is disabled using global replace filter.
+                               'hook'     => 'post.php',
+                               'filter'   => array(
+                                       'name'     => 'replace_editor',
+                                       'function' => '__return_true',
+                               ),
+                               'expected' => false,
+                       ),
+                       array(
+                               // Create post: Post type supports `show_in_rest`, no filters.
+                               'hook'     => 'post-new.php',
+                               'filter'   => array(),
+                               'expected' => true,
+                       ),
+                       array(
+                               // Create post: Support is disabled using post type specific filter.
+                               'hook'     => 'post-new.php',
+                               'filter'   => array(
+                                       'name'     => 'use_block_editor_for_post_type',
+                                       'function' => '__return_false',
+                               ),
+                               'expected' => false,
+                       ),
+
+                       array(
+                               // Create post: Support is not immediately disabled using post specific filter.
+                               'hook'     => 'post-new.php',
+                               'filter'   => array(
+                                       'name'     => 'use_block_editor_for_post',
+                                       'function' => '__return_false',
+                               ),
+                               'expected' => true,
+                       ),
+
+                       array(
+                               // Create post: Support is not immediately disabled using global replace filter.
+                               'hook'     => 'post-new.php',
+                               'filter'   => array(
+                                       'name'     => 'replace_editor',
+                                       'function' => '__return_true',
+                               ),
+                               'expected' => true,
+                       ),
+               );
+       }
+
+       /**
+        * When editing a post type with `show_in_rest` support, the is_block_editor should indicate support.
+        *
+        * @ticket 46195
+        * @dataProvider data_is_block_editor
+        *
+        * @param string $hook Admin hook.
+        * @param array  $filter {
+        *     Optional. Filter name and function to hook.
+        *
+        *     $name     string Filter name to hook a function.
+        *     $function string Function name to hook to the filter.
+        * }
+        * @param bool   $expected The expected `is_block_editor` value.
+        */
+       public function test_is_block_editor( $hook, $filter, $expected ) {
+               if ( ! empty( $filter['name'] ) && ! empty( $filter['function'] ) ) {
+                       add_filter( $filter['name'], $filter['function'] );
+               }
+
+               $screen = $this->setup_block_editor_test( $hook );
+
+               $this->assertSame( 'post', $screen->base );
+               $this->assertSame( 'type_shows_in_rest', $screen->post_type );
+
+               if ( 'post.php' === $hook ) {
+                       $this->assertEmpty( $screen->action );
+               } else {
+                       $this->assertSame( 'add', $screen->action );
+               }
+
+               $this->assertSame( $expected, $screen->is_block_editor );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>