Repository navigation
Fix TypeError on before_delete_post when the post was already deleted by a concurrent request - #564
Open
fabiomsnunes wants to merge 1 commit into
Open
fabiomsnunes wants to merge 1 commit into
fabiomsnunes wants to merge 1 commit into
Conversation
fabiomsnunes
force-pushed
the
563-fix-before-delete-post-typeerror
branch
from
October 14, 2026 14:40
a4e1807 to
a9c55fa
Compare
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
Post_Republisher::clean_up_when_copy_manually_deleted()re-fetches the post withget_post()onbefore_delete_postand passes the result toPermissions_Helper::is_rewrite_and_republish_copy( WP_Post $post ). When another request deleted the same post first,get_post()returnsnulland the request dies with aTypeError.Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
WP_Postthatwp_delete_post()already passes as the 2nd argument ofbefore_delete_post(10, 2), so it no longer depends on the row still being in the database.$postis optional and the method falls back toget_post()when it is not passed, so direct callers using only the post ID keep working. Theinstanceof WP_Postcheck covers that fallback returningnull.wp_delete_post(): with a real concurrent delete, core's own_reset_front_page_settings_for_post()(also onbefore_delete_post) emits a PHP warning for the same reason, which PHPUnit turns into an error.changelog: bugfix.Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
trunk, with only Duplicate Post active, save this asrepro.phpand runwp eval-file repro.php. It simulates a concurrent request deleting the post right before this request'sbefore_delete_postcallbacks run:TypeError: ... is_rewrite_and_republish_copy(): Argument #1 ($post) must be of type WP_Post, null given._reset_front_page_settings_for_post(), see above).Relevant test scenarios
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:
UI changes
Documentation
Quality assurance
Checks run locally:
composer lint,composer test,composer check-cs-thresholds(57/57 errors, 0/0 warnings, same astrunk) andcomposer test-wp-env. The integration tests ran with--php=8.4, becausecomposer updateon my PHP 8.4 host installs adoctrine/instantiatorthat doesn't parse on the default PHP 8.2 container. The new unit and integration tests fail ontrunkwith theTypeErrorand pass on this branch.