Yoast / Yoast/duplicate-post

`"rest_after_insert_{$enabled_post_type}"` actions are set too early, `duplicate_post_enabled_post_types` filter has no effect.

Open
#376 0 comments 0 reactions 0 assignees View on GitHub

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
  1. Add duplicate_post_enabled_post_types filter in your theme or plugin.
  2. Observe that "rest_after_insert_{$enabled_post_type}" action is registered only for post types from the settings not including ones added through duplicate_post_enabled_post_types filter.
Expected results
  1. The duplicate_post_enabled_post_types should allow to set custom post types that can be then used to add "rest_after_insert_{$enabled_post_type}" actions.
Actual results
  1. The "rest_after_insert_{$enabled_post_type}" actions are set before the theme or plugin has a chance to set duplicate_post_enabled_post_types filter.
  2. This results in An error occurred while deleting the Rewrite & Republish copy. error when you try to duplicate custom post type set in duplicate_post_enabled_post_types filter.
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:
image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.