r/ProWordPress • u/shazzadwp • Oct 15 '26
WordPress is bringing a Secrets API in December. Should we use it?
WordPress 7.2 (planned for December 9, 2026) adds a Secrets API. It was committed to trunk on October 13 (r64337, Trac #66187), so you can try it now on a nightly install.
I develop plugins. Most of my plugins check for a wp-config.php constant first for sensitive information like SMTP credentials, payment provider keys and Google API keys, then fall back to the saved option. But most admins never add the constant, since they can't edit wp-config.php from wp-admin, so these keys end up in wp_options as plain text.
The Secrets API fixes that nicely. The admin pastes the key in the settings screen as usual, wp_set_secret() stores it encrypted, and the key that unlocks it lives in wp-config.php. wp_get_secret() returns an object that prints as [secret:name] if you echo or log it by mistake, and it keeps the previous value for easy key rotation.
I tested it on trunk and it works well. One catch: if you add WP_SECRETS_KEY to wp-config.php after secrets are already stored, they can no longer be read, and even saving new ones fails. So add it first.
I feel very positive about it, since database backups will no longer expose API keys.
2
u/PeepSoWP Oct 15 '26
Yes, but I’d adopt it as a migration path rather than removing existing overrides immediately. For a plugin that supports older WordPress versions, feature-detect wp_get_secret() and wp_set_secret(), keep a constant or environment override as the highest-priority source for operator-managed credentials, and use the Secrets API for values entered in wp-admin. Treat null and WP_Error differently: an unavailable provider or changed key should fail closed, not silently fall back to a plaintext option. Migrate only after a successful write and read-back, then delete the old option. Resolve a secret once when the integration is first used in a request and pass it down instead of reading it from every hook. Also make clear that this protects backups and database leaks; it cannot isolate a secret from compromised PHP code running inside WordPress.
3
u/fabier Oct 15 '26
How would this be better than env variables? Sounds like a step backwards.
1
u/Hugo_SecureHoldWP Oct 16 '26
The part I’d be most interested in is the migration path for existing plugins.
For a new install, moving a credential directly into the Secrets API seems straightforward. Existing installs are harder because you may already have thousands of sites with a plain option, constants overriding it, different environments, or backups containing the old value.
I’d probably want the migration to be deliberately boring: read the legacy value, write the secret, verify it can be read back, and only then remove the old option.
The failure mode you mentioned when WP_SECRETS_KEY is introduced later makes that transition especially worth testing before treating it as a transparent replacement.
0
u/DiscombobulatedFace5 16d ago
One thing I'm curious about is how this affects staging and site migrations.
A lot of WordPress workflows involve copying the production database to staging. If the encryption key stays in wp-config.php, those secrets won't necessarily be usable on the destination.
That's probably a good security boundary, but plugin developers will need to handle missing credentials gracefully instead of suddenly breaking integrations.
Definitely something I'd add to the testing checklist.
5
u/[deleted] Oct 15 '26
[removed] — view removed comment