Writing user meta is risky without safety rails
You want to tag 200 customers with loyalty_tier=gold. WordPress's profile page edits one user at a time. The bulk alternative — update_user_meta in PHP — works, but one typo into wp_capabilities can elevate a subscriber to admin. Or clear session tokens for everyone.
Production WordPress installs have been compromised by exactly this pattern: a command meant to write loyalty_tier accidentally wrote wp_capabilities because of a variable name mixup.
What most people do instead
A better way: one command, protected keys blocked
Run update user meta with -user_id, -key, -value. Privilege-escalation keys (wp_capabilities, wp_user_level, session_tokens, use_ssl) are hard-blocked. A typo'd write fails with an error instead of silently escalating privileges.
Privilege-escalation keys hard-blocked. Attempting to write wp_capabilities, wp_user_level, session_tokens, or similar core keys returns an error — doesn't touch the database. Even inside a macro running under a trigger, there's no path to elevate.
How it works
Wraps update_user_meta with a blocklist check. If -user_id is omitted, uses the current user (useful for "on_user_register" triggered macros). Returns success/failure so branching macros can react.
| Parameter | Value |
|---|---|
-user_id | Target user ID. Empty uses current user context. |
-key(required) | Meta key (not a privilege-escalation key) |
-value(required) | Meta value (string, number, or serialized) |
| Blocked keys | wp_capabilities, wp_user_level, session_tokens, use_ssl, and similar core keys |
| Can be used in |
Real example
You're launching a VIP program for customers who've spent over $1,000 lifetime. Each qualifying user gets a loyalty_tier=gold meta flag that your theme reads to show a VIP badge on their account.
Macro: filter user -role=customer -spend_min=1000 → for_each: update user meta -key=loyalty_tier -value=gold. 87 VIPs enrolled in under a minute. Theme renders badges on the next page load. Monthly schedule recomputes tiers as customers spend more.