`"rest_after_insert_{$enabled_post_type}"` actions are set too early, `duplicate_post_enabled_post_types` filter has no effect.
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 53
- Forks
- 38
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 1
Description
- I've searched for any related issues and avoided creating a duplicate issue.
Please give us a description of what happened
The "rest_after_insert_{$enabled_post_type}" actions are added too early, there is no way to add a duplicate_post_enabled_post_types filter before them.
The solution would be to add these actions in init action or similar, so these lines would be executed in init: https://github.com/Yoast/duplicate-post/blob/trunk/src/post-republisher.php#L48-L55
This would give the themes/plugins chance to register duplicate_post_enabled_post_types filter before the REST hooks.
To Reproduce
Step-by-step reproduction instructions
- Add
duplicate_post_enabled_post_typesfilter in your theme or plugin. - Observe that
"rest_after_insert_{$enabled_post_type}"action is registered only for post types from the settings not including ones added throughduplicate_post_enabled_post_typesfilter.
Expected results
- The
duplicate_post_enabled_post_typesshould allow to set custom post types that can be then used to add"rest_after_insert_{$enabled_post_type}"actions.
Actual results
- The
"rest_after_insert_{$enabled_post_type}"actions are set before the theme or plugin has a chance to setduplicate_post_enabled_post_typesfilter. - This results in
An error occurred while deleting the Rewrite & Republish copy.error when you try to duplicate custom post type set induplicate_post_enabled_post_typesfilter.
Screenshots, screen recording, code snippet
I get this error when I try to rewrite & republish a custom post type added through filter duplicate_post_enabled_post_types:
Technical info
- If relevant, which editor is affected (or editors):
- Block Editor
- Gutenberg Editor
- Classic Editor
- Other:
- Which browser is affected (or browsers):
- Chrome
- Firefox
- [x ] Safari
- Opera
Used versions
- Device you are using: PC
- Operating system: Windows 10
- PHP version: 8.2
- WordPress version: 6.5.5
- WordPress Theme: Twenty-Twenty
- Yoast Duplicate Post version: 4.5
- Gutenberg plugin version:
- Classic Editor plugin version:
- Relevant plugins in case of a bug: none
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open src/post-republisher.php around lines 48-55 and trace when the REST actions are registered relative to the duplicate_post_enabled_post_types filter. Reproduce the custom post-type case described in the issue, then verify that the filtered post type receives the expected REST action and no longer produces the deletion error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100