Changeset 45224
- Timestamp:
- 04/17/2019 01:55:21 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/edit-form-advanced.php
r45140 r45224 18 18 */ 19 19 global $post_type, $post_type_object, $post; 20 21 // Flag that we're not loading the block editor. 22 $current_screen = get_current_screen(); 23 $current_screen->is_block_editor( false ); 20 24 21 25 if ( is_multisite() ) { -
trunk/src/wp-admin/includes/class-wp-screen.php
r44574 r45224 203 203 } 204 204 205 $post_type = $taxonomy = null; 206 $in_admin = false; 207 $action = ''; 205 $post_type = $taxonomy = null; 206 $in_admin = false; 207 $action = ''; 208 $is_block_editor = false; 208 209 209 210 if ( $hook_name ) { … … 295 296 if ( $post ) { 296 297 $post_type = $post->post_type; 298 299 /** This filter is documented in wp-admin/post.php */ 300 $replace_editor = apply_filters( 'replace_editor', false, $post ); 301 302 if ( ! $replace_editor ) { 303 $is_block_editor = use_block_editor_for_post( $post ); 304 } 297 305 } 298 306 } … … 315 323 $post_type = 'post'; 316 324 } 325 326 // When creating a new post, use the default block editor support value for the post type. 327 if ( empty( $post_id ) ) { 328 $is_block_editor = use_block_editor_for_post_type( $post_type ); 329 } 330 317 331 $id = $post_type; 318 332 break; … … 358 372 } 359 373 360 $screen->base = $base; 361 $screen->action = $action; 362 $screen->post_type = (string) $post_type; 363 $screen->taxonomy = (string) $taxonomy; 364 $screen->is_user = ( 'user' == $in_admin ); 365 $screen->is_network = ( 'network' == $in_admin ); 366 $screen->in_admin = $in_admin; 374 $screen->base = $base; 375 $screen->action = $action; 376 $screen->post_type = (string) $post_type; 377 $screen->taxonomy = (string) $taxonomy; 378 $screen->is_user = ( 'user' == $in_admin ); 379 $screen->is_network = ( 'network' == $in_admin ); 380 $screen->in_admin = $in_admin; 381 $screen->is_block_editor = $is_block_editor; 367 382 368 383 self::$_registry[ $id ] = $screen; -
trunk/src/wp-admin/post-new.php
r44165 r45224 75 75 include( ABSPATH . 'wp-admin/edit-form-advanced.php' ); 76 76 } 77 } else { 78 // Flag that we're not loading the block editor. 79 $current_screen = get_current_screen(); 80 $current_screen->is_block_editor( false ); 77 81 } 78 82 -
trunk/tests/phpunit/tests/admin/includesScreen.php
r44577 r45224 8 8 var $core_screens = array( 9 9 'index.php' => array( 10 'base' => 'dashboard', 11 'id' => 'dashboard', 10 'base' => 'dashboard', 11 'id' => 'dashboard', 12 'is_block_editor' => false, 12 13 ), 13 14 'edit.php' => array( 14 'base' => 'edit', 15 'id' => 'edit-post', 16 'post_type' => 'post', 15 'base' => 'edit', 16 'id' => 'edit-post', 17 'post_type' => 'post', 18 'is_block_editor' => false, 17 19 ), 18 20 'post-new.php' => array( 19 'action' => 'add', 20 'base' => 'post', 21 'id' => 'post', 22 'post_type' => 'post', 21 'action' => 'add', 22 'base' => 'post', 23 'id' => 'post', 24 'post_type' => 'post', 25 'is_block_editor' => true, 26 ), 27 'post.php' => array( 28 'base' => 'post', 29 'id' => 'post', 30 'post_type' => 'post', 31 'is_block_editor' => true, 23 32 ), 24 33 'edit-tags.php' => array( 25 'base' => 'edit-tags', 26 'id' => 'edit-post_tag', 27 'post_type' => 'post', 28 'taxonomy' => 'post_tag', 34 'base' => 'edit-tags', 35 'id' => 'edit-post_tag', 36 'post_type' => 'post', 37 'taxonomy' => 'post_tag', 38 'is_block_editor' => false, 29 39 ), 30 40 'edit-tags.php?taxonomy=post_tag' => array( 31 'base' => 'edit-tags', 32 'id' => 'edit-post_tag', 33 'post_type' => 'post', 34 'taxonomy' => 'post_tag', 41 'base' => 'edit-tags', 42 'id' => 'edit-post_tag', 43 'post_type' => 'post', 44 'taxonomy' => 'post_tag', 45 'is_block_editor' => false, 35 46 ), 36 47 'edit-tags.php?taxonomy=category' => array( 37 'base' => 'edit-tags', 38 'id' => 'edit-category', 39 'post_type' => 'post', 40 'taxonomy' => 'category', 48 'base' => 'edit-tags', 49 'id' => 'edit-category', 50 'post_type' => 'post', 51 'taxonomy' => 'category', 52 'is_block_editor' => false, 41 53 ), 42 54 'upload.php' => array( 43 'base' => 'upload', 44 'id' => 'upload', 45 'post_type' => 'attachment', 55 'base' => 'upload', 56 'id' => 'upload', 57 'post_type' => 'attachment', 58 'is_block_editor' => false, 46 59 ), 47 60 'media-new.php' => array( 48 'action' => 'add', 49 'base' => 'media', 50 'id' => 'media', 61 'action' => 'add', 62 'base' => 'media', 63 'id' => 'media', 64 'is_block_editor' => false, 51 65 ), 52 66 'edit.php?post_type=page' => array( 53 'base' => 'edit', 54 'id' => 'edit-page', 55 'post_type' => 'page', 67 'base' => 'edit', 68 'id' => 'edit-page', 69 'post_type' => 'page', 70 'is_block_editor' => false, 56 71 ), 57 72 'link-manager.php' => array( 58 'base' => 'link-manager', 59 'id' => 'link-manager', 73 'base' => 'link-manager', 74 'id' => 'link-manager', 75 'is_block_editor' => false, 60 76 ), 61 77 'link-add.php' => array( 62 'action' => 'add', 63 'base' => 'link', 64 'id' => 'link', 78 'action' => 'add', 79 'base' => 'link', 80 'id' => 'link', 81 'is_block_editor' => false, 65 82 ), 66 83 'edit-tags.php?taxonomy=link_category' => array( 67 'base' => 'edit-tags', 68 'id' => 'edit-link_category', 69 'taxonomy' => 'link_category', 70 'post_type' => '', 84 'base' => 'edit-tags', 85 'id' => 'edit-link_category', 86 'taxonomy' => 'link_category', 87 'post_type' => '', 88 'is_block_editor' => false, 71 89 ), 72 90 'edit-comments.php' => array( 73 'base' => 'edit-comments', 74 'id' => 'edit-comments', 91 'base' => 'edit-comments', 92 'id' => 'edit-comments', 93 'is_block_editor' => false, 75 94 ), 76 95 'themes.php' => array( 77 'base' => 'themes', 78 'id' => 'themes', 96 'base' => 'themes', 97 'id' => 'themes', 98 'is_block_editor' => false, 79 99 ), 80 100 'widgets.php' => array( 81 'base' => 'widgets', 82 'id' => 'widgets', 101 'base' => 'widgets', 102 'id' => 'widgets', 103 'is_block_editor' => false, 83 104 ), 84 105 'nav-menus.php' => array( 85 'base' => 'nav-menus', 86 'id' => 'nav-menus', 106 'base' => 'nav-menus', 107 'id' => 'nav-menus', 108 'is_block_editor' => false, 87 109 ), 88 110 'plugins.php' => array( 89 'base' => 'plugins', 90 'id' => 'plugins', 111 'base' => 'plugins', 112 'id' => 'plugins', 113 'is_block_editor' => false, 91 114 ), 92 115 'users.php' => array( 93 'base' => 'users', 94 'id' => 'users', 116 'base' => 'users', 117 'id' => 'users', 118 'is_block_editor' => false, 95 119 ), 96 120 'user-new.php' => array( 97 'action' => 'add', 98 'base' => 'user', 99 'id' => 'user', 121 'action' => 'add', 122 'base' => 'user', 123 'id' => 'user', 124 'is_block_editor' => false, 100 125 ), 101 126 'profile.php' => array( 102 'base' => 'profile', 103 'id' => 'profile', 127 'base' => 'profile', 128 'id' => 'profile', 129 'is_block_editor' => false, 104 130 ), 105 131 'tools.php' => array( 106 'base' => 'tools', 107 'id' => 'tools', 132 'base' => 'tools', 133 'id' => 'tools', 134 'is_block_editor' => false, 108 135 ), 109 136 'import.php' => array( 110 'base' => 'import', 111 'id' => 'import', 137 'base' => 'import', 138 'id' => 'import', 139 'is_block_editor' => false, 112 140 ), 113 141 'export.php' => array( 114 'base' => 'export', 115 'id' => 'export', 142 'base' => 'export', 143 'id' => 'export', 144 'is_block_editor' => false, 116 145 ), 117 146 'options-general.php' => array( 118 'base' => 'options-general', 119 'id' => 'options-general', 147 'base' => 'options-general', 148 'id' => 'options-general', 149 'is_block_editor' => false, 120 150 ), 121 151 'options-writing.php' => array( 122 'base' => 'options-writing', 123 'id' => 'options-writing', 152 'base' => 'options-writing', 153 'id' => 'options-writing', 154 'is_block_editor' => false, 124 155 ), 125 156 ); … … 133 164 unset( $GLOBALS['wp_taxonomies']['old-or-new'] ); 134 165 unset( $GLOBALS['screen'] ); 166 unset( $GLOBALS['current_screen'] ); 135 167 parent::tearDown(); 136 168 } … … 179 211 $this->assertFalse( $current_screen->in_admin( 'user' ) ); 180 212 $this->assertFalse( $current_screen->in_admin( 'garbage' ) ); 213 $this->assertSame( $screen->is_block_editor, $current_screen->is_block_editor ); 181 214 182 215 // With convert_to_screen(), the same ID should return the exact $current_screen. … … 196 229 $this->assertEquals( $screen->base, 'post' ); 197 230 $this->assertEquals( $screen->id, 'page' ); 231 $this->assertTrue( $screen->is_block_editor ); 198 232 } 199 233 … … 204 238 $this->assertEquals( $screen->base, 'post' ); 205 239 $this->assertEquals( $screen->id, 'value-add' ); 240 $this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default. 206 241 207 242 $screen = convert_to_screen( 'edit-value-add' ); // the -add part is key. … … 209 244 $this->assertEquals( $screen->base, 'edit' ); 210 245 $this->assertEquals( $screen->id, 'edit-value-add' ); 246 $this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default. 211 247 } 212 248 … … 217 253 $this->assertEquals( $screen->base, 'edit-tags' ); 218 254 $this->assertEquals( $screen->id, 'edit-old-or-new' ); 255 $this->assertFalse( $screen->is_block_editor ); 219 256 } 220 257 … … 225 262 $this->assertEquals( $screen->base, 'post' ); 226 263 $this->assertEquals( $screen->id, 'edit-some-thing' ); 264 $this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default. 227 265 228 266 $screen = convert_to_screen( 'edit-edit-some-thing' ); … … 230 268 $this->assertEquals( $screen->base, 'edit' ); 231 269 $this->assertEquals( $screen->id, 'edit-edit-some-thing' ); 270 $this->assertFalse( $screen->is_block_editor ); // Post types do not support `show_in_rest` by default. 232 271 } 233 272 … … 434 473 $GLOBALS['current_screen'] = $screen; 435 474 } 475 476 /** 477 * Sets up a method for testing is_block_editor for a custom post type. 478 * 479 * @since 5.2.0 480 * 481 * @param string $hook Admin page hook. 482 * @return WP_Screen Screen object. 483 */ 484 public function setup_block_editor_test( $hook = 'post.php' ) { 485 register_post_type( 'type_shows_in_rest', array( 'show_in_rest' => true ) ); 486 487 $GLOBALS['typenow'] = $_GET['post_type'] = $_POST['post_type'] = $_REQUEST['post_type'] = 'type_shows_in_rest'; 488 $GLOBALS['hook_suffix'] = $hook; 489 490 if ( 'post.php' === $hook ) { 491 $post_id = $this->factory->post->create( 492 array( 493 'post_type' => 'type_shows_in_rest', 494 ) 495 ); 496 $_GET['post'] = $post_id; 497 } 498 499 set_current_screen(); 500 501 return get_current_screen(); 502 } 503 504 /** 505 * Data provider for testing is_block_editor. 506 */ 507 public function data_is_block_editor() { 508 return array( 509 array( 510 // Edit post: Post type supports `show_in_rest`, no filters. 511 'hook' => 'post.php', 512 'filter' => array(), 513 'expected' => true, 514 ), 515 array( 516 // Edit post: Support is disabled using post specific filter. 517 'hook' => 'post.php', 518 'filter' => array( 519 'name' => 'use_block_editor_for_post', 520 'function' => '__return_false', 521 ), 522 'expected' => false, 523 ), 524 array( 525 // Edit post: Support is disabled using post type specific filter. 526 'hook' => 'post.php', 527 'filter' => array( 528 'name' => 'use_block_editor_for_post_type', 529 'function' => '__return_false', 530 ), 531 'expected' => false, 532 ), 533 array( 534 // Edit post: Support is disabled using global replace filter. 535 'hook' => 'post.php', 536 'filter' => array( 537 'name' => 'replace_editor', 538 'function' => '__return_true', 539 ), 540 'expected' => false, 541 ), 542 array( 543 // Create post: Post type supports `show_in_rest`, no filters. 544 'hook' => 'post-new.php', 545 'filter' => array(), 546 'expected' => true, 547 ), 548 array( 549 // Create post: Support is disabled using post type specific filter. 550 'hook' => 'post-new.php', 551 'filter' => array( 552 'name' => 'use_block_editor_for_post_type', 553 'function' => '__return_false', 554 ), 555 'expected' => false, 556 ), 557 558 array( 559 // Create post: Support is not immediately disabled using post specific filter. 560 'hook' => 'post-new.php', 561 'filter' => array( 562 'name' => 'use_block_editor_for_post', 563 'function' => '__return_false', 564 ), 565 'expected' => true, 566 ), 567 568 array( 569 // Create post: Support is not immediately disabled using global replace filter. 570 'hook' => 'post-new.php', 571 'filter' => array( 572 'name' => 'replace_editor', 573 'function' => '__return_true', 574 ), 575 'expected' => true, 576 ), 577 ); 578 } 579 580 /** 581 * When editing a post type with `show_in_rest` support, the is_block_editor should indicate support. 582 * 583 * @ticket 46195 584 * @dataProvider data_is_block_editor 585 * 586 * @param string $hook Admin hook. 587 * @param array $filter { 588 * Optional. Filter name and function to hook. 589 * 590 * $name string Filter name to hook a function. 591 * $function string Function name to hook to the filter. 592 * } 593 * @param bool $expected The expected `is_block_editor` value. 594 */ 595 public function test_is_block_editor( $hook, $filter, $expected ) { 596 if ( ! empty( $filter['name'] ) && ! empty( $filter['function'] ) ) { 597 add_filter( $filter['name'], $filter['function'] ); 598 } 599 600 $screen = $this->setup_block_editor_test( $hook ); 601 602 $this->assertSame( 'post', $screen->base ); 603 $this->assertSame( 'type_shows_in_rest', $screen->post_type ); 604 605 if ( 'post.php' === $hook ) { 606 $this->assertEmpty( $screen->action ); 607 } else { 608 $this->assertSame( 'add', $screen->action ); 609 } 610 611 $this->assertSame( $expected, $screen->is_block_editor ); 612 } 436 613 }
Note: See TracChangeset
for help on using the changeset viewer.