[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/secrets/ -> class-wp-secrets-key-manager.php (summary)

Secrets API: WP_Secrets_Key_Manager class

File Size: 556 lines (16 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 10 functions

  __construct()
  get_keyring()
  get_master_key()
  get_root_key()
  rotate_site_key()
  get_wrapped_root_key()
  generate_root_key()
  insert_root_key()
  read_stored_root_key()
  forget_missing_root_key()

Functions
Functions that are not part of a class:

__construct( ?WP_Secrets_Keyring $keyring = null )   X-Ref
Constructor.

param: WP_Secrets_Keyring|null $keyring Keyring to use. Defaults to the

get_keyring()   X-Ref
Returns the keyring in use.

Used by Site Health and by `wp secret dropin` and `wp secret health`, which all
need to describe the active keyring without duplicating the logic that resolves
it.

return: WP_Secrets_Keyring

get_master_key( string $scope, ?int $site_id = null, bool $create_root_key = true )   X-Ref
Derives a scope's master key from the root key.

param: string   $scope           'site' or 'network'.
param: int|null $site_id         Blog ID for site scope. Defaults to the current blog.
param: bool     $create_root_key Optional. Whether to generate and store a root key
return: string|WP_Error 32-byte master key on success. WP_Error on failure,

get_root_key( bool $create = true )   X-Ref
Returns the root key, generating and persisting one on first use.

get_site_option() also returns false when its query fails, so a false result is
checked against the database before a new root key is generated. Generating one
while another is stored would make every existing secret undecryptable.

param: bool $create Optional. Whether to generate and store a root key if none
return: string|WP_Error 32 raw bytes on success. WP_Error on failure.

rotate_site_key( WP_Secrets_Keyring $old_keyring, WP_Secrets_Keyring $new_keyring )   X-Ref
Re-wraps the root key under a new keyring, without touching any stored secret.

Every derived master key is unchanged by this: they come from the root key's
raw bytes, which rotation never alters, only its wrapping. No secret value is
ever re-encrypted as a result of a site-key rotation.

param: WP_Secrets_Keyring $old_keyring Unwraps the current wrapped root key.
param: WP_Secrets_Keyring $new_keyring Wraps it again for storage.
return: true|WP_Error

get_wrapped_root_key()   X-Ref
Returns the wrapped root key, adopting a pre-conversion copy if needed.

A single site converted to multisite keeps its wrapped root key in its own
(now main site's) options row: `update_site_option()` only starts writing to
sitemeta once `is_multisite()` is true, and the conversion process does not
move existing option rows. Without this, a network's first read would find no
sitemeta row and mint a brand new root key, stranding every secret written
before conversion.

return: mixed The wrapped root key, or false if none exists anywhere. Anything

generate_root_key()   X-Ref
Generates a new root key and persists it.

Handles the race where two requests both find no root key at the same time.

return: string|WP_Error

insert_root_key( string $wrapped )   X-Ref
Stores a new wrapped root key unless one is already stored.

This does not use add_site_option(). On a single site that is add_option(), which
skips its existence check for an option cached as missing and then overwrites the
stored row, so a failed read followed by add_option() would replace the root key.

param: string $wrapped The wrapped root key.
return: int ID of the inserted wp_sitemeta row on multisite, 0 otherwise.

read_stored_root_key()   X-Ref
Reads the wrapped root key from the database, bypassing the options cache.

get_site_option() returns false both when the root key does not exist and when
its query failed, and caches the option as missing either way. This read tells
the two apart. When the row exists, it also clears that cache entry.

return: string|false|WP_Error The wrapped root key, false if none is stored, or

forget_missing_root_key()   X-Ref
Removes the root key from the cache of options that do not exist.




Generated : Mon Nov 16 08:20:01 2026 Cross-referenced by PHPXref