wpseek.com
WordPress开发者和主题制作者的搜索引擎



wp_import_option_as_secret › WordPress Function

Since7.2.0
已弃用n/a
› wp_import_option_as_secret ( $option, $name )
参数: (2)
  • (string) $option The existing option's name.
    Required: Yes
  • (string) $name The secret's namespaced name to store it under.
    Required: Yes
返回:
  • (true|WP_Error)
定义在:
文档:

Imports an existing option's value as a secret.

For an explicit migration on the caller's own schedule, 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.


源码

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' );
}