403 ) ); } $api_key = $request->get_header( 'x_api_key' ); if ( empty( $api_key ) ) { return new WP_Error( 'aeocas_missing_api_key', __( 'Missing x-api-key header.', 'aeo-content-ai-studio' ), array( 'status' => 401 ) ); } if ( ! hash_equals( $plugin_token, $api_key ) ) { return new WP_Error( 'aeocas_invalid_api_key', __( 'Invalid site credential.', 'aeo-content-ai-studio' ), array( 'status' => 401 ) ); } return true; } /** * Generate a cryptographically secure plugin token. * * @return string 64-character hex string (32 random bytes). */ public static function generate_plugin_token() { return bin2hex( random_bytes( 32 ) ); } }