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



wp_is_secrets_api_available › WordPress Function

Since7.2.0
已弃用n/a
› wp_is_secrets_api_available ( 没有参数 )
返回:
  • (bool)
定义在:
文档:

Whether the Secrets API can store and read secrets on this site.

A plugin can check this before it moves a credential into the Secrets API, and keep its existing storage while it returns false: if ( wp_is_secrets_api_available() ) { // Move the credential, then use wp_set_secret() and wp_get_secret(). } else { // Keep using the existing storage. } Returns false when the secrets.php drop-in failed to load, when the default keyring has no usable WP_SECRETS_KEY, or when WP_SECRETS_KEY cannot unwrap the stored root key. The last happens when a site that already stored secrets adds or changes the key without re-wrapping the root key. A provider or keyring from a working drop-in manages its own keys, so it is reported as available. Its backend can still be unreachable on a given request, which each call reports as a WP_Error. Whether the provider accepts writes is a separate question. See wp_secrets_provider_is_writable().


源码

function wp_is_secrets_api_available(): bool {
	if ( _wp_secrets_get_provider() instanceof WP_Secrets_Broken_Provider ) {
		return false;
	}

	if ( isset( $GLOBALS['wp_secrets_provider'] ) ) {
		return true;
	}

	$keyring = _wp_secrets_get_key_manager()->get_keyring();

	if ( $keyring instanceof WP_Secrets_Broken_Keyring ) {
		return false;
	}

	if ( $keyring instanceof WP_Secrets_Config_Key_Provider ) {
		$is_usable = in_array(
			$keyring->get_key_status(),
			array( WP_Secrets_Config_Key_Provider::KEY_STATUS_BASE64, WP_Secrets_Config_Key_Provider::KEY_STATUS_LEGACY ),
			true
		);

		if ( ! $is_usable ) {
			return false;
		}

		$root_key = _wp_secrets_get_key_manager()->get_root_key( false );

		if ( ! is_wp_error( $root_key ) ) {
			wp_secrets_memzero( $root_key );

			return true;
		}

		// With no root key stored yet, the first write creates one under this key.
		return false === get_site_option( WP_Secrets_Key_Manager::ROOT_KEY_OPTION );
	}

	return true;
}