[wp-trac] [WordPress Trac] #52363: use_block_editor_for_post() does not check if post supports editor

WordPress Trac noreply at wordpress.org
Mon Jan 25 16:26:52 UTC 2021


#52363: use_block_editor_for_post() does not check if post supports editor
----------------------------+-----------------------------
 Reporter:  gudmdharalds    |      Owner:  (none)
     Type:  defect (bug)    |     Status:  assigned
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Editor          |    Version:  5.6
 Severity:  normal          |   Keywords:  has-patch
  Focuses:  administration  |
----------------------------+-----------------------------
 The current implementation of the `use_block_editor_for_post()` function
 in [https://core.trac.wordpress.org/browser/tags/5.6/src/wp-
 admin/includes/post.php?rev=49777#L2109 WordPress 5.6] (and
 [https://core.trac.wordpress.org/browser/trunk/src/wp-
 admin/includes/post.php#L2109 trunk]) does not check if the post-type in
 question supports `editor`. This can lead to situations where the
 Gutenberg Editor is being loaded for a particular post which does not
 support an editor, resulting in a JavaScript error and a white screen.

 Note that while `use_block_editor_for_post_type` does perform this check,
 that is not enough, as the `use_block_editor_for_post` filter is applied
 ''later''.

 To replicate:

 1. Set up WordPress 5.6 with no plugins active and default theme
 activated.

 2. Add `add_filter( 'use_block_editor_for_post', '__return_true' );` to a
 file in `wp-content/mu-plugins`.

 3. Edit any post item of type `post`, verify that Gutenberg loads
 successfully.

 4. Add image to Media Library, note the ID of it.

 5. Attempt to edit the newly uploaded image by navigating to: `wp-
 admin/post.php?post=ID&action=edit` -- replace `ID` with ID of the image.

 6. White screen should appear, with JavaScript error: `Uncaught (in
 promise) TypeError: Cannot read property 'raw' of undefined [...]`

 This occurs is because the `attachment` post-type does
 [https://core.trac.wordpress.org/browser/tags/5.6/src/wp-
 includes/post.php?rev=49777#L96 not support] the Gutenberg Editor.

 This behaviour does not happen when using the filter
 `use_block_editor_for_post_type`, as the function that calls the filter
 checks if the post-type supports editors. The same kind of check should be
 performed when using the `use_block_editor_for_post` filter to avoid
 unexpected errors. Users of the filter would assume that Gutenberg is not
 loaded if it is not supported by the post-type.


 Expected behavior: Gutenberg is not loaded for post-types not supporting
 `editor`, even if the `use_block_editor_for_post` filter is used as
 described above.

 Observed behavior: White screen, unable to do editing.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52363>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list