Opened 2 months ago
Closed 2 months ago
#63382 closed enhancement (duplicate)
No hooks to load custom Post Editor
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | minor | Version: | |
Component: | Editor | Keywords: | 2nd-opinion close |
Focuses: | administration | Cc: |
Description
We're all familiar with the classic and block Post Editor. In the source code with the filter 'replace_editor' we can opt for using a custom Post Editor. But on further inspection see wp-admin/post-new.php @ line 70 and wp-admin/post.php @ line 182, there are no follow-up action hooks or other code that allows for the loading of an custom editor. The script (immediately) goes to loading the admin-footer.php if a true is returned by the filter 'replace_editor'. This leads me to believe that the team insists any custom editor be loaded with JS script. There are action hooks in admin-footer.php, but outputting an editor in the footer is not a sound idea. The hooks in admin-footer.php are meant for output of css an js script.
My solution is can be seen in attached image.
Attachments (1)
Change History (4)
#2
in reply to:
↑ 1
@
2 months ago
Replying to swissspidy:
This leads me to believe that the team insists any custom editor be loaded with JS script.
No, the idea is to require your custom PHP code and then return true in the filter. See this example:
And the included file:
As someone who built such a custom editor, the current solution works fine and I don't see the need to add 3 extra hooks for that.
What you are proposing with your approach is to load your custom editor in a callback function registered to filter 'replace_editor' and then to return true. You might not be aware of it, but performing other tasks than the action or filter hook was intended for, is called side-effect. BTW, a filter hook is meant to filter an argument. You are using the filter hook as an action hook. This goes against coding standards. In practice you can apply your approach but it is a bad practice. Awaiting a response.
#3
@
2 months ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
No, the idea is to require your custom PHP code and then return true in the filter.
I'm going to mark this as a duplicate of #51258, which I closed before coming across this ticket because I agree with @swissspidy's comment.
If cleaner code is an objective, I've also had success replacing interfaces in the admin via other available actions like load-{$pagenow}
.
No, the idea is to require your custom PHP code and then return true in the filter. See this example:
https://github.com/GoogleForCreators/web-stories-wp/blob/5ca9ff4043990a3f736ace1b83c28cfc705ad24c/includes/Admin/Editor.php#L234-L258
And the included file:
https://github.com/GoogleForCreators/web-stories-wp/blob/5ca9ff4043990a3f736ace1b83c28cfc705ad24c/includes/templates/admin/edit-story.php
As someone who built such a custom editor, the current solution works fine and I don't see the need to add 3 extra hooks for that.