wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_import_option_as_secret › WordPress Function
Seit7.2.0
Veraltetn/v
› wp_import_option_as_secret ( $option, $name )
| Parameter: (2) |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Imports an existing option's value as a secret.
For an explicit migration, "on their own explicit upgrade schedule," in the proposal's words, because "core cannot reliably tell which options are credentials, and guessing would break sites." The source option is left untouched: this reads it, it does not move or delete it. The imported secret is flagged needs_rotation, unconditionally. A credential that sat in a plain option has already been through however many backups and replication paths that option went through; re-encrypting it here does not undo that, and the flag exists so an operator (or a future admin screen) knows to actually rotate the value rather than considering the migration finished.Quellcode
function wp_import_option_as_secret( string $option, string $name ) {
if ( '' === $option ) {
return new WP_Error(
WP_SECRETS_ERROR_INVALID_VALUE,
__( 'The option name must not be empty.' )
);
}
$value = get_option( $option, null );
if ( null === $value ) {
return new WP_Error(
WP_SECRETS_ERROR_INVALID_VALUE,
__( 'The option does not exist.' )
);
}
if ( ! is_string( $value ) ) {
return new WP_Error(
WP_SECRETS_ERROR_INVALID_VALUE,
__( 'The option value is not a string and cannot be imported as a secret.' )
);
}
return _wp_secrets_set( $name, $value, false, true, 'imported' );
}