cache = $cache; $this->server = $server; $this->htaccess = $htaccess; $this->matcher = $matcher; } /** * Returns the check identifier. * * @return string Identifier. */ public function get_id(): string { return 'php_gate'; } /** * Whether a loopback request is required. * * @return bool False. */ public function needs_loopback(): bool { return false; } /** * Runs the check. * * @return Result The finding. */ public function run(): Result { $label = __( 'WordPress blocking (PHP)', 'ai-blackout' ); $tokens = $this->matcher->get_enforceable_tokens(); $caching = $this->cache->is_operating(); $htaccess = $this->htaccess->is_applied(); $detail = array( 'token_count' => count( $tokens ), 'tokens' => $tokens, 'cache_operating' => $caching, 'cache_evidence' => $this->cache->get_evidence(), ); if ( aiblackout_is_disabled() ) { return new Result( $this->get_id(), $label, Result::INACTIVE, __( 'AI Blackout is switched off by the AIBLACKOUT_DISABLE setting in wp-config.php.', 'ai-blackout' ), __( 'No requests are being blocked by WordPress.', 'ai-blackout' ), __( 'Remove the AIBLACKOUT_DISABLE line from wp-config.php to turn protection back on.', 'ai-blackout' ), $detail ); } if ( empty( $tokens ) ) { return new Result( $this->get_id(), $label, Result::INACTIVE, __( 'WordPress is refusing nobody, because no crawler is set to be blocked.', 'ai-blackout' ), __( 'Nothing is being refused, because nothing has been chosen to refuse.', 'ai-blackout' ), __( 'Choose one of the blocking answers at the top of this screen.', 'ai-blackout' ), $detail ); } if ( $caching && ! $htaccess ) { return new Result( $this->get_id(), $label, Result::INERT, sprintf( /* translators: %d: Number of crawler tokens. */ _n( 'WordPress is set to refuse %d crawler, but a page cache is serving visitors before WordPress runs.', 'WordPress is set to refuse %d crawlers, but a page cache is serving visitors before WordPress runs.', count( $tokens ), 'ai-blackout' ), count( $tokens ) ), __( 'Most AI crawlers are getting your pages anyway. When a page is served from the cache, WordPress never loads, so this layer never gets the chance to refuse anything. Right now robots.txt is the only thing asking them to stay away, and it is a request, not a barrier.', 'ai-blackout' ), $this->server->supports_htaccess() ? __( 'Server rules would close this gap completely, and they could not be written. See the .htaccess layer above for why.', 'ai-blackout' ) : __( 'Add the nginx rule to your server configuration, or ask your host to add it. A CDN in front of your site, such as Cloudflare, can also block these requests before the cache is consulted. That is set up in the CDN, not here.', 'ai-blackout' ), $detail ); } if ( $caching ) { return new Result( $this->get_id(), $label, Result::PROTECTED_STATE, __( 'WordPress is refusing crawlers, and your server rules are covering the requests it cannot see.', 'ai-blackout' ), __( 'A page cache is active, so many visitors never reach WordPress. But your server-level rules block AI crawlers before the cache is consulted, so they are refused either way.', 'ai-blackout' ), '', $detail ); } return new Result( $this->get_id(), $label, Result::PROTECTED_STATE, sprintf( /* translators: %d: Number of crawler tokens. */ _n( 'WordPress is refusing %d AI crawler.', 'WordPress is refusing %d AI crawlers.', count( $tokens ), 'ai-blackout' ), count( $tokens ) ), __( 'Blocked crawlers get a 403 refusal. No page cache was detected, so requests are reaching WordPress and this layer is doing its job. If you add a caching plugin later, check this screen again.', 'ai-blackout' ), '', $detail ); } }