managed_lines( $base ); if ( array() === $lines ) { return $base; } $prefix = $base; if ( '' !== $prefix && "\n" !== substr( $prefix, -1 ) ) { $prefix .= "\n"; } return $prefix . "\n" . RobotsMarkers::wrap( $lines ); } /** * Builds the directive lines AIVE contributes for the current policy. * * @since 1.2.0 * * @param string $existing_output Response text outside AIVE's markers. * @return array Directive lines, without the markers. */ public function managed_lines( $existing_output ) { $named = RobotsParser::agents( $existing_output ); $lines = array(); foreach ( Helpers::effective_bot_rules() as $token => $rule ) { if ( Helpers::RULE_NONE === $rule ) { continue; } // An existing group for this token stays authoritative. if ( isset( $named[ strtolower( $token ) ] ) ) { continue; } if ( array() !== $lines ) { $lines[] = ''; } $lines[] = 'User-agent: ' . $token; if ( Helpers::RULE_ALLOW === $rule ) { /* * The Disallow accompanying an Allow keeps the admin area out of * a crawl the site is otherwise inviting. It mirrors what * WordPress itself writes for `User-agent: *`. */ $lines[] = 'Allow: /'; $lines[] = 'Disallow: /wp-admin/'; continue; } $lines[] = 'Disallow: /'; } return $lines; } /** * Returns the generated robots.txt response without AIVE's contribution. * * Used by the admin screen to see the response as it would be if this * module were not installed, which is the only way to tell marker text * AIVE wrote from marker text left behind by a hand edit. Detaching and * reattaching the filter around the call is what keeps it from recursing. * * @since 1.2.0 * * @return string Generated response text without AIVE's block. */ public function foreign_output() { remove_filter( 'robots_txt', array( $this, 'filter_robots_txt' ), 10 ); $output = RobotsAudit::local_output(); add_filter( 'robots_txt', array( $this, 'filter_robots_txt' ), 10, 2 ); return $output; } }