feat: add user scrambler for demoing cloned sites (#175) - #231
feat: add user scrambler for demoing cloned sites (#175)#231faisalahammad wants to merge 1 commit into
Conversation
Adds a FakerPress > Scramble admin page that replaces the names and emails of existing users with realistic fake data, so a site owner can demo a clone of their real site without exposing real customer info. - New Scramble_View, modeled on the Settings erase-all flow: gated by a typed confirmation phrase, manage_options capability, and a nonce. - Queries real users with its own WP_User_Query, excluding the current admin, already-scrambled users, and FakerPress-generated users. - Updates first_name, last_name, display_name, nickname and user_email via wp_update_user; leaves user_login and user_pass intact so logins keep working and no password reset emails fire. - Marks each scrambled user with an internal _fakerpress_scrambled meta flag so re-runs are idempotent. Batch cap of 500 users per run. Closes bordoni#175
|
The two failing checks (PHP Code Standards and JS Build & Lint) are not caused by this PR. They fail the same way on the
The files this PR adds or changes are clean:
So nothing in this PR needs to change to fix CI. The red checks are repo-wide debt on |
Summary
Adds a new FakerPress > Scramble admin page that replaces the names and emails of existing (real) users with realistic fake data. This lets a site owner clone their real site and demo it without exposing real customer names or emails, as requested in #175.
Closes #175
Changes
New admin view:
Scramble_ViewModeled on the existing destructive "erase all" flow in
Settings_View(same nonce + typed confirmation phrase + capability pattern), since scrambling real data is irreversible.Why a plain admin POST and not a REST endpoint or a Module: every existing module is insert-only (they all call
wp_insert_*), andModule::fetch()only returns FakerPress-flagged records, never real ones. A scrambler is the opposite: it must find and update real records. Routing it through the moduleset() -> generate() -> save()lifecycle would mean stubbingfetch/delete/get_slugjust to overridefilter_save_response, so it is simpler and safer to keep it as a standalone admin action.What gets scrambled
Per eligible user:
first_name,last_name,display_name(set to "First Last"),nickname, anduser_email(a fake@example.*address).Intentionally left untouched:
user_login(changing it breaks logins, anddisplay_nameis what shows publicly)user_pass(so no password reset emails fire)Safety
manage_optionsand a typed phrase (ScrambleorScramble!).fakerpress_flagand are already fake)._fakerpress_scrambledmeta flag, so re-runs are idempotent.user_emailunique index) are retried up to 5 times; if all fail the user is skipped and stays eligible next run.Registration
One line added to
Admin/View/Factory.php::get_all()to register the view (views register their own admin menu viahook()).Before:
$views_classes = [ Attachment_View::class, Comment_View::class, Post_View::class, Settings_View::class, Error_View::class, Changelog_View::class, Term_View::class, User_View::class, ];After:
$views_classes = [ Attachment_View::class, Comment_View::class, Post_View::class, Settings_View::class, Scramble_View::class, Error_View::class, Changelog_View::class, Term_View::class, User_View::class, ];Testing
Test 1: page appears
Result: a "Scramble Users" page with one text field and a "Scramble!" button.
Test 2: wrong phrase does nothing
helloand click Scramble!.Result: a red error notice "The verification to scramble the users has failed...", no user data changes.
Test 3: correct phrase scrambles eligible users
Scrambleand click Scramble!.Result: green success notice "Successfully scrambled N users". In Users, non-admin users now have fake names/emails; the logged-in admin's row is unchanged;
user_loginslugs are unchanged.Test 4: idempotent re-run
Scramble, click again.Result: "No users were available to scramble..." Already-scrambled users are not touched again.
Test 5: FakerPress-generated users are skipped
Result: the generated users keep their original fake data (they carry
fakerpress_flag).Environment: WordPress 6.x, PHP 8.1+. PHPCS clean on the changed files (only the inherent
meta_query/excludewarnings remain).Notes