WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 5 months ago

#51258 new enhancement

Fire an action when `replace_editor` is filtered to true

Reported by: jeremyfelt Owned by:
Milestone: 5.9 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 14 months ago.

Download all attachments as: .zip

Change History (15)

@jeremyfelt
14 months ago

#1 in reply to: ↑ description @teamdnk
13 months 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.

#2 follow-up: @noisysocks
11 months 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: @jeremyfelt
11 months ago

  • Keywords reporter-feedback removed

Replying to noisysocks:

Hi @jeremyfelt. Do the enqueue_block_editor_assets or enqueue_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.

#4 @noisysocks
11 months ago

  • Milestone changed from Awaiting Review to 5.7

Aha, got it, thanks :)

#5 in reply to: ↑ 3 @azaozz
11 months 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.

Last edited 11 months ago by azaozz (previous) (diff)

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


9 months ago

#7 @hellofromTonya
9 months ago

  • Keywords needs-refresh added

Adding needs-refresh for Ozz's comments.

This ticket was mentioned in PR #922 on WordPress/wordpress-develop by pawki07.


9 months ago

  • Keywords needs-refresh removed

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.


9 months ago

#10 @hellofromTonya
9 months 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.


8 months ago

This ticket was mentioned in Slack in #core by chaion07. View the logs.


5 months ago

#13 @chaion07
5 months 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 @desrosj
5 months 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.

Note: See TracTickets for help on using tickets.