Per-site key cache for the request. */ private static array $cache = array(); /** The signing key for the current site. */ public static function get(): string { $site = function_exists( 'get_current_blog_id' ) ? (int) get_current_blog_id() : 1; if ( ! isset( self::$cache[ $site ] ) ) { $secret = self::explicit(); if ( '' === $secret ) { $secret = wp_salt( 'secure_auth' ); } self::$cache[ $site ] = hash_hmac( 'sha256', 'ops404-activity-log-chain-v1|' . $site, $secret ); } return self::$cache[ $site ]; } /** * A short public identifier of the key, stored beside the state it signs * so a changed key (rotated salts) is reported as that rather than as a * wall of forged rows. It reveals nothing usable about the key. * * @param string $key Signing key. */ public static function fingerprint( string $key ): string { return substr( hash_hmac( 'sha256', 'fingerprint', $key ), 0, 16 ); } /** * Whether the key comes from wp-config.php rather than from the options * table. See the class docblock for what that decides. */ public static function config_backed(): bool { if ( '' !== self::explicit() ) { return true; } foreach ( array( 'SECURE_AUTH_KEY', 'SECURE_AUTH_SALT' ) as $name ) { if ( ! defined( $name ) ) { return false; } $value = (string) constant( $name ); if ( '' === $value || 'put your unique phrase here' === $value ) { return false; } } return true; } /** Forget the cached key (tests, and a restart after the constant changes). */ public static function reset(): void { self::$cache = array(); } private static function explicit(): string { if ( ! defined( self::CONSTANT ) ) { return ''; } $value = constant( self::CONSTANT ); return is_string( $value ) ? $value : ''; } }