feat: register WordPress abilities for the copy actions - #1
Draft
roborourke wants to merge 3 commits into
Draft
roborourke wants to merge 3 commits into
roborourke wants to merge 3 commits into
Conversation
Adds Post_Duplicator::get_configured_options(), which maps the saved copy settings onto the options array the duplicator takes. The legacy admin duplication path reads the same settings, so code that has to create a copy outside an admin request can now do so with the same settings applied. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LxVAxTfaqRjd8faeWp37tx
Registers a `duplicate-post` ability category and four abilities on the Abilities API: clone, copy-to-new-draft, rewrite and republish. They run the existing services, so the copy settings, the enabled post types, the `copy_posts` capability, the Rewrite & Republish constraints and the `duplicate_post_allow` filter all apply as they do in the admin. The abilities file is added to the temporary exclusion for the hook prefix sniff, because it applies the existing `duplicate_post_allow` filter. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LxVAxTfaqRjd8faeWp37tx
roborourke
commented
Sep 15, 2026
Bakes the shared `duplicate_post_copy` prefix into the helper, so it takes the post element to copy instead of a full option name and can only read the copy settings it is meant for. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LxVAxTfaqRjd8faeWp37tx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
Yoast\WP\Duplicate_Post\Abilitiesclass registers aduplicate-postability category and four abilities:duplicate-post/clone,duplicate-post/copy-to-new-draft,duplicate-post/rewriteandduplicate-post/republish. It is wired by hand in theDuplicate_Postbootstrap class, like the other services.post_idand returns the resulting post's ID, title, status and edit link.duplicate-post/republishaccepts either the ID of the Rewrite & Republish copy or the ID of the post it was made from.Permissions_Helper, so thecopy_postscapability, the enabled post types and the Rewrite & Republish constraints apply exactly as they do in the admin. Republishing additionally requiresedit_poston the original, which is the same checkPost_Republishermakes. Theduplicate_post_allowfilter is honoured too, so a site that blocks duplication of a post blocks it here as well.Post_Duplicatorrather than the legacyduplicate_post_create_duplicate(), becauseadmin-functions.phpbails out when the request is not an admin request and abilities run outside the admin. To keep the behaviour the same,Post_Duplicator::get_configured_options()was added: it maps the saved copy settings onto the duplicator's options array, and the abilities then copy taxonomies and meta with those options.duplicate_post_after_duplicated, so those three settings do not apply to copies made through an ability. That action is deliberately not fired from the abilities — in an admin request its handlers are attached and would copy the meta a second time. Happy to move those handlers intosrc/in a follow-up if you would rather have full parity.src/abilities.phpwas added to the existing temporary exclusion forYoast.NamingConventions.ValidHookName.WrongPrefix, because it applies the existing, non-namespacedduplicate_post_allowfilter. No thresholds were raised:composer check-cs-thresholdsstill reports 57/57 errors and 0/0 warnings.Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
postnumber in the URL when you edit it).wp eval 'foreach ( wp_get_abilities() as $ability ) { echo $ability->get_name(), PHP_EOL; }'. The fourduplicate-post/...abilities should be listed.wp eval 'var_dump( wp_get_ability( "duplicate-post/clone" )->execute( array( "post_id" => 123 ) ) );' --user=1, replacing 123 with your post ID. A copy should appear in the posts list, with the title prefix and suffix and the other copy settings applied, just like the "Clone" row action.duplicate-post/copy-to-new-draft: the copy should always be a draft.duplicate-post/rewriteon the published post: a Rewrite & Republish copy should be created, and the post should show "Rewrite & Republish" is in progress. Open the copy, change its content, save it as a draft, then runduplicate-post/republishwith the copy's ID: the original post should now show the rewritten content and the copy should be gone.duplicate-post/clonecall as a user without the copy_posts permission (--user=<subscriber>): it should fail with a permission error instead of creating a copy.Relevant test scenarios
The abilities apply the copy settings and the enabled post types, so they are worth trying on a custom post type and on a post with taxonomy terms and custom fields.
Test instructions for QA when the code is in the RC
QA can test this PR by following these steps:
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
Post_Duplicatorgained a new method but none of its existing methods changed, and the admin links, bulk actions and Rewrite & Republish flows are untouched.UI changes
Documentation
Quality assurance
composer test,composer lintandcomposer check-cs-thresholdsall pass. The integration tests intests/WP/Abilities_Test.phpcould not be run in the environment this was written in, because neither Docker nor a database was available forcomposer test-wp-env— they still need to be verified by CI or a reviewer.Innovation
innovationlabel and noted the work hours.Fixes Yoast#544
🤖 Generated with Claude Code
https://claude.ai/code/session_01LxVAxTfaqRjd8faeWp37tx
Generated by Claude Code