Opened 4 years ago
Last modified 3 years ago
#51258 new enhancement
Fire an action when `replace_editor` is filtered to true
Reported by: | jeremyfelt | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 4.9 |
Component: | Editor | Keywords: | has-patch needs-refresh |
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)
Change History (17)
#1
in reply to:
↑ description
@
4 years ago
#2
follow-up:
↓ 3
@
4 years ago
- Keywords reporter-feedback added
Hi @jeremyfelt. Do the enqueue_block_editor_assets
or enqueue_block_assets
actions not suit your use case?
#3
in reply to:
↑ 2
;
follow-up:
↓ 5
@
4 years ago
- Keywords reporter-feedback removed
Replying to noisysocks:
Hi @jeremyfelt. Do the
enqueue_block_editor_assets
orenqueue_block_assets
actions not suit your use case?
In this use case, replace_editor
is filtered to true
, so the block editor is not loaded and neither of those actions are available.
A replaced_editor
action would be used to render markup and scripts for a completely different editor.
#5
in reply to:
↑ 3
@
4 years ago
Replying to jeremyfelt:
This filter wasn't named that well, perhaps should have been something like replace_editor_template
as that's what it does.
A
replaced_editor
action would be used to render markup and scripts for a completely different editor.
Right, an action would solve the problem with the "missing" edit-form-advanced.php
when replace_editor
returns true. There are some caveats though. As mentioned admin-footer.php
is still included, but admin-header.php
is not. Also things like $current_screen->is_block_editor( false );
, missing PHP globals like $post_ID
, etc. Perhaps adding a big, nice docblock would help somewhat.
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
This ticket was mentioned in PR #922 on WordPress/wordpress-develop by pawki07.
4 years ago
#8
- Keywords needs-refresh removed
Trac ticket: https://core.trac.wordpress.org/ticket/51258
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#10
@
4 years ago
- Milestone changed from 5.7 to 5.8
5.7 Beta 1 is happening in ~1 hour. Ran out of time to get this ticket into 5.7. Punting to 5.8.
If any maintainer or committer feels this can be resolved in time, or wishes to assume ownership during a specific cycle, feel free to update the milestone accordingly.
This ticket was mentioned in Slack in #core by jeremyfelt. View the logs.
4 years ago
This ticket was mentioned in Slack in #core by chaion07. View the logs.
3 years ago
#13
@
3 years ago
Thank you @jeremyfelt for reporting the issue. This ticket was reviewed during one of the recent [5.8 bug-scrub sessions]https://wordpress.slack.com/archives/C02RQBWTW/p1621397086063800. Emphasizing on what @hellofromTonya suggested in her [previous comment]https://core.trac.wordpress.org/ticket/51258#comment:10 and inviting a core committer or a component maintainer to take this on. @noisysocks would you be interested? Can be a good edition to 5.8. Thank you much!
#14
@
3 years ago
- Milestone changed from 5.8 to 5.9
Since someone was not able to give this a good review and feature freeze day is upon us, I'm going to punt this ticket. I'll assign to 5.9
instead of Future Release
, as it would be best to make this adjustment before official support for the Classic Editor ends at the end of the calendar year.
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.