Fix: skip avatar/cover deletion when file doesn't exist (#439) - #442
Merged
Conversation
Remove the realpath() security checks added in b5d95fc. These checks cause account updates to fail when avatar/cover files no longer exist on disk (stale meta after migrations, cleanup plugins, etc). wp_delete_file() already prevents deletion outside ABSPATH in modern WordPress, making the realpath() check redundant. Instead, guard each wp_delete_file() call with file_exists() so missing files are silently skipped. Resolves #439
3 tasks
Tests verify that: - Account updates succeed when avatar/cover meta points to missing files - Old files are deleted when a new avatar/cover is uploaded - Files are deleted when avatar/cover is cleared - Existing files are preserved when nothing changes - Stale file meta does not block unrelated account updates (name, email) - wpum_user_update_remove_avatar hook fires on removal Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
filter_input() reads from the real PHP input stream, not $_POST, so it always returns null in CLI/WPUnit context. Replace the two affected tests with alternatives that verify meta storage instead. The original scenarios (replace cover, keep same avatar) are noted as needing E2E coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
polevaultweb
added a commit
that referenced
this pull request
Apr 8, 2026
* Fix: skip avatar/cover deletion when file doesn't exist (#439) Remove the realpath() security checks added in b5d95fc. These checks cause account updates to fail when avatar/cover files no longer exist on disk (stale meta after migrations, cleanup plugins, etc). wp_delete_file() already prevents deletion outside ABSPATH in modern WordPress, making the realpath() check redundant. Instead, guard each wp_delete_file() call with file_exists() so missing files are silently skipped. Resolves #439 * Add WPUnit tests for avatar/cover file handling (#439) Tests verify that: - Account updates succeed when avatar/cover meta points to missing files - Old files are deleted when a new avatar/cover is uploaded - Files are deleted when avatar/cover is cleared - Existing files are preserved when nothing changes - Stale file meta does not block unrelated account updates (name, email) - wpum_user_update_remove_avatar hook fires on removal Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix two tests that depend on filter_input(INPUT_POST) filter_input() reads from the real PHP input stream, not $_POST, so it always returns null in CLI/WPUnit context. Replace the two affected tests with alternatives that verify meta storage instead. The original scenarios (replace cover, keep same avatar) are noted as needing E2E coverage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Replaces #440 with a simpler approach.
Removes the
realpath()security checks added in b5d95fc. These checks cause account updates to fail when avatar/cover files no longer exist on disk (stale meta after migrations, cleanup plugins, etc).wp_delete_file()already prevents deletion outsideABSPATHin modern WordPress, making therealpath()check redundant. Instead, eachwp_delete_file()call is now guarded withfile_exists()so missing files are silently skipped.Changes (-13/+2):
$upload_dir/realpath()check blocks for both avatar and coverfile_exists()guard to the twowp_delete_file()calls that lacked oneSupersedes #440
Resolves #439
Test plan
🤖 Generated with Claude Code