checks[ $check->get_id() ] = $check; } /** * Runs the checks. * * @param bool $include_loopback Whether to run checks that request the site. * @return Result[] Findings, keyed by check identifier. */ public function run( bool $include_loopback = false ): array { $results = array(); foreach ( $this->checks as $id => $check ) { if ( $check->needs_loopback() && ! $include_loopback ) { continue; } $results[ $id ] = $check->run(); } return $results; } /** * Derives the overall verdict from a set of findings. * * @param Result[] $results Findings. * @return array Verdict with 'status', 'headline', 'explanation', 'action' and counts. */ public function summarise( array $results ): array { $enforcing = array(); $declaring = array(); $attention = array(); foreach ( $results as $result ) { if ( $result->is_enforcing() ) { $enforcing[] = $result->get_label(); } if ( Result::DECLARED === $result->get_status() ) { $declaring[] = $result->get_label(); } if ( $result->needs_attention() ) { $attention[] = $result->get_label(); } } $counts = array( 'enforcing' => count( $enforcing ), 'declaring' => count( $declaring ), 'attention' => count( $attention ), 'total' => count( $results ), ); if ( aiblackout_is_disabled() ) { return array( 'status' => Result::INACTIVE, 'headline' => __( 'AI Blackout is switched off.', 'ai-blackout' ), 'explanation' => __( 'The AIBLACKOUT_DISABLE setting in wp-config.php turns off everything this plugin does. Nothing is being blocked and nothing is being declared.', 'ai-blackout' ), 'action' => __( 'Remove the AIBLACKOUT_DISABLE line from wp-config.php to turn protection back on.', 'ai-blackout' ), 'layers' => array( 'enforcing' => $enforcing, 'declaring' => $declaring, 'attention' => $attention, ), 'counts' => $counts, ); } if ( empty( $enforcing ) && empty( $declaring ) ) { return array( 'status' => Result::INACTIVE, 'headline' => __( 'Your content is not protected.', 'ai-blackout' ), 'explanation' => __( 'Nothing is currently blocking AI crawlers or telling them to stay away.', 'ai-blackout' ), 'action' => __( 'Choose what AI is allowed to do with your content, below.', 'ai-blackout' ), 'layers' => array( 'enforcing' => $enforcing, 'declaring' => $declaring, 'attention' => $attention, ), 'counts' => $counts, ); } if ( empty( $enforcing ) ) { return array( 'status' => Result::DECLARED, 'headline' => __( 'You are asking AI crawlers to stay away, and not stopping them.', 'ai-blackout' ), 'explanation' => __( 'Your robots.txt rules are published, and crawlers that choose to obey them will leave you alone. Crawlers that ignore robots.txt are getting your content, because nothing is refusing them.', 'ai-blackout' ), 'action' => __( 'This is what "just state my terms" means. Choose one of the blocking answers below to turn it into a barrier.', 'ai-blackout' ), 'layers' => array( 'enforcing' => $enforcing, 'declaring' => $declaring, 'attention' => $attention, ), 'counts' => $counts, ); } if ( ! empty( $attention ) ) { return array( 'status' => Result::BROKEN, 'headline' => __( 'AI crawlers are being blocked, but part of your setup needs attention.', 'ai-blackout' ), 'explanation' => __( 'At least one layer is refusing AI crawlers. Something else is not working the way it should.', 'ai-blackout' ), 'action' => __( 'Open "Check exactly what is protecting you" below and follow the step on the layer marked for attention.', 'ai-blackout' ), 'layers' => array( 'enforcing' => $enforcing, 'declaring' => $declaring, 'attention' => $attention, ), 'counts' => $counts, ); } return array( 'status' => Result::PROTECTED_STATE, 'headline' => __( 'AI crawlers that identify themselves are being refused.', 'ai-blackout' ), 'explanation' => __( 'Requests from the AI crawlers you chose to block are turned away, and your robots.txt asks the rest to stay away. This does not stop a crawler that hides what it is. Nothing running on your own server can.', 'ai-blackout' ), 'action' => __( 'Nothing else to do.', 'ai-blackout' ), 'layers' => array( 'enforcing' => $enforcing, 'declaring' => $declaring, 'attention' => $attention, ), 'counts' => $counts, ); } /** * Runs the checks and returns findings plus verdict. * * @param bool $include_loopback Whether to run checks that request the site. * @return array Array with 'summary' and 'results'. */ public function report( bool $include_loopback = false ): array { $results = $this->run( $include_loopback ); return array( 'summary' => $this->summarise( $results ), 'results' => array_map( static function ( Result $result ) { return $result->to_array(); }, $results ), ); } }