Skip to content

Fix: skip avatar/cover deletion when file doesn't exist (#439) - #442

Merged
polevaultweb merged 3 commits into
masterfrom
fix/439-avatar-path-cleanup
Apr 8, 2026
Merged

Fix: skip avatar/cover deletion when file doesn't exist (#439)#442
polevaultweb merged 3 commits into
masterfrom
fix/439-avatar-path-cleanup

Conversation

@polevaultweb

Copy link
Copy Markdown
Contributor

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 outside ABSPATH in modern WordPress, making the realpath() check redundant. Instead, each wp_delete_file() call is now guarded with file_exists() so missing files are silently skipped.

Changes (-13/+2):

  • Remove $upload_dir / realpath() check blocks for both avatar and cover
  • Add file_exists() guard to the two wp_delete_file() calls that lacked one

Supersedes #440
Resolves #439

Test plan

  • Account update succeeds when avatar meta points to non-existent file
  • Account update succeeds when cover meta points to non-existent file
  • Uploading a new avatar deletes the old one (when it exists)
  • Removing avatar deletes the file (when it exists)
  • Same for cover images

🤖 Generated with Claude Code

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
polevaultweb and others added 2 commits April 8, 2026 07:58
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
polevaultweb merged commit 5d1e4a5 into master Apr 8, 2026
19 checks passed
@polevaultweb
polevaultweb deleted the fix/439-avatar-path-cleanup branch April 8, 2026 07:22
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant