*/ public function unmet(): array { $unmet = array(); if ( null === $this->woocommerce_version ) { $unmet[] = self::WOOCOMMERCE_MISSING; } elseif ( version_compare( $this->woocommerce_version, self::MIN_WOOCOMMERCE . '.0', '<' ) ) { // Compared as x.y.0: version_compare() ranks "10.9.0-beta.1" // above "10.9" but, correctly, below "10.9.0". $unmet[] = self::WOOCOMMERCE_TOO_OLD; } if ( null === $this->agent_firewall_version ) { $unmet[] = self::AGENT_FIREWALL_MISSING; } elseif ( version_compare( $this->agent_firewall_version, self::MIN_AGENT_FIREWALL, '<' ) ) { $unmet[] = self::AGENT_FIREWALL_TOO_OLD; } elseif ( null === $this->extension_api_version ) { $unmet[] = self::EXTENSION_API_MISSING; } elseif ( ! self::api_supported( $this->extension_api_version ) ) { $unmet[] = self::EXTENSION_API_INCOMPATIBLE; } return $unmet; } /** * Whether every requirement is met. */ public function met(): bool { return array() === $this->unmet(); } /** * Admin-facing explanation of an unmet requirement. * * @param string $code One of the class constants. */ public static function message( string $code ): string { switch ( $code ) { case self::WOOCOMMERCE_MISSING: return __( 'Agent Firewall for WooCommerce needs WooCommerce to be active.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ); case self::WOOCOMMERCE_TOO_OLD: /* translators: %s: lowest supported WooCommerce version. */ return sprintf( __( 'Agent Firewall for WooCommerce needs WooCommerce %s or later.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), self::MIN_WOOCOMMERCE ); case self::AGENT_FIREWALL_MISSING: return __( 'Agent Firewall for WooCommerce needs Agentic Daisy AI Agent Firewall to be active.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ); case self::AGENT_FIREWALL_TOO_OLD: /* translators: %s: lowest supported Agent Firewall version. */ return sprintf( __( 'Agent Firewall for WooCommerce needs Agentic Daisy AI Agent Firewall %s or later. Update Agent Firewall.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ), self::MIN_AGENT_FIREWALL ); case self::EXTENSION_API_MISSING: return __( 'Agent Firewall for WooCommerce needs a newer Agentic Daisy AI Agent Firewall, one with the Extension API. Update Agent Firewall.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ); case self::EXTENSION_API_INCOMPATIBLE: return __( 'This version of Agent Firewall for WooCommerce does not support the installed Agentic Daisy AI Agent Firewall. Update both plugins.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ); default: return ''; } } /** * Whether an Extension API version is in the supported range: at least * MIN_EXTENSION_API and in the same major. The major is compared as a * number rather than with version_compare(), which ranks a pre-release * of the next major ("2.0.0-beta.1") below "2.0.0". * * @param string $version Extension API version. */ private static function api_supported( string $version ): bool { return version_compare( $version, self::MIN_EXTENSION_API, '>=' ) && self::major( $version ) === self::major( self::MIN_EXTENSION_API ); } /** * The major component of a version string. * * @param string $version Version. */ private static function major( string $version ): int { return (int) explode( '.', $version )[0]; } }