Skip to content

Fix unbounded get_users() in theme-switch review-notice cleanup - #115

Merged
iamprazol merged 1 commit into
developfrom
fix/unbounded-get-users-review-notice-cleanup
Sep 30, 2026
Merged

iamprazol merged 1 commit into
developfrom
fix/unbounded-get-users-review-notice-cleanup

Conversation

@deepench

Copy link
Copy Markdown
Contributor

Fixes themegrill/flash-pro#36

Changes proposed in this Pull Request:

review_notice_data_remove() (inc/admin/class-flash-theme-review-notice.php, hooked on switch_theme) called get_users() with no arguments - loading every user on the site as a full WP_User object, then doing a get_user_meta() round-trip per user, purely to delete two dismissal meta keys that either exist or don't. The code never branched on the meta's actual value, only whether it existed, so there was no need to read it first at all.

Replaced the whole get_users()-plus-loop with two delete_metadata( 'user', 0, $key, '', true ) calls, which delete a meta key across every user in one query each, without ever loading a single user object.

Verification note: this class only loads inside is_admin(), so it can't be exercised via a plain front-end visit or WP-CLI's own theme-switch command - had to verify via the real wp-admin theme-switch UI instead. Set both meta keys on multiple users, switched away from Flash through that UI, confirmed both keys were gone for every user afterward.

How to test the changes in this Pull Request:

  1. As multiple users, dismiss the theme review notice (permanently and/or partially) so more than one user has flash_ignore_theme_review_notice and/or nag_flash_ignore_theme_review_notice_partially set.
  2. In wp-admin, switch the active theme away from Flash.
  3. Confirm both meta keys are gone for every user that had them, not just the current one, and that the flash_theme_installed_time option is also cleared.

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (modification of the currently available functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Other information:

  • Have you added an explanation of what your changes do and why you would like us to include them?
  • Have you successfully ran tests with your changes locally?
  • Have you updated the documentation accordingly?

Changelog entry

Fix - Theme-switch cleanup no longer loads every user on the site to delete two dismissal meta keys.

review_notice_data_remove() called get_users() with no arguments -
loading every user on the site as a full WP_User object, then doing a
get_user_meta() round-trip per user - purely to delete two user-meta
keys that either exist or don't. Since the code never branched on the
meta's actual value (only whether it existed), there was no need to
read it first at all.

Replaced the whole get_users()-plus-loop with two delete_metadata()
calls (delete_all = true), which delete a meta key across every user in
one query each, without ever loading a single user object.

Verified live via the real wp-admin theme-switch UI (this class only
loads inside is_admin(), so WP-CLI's own theme-switch bootstrap doesn't
exercise it): set the two meta keys on multiple users, switched away
from Flash, confirmed both keys were gone for every user afterward.
@tg-autopilot
tg-autopilot requested a lite review from Copilot September 28, 2026 08:52
@github-actions

Copy link
Copy Markdown

QA suite — refused, no regression spec

This PR changes product source but adds no spec, so the suite was
refused before booting WordPress — running it just to report the same
thing at the end costs runner minutes for nothing. Run
/claudegrill:verify-fix locally and let write-spec add the guard
to this branch, then push again.

Source files changed with no matching spec
inc/admin/class-flash-theme-review-notice.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The optimization preserves intended behavior; only a non-blocking documentation nit remains.

Review effort: Lite
Findings: None

What changed in this PR

Fixes theme-switch cleanup to avoid loading every user when removing review-notice metadata.

Changes:

  • Replaces unbounded get_users() usage with bulk metadata deletion.
  • Preserves removal of the installation-time option.
File Summary
inc/​admin/​class-flash-theme-review-notice.php Optimizes cleanup; non-blocking nit: revise the comment’s query-count claim.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@deepench
deepench requested a review from subin-shk September 28, 2026 09:13
@deepench deepench self-assigned this Sep 28, 2026
@deepench deepench added the bug label Sep 28, 2026

@subin-shk subin-shk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏼

@iamprazol
iamprazol merged commit 873c4bd into develop Sep 30, 2026
3 of 5 checks passed
@iamprazol
iamprazol deleted the fix/unbounded-get-users-review-notice-cleanup branch September 30, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants