WordPress.org

Make WordPress Core

Opened 7 weeks ago

Last modified 3 weeks ago

#51258 new enhancement

Fire an action when `replace_editor` is filtered to true

Reported by: jeremyfelt Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9
Component: Editor Keywords: has-patch
Focuses: administration Cc:

Description

The replace_editor filter was added during the development of Gutenberg to make it possible to implement multiple editor options. See [41829].

Gutenberg previously used this filter to inject necessary hooks and markup before returning true to indicate that the editor had been replaced.

The replace_editor filter is no longer used by the block editor or the Gutenberg plugin—as it has become the editor. Instead, we rely on use_block_editor_for_post() to determine whether the block or classic interface should load.

In the current state, if true is returned via replace_editor, the current screen is set and the admin footer markup is loaded. There is no clean opportunity to add markup or other logic. This can be done during the filter, but that does not provide a clean pattern, especially if one or more pieces of code may be making a decision on editor replacement. See #50216 for a description of how it may fire multiple times.

The patch attached to this ticket adds a replaced_editor action in the post-new.php and post.php files so that plugins can cleanly inject replacement editor code.

Attachments (1)

51258.diff (1.0 KB) - added by jeremyfelt 7 weeks ago.

Download all attachments as: .zip

Change History (2)

@jeremyfelt
7 weeks ago

#1 in reply to: ↑ description @teamdnk
3 weeks ago

There is no clean opportunity to add markup or other logic. This can be done during the filter, but that does not provide a clean pattern, especially if one or more pieces of code may be making a decision on editor replacement.

I agree. Currently, this is a problem for us as we are wanting to use a standalone block editor tailored for a specific post type. At the moment we are using custom actions to implement our own standalone editor, but this requires us to re-route all edit related functions and related logic to our new action such as get_edit_post_link().

@jeremyfelt Thanks for the report and patch submission.

Note: See TracTickets for help on using tickets.