` mit noindex, nofollow (Filter `wp_robots`) * - Header `X-Robots-Tag: noindex, nofollow` * - `robots.txt` mit `Disallow: /` (WordPress 7.1 gibt das selbst nicht aus, * auch nicht bei `blog_public=0`; Spike T1) * * Die Option `blog_public` wird nie veraendert: Nach dem Abschalten des * Schutzes ist alles wie vorher. */ if ( ! defined( 'ABSPATH' ) ) { exit; } class Wp360_Staging_Guard_Visibility { public static function init() { add_filter( 'wp_robots', array( __CLASS__, 'robots' ), 99 ); add_filter( 'robots_txt', array( __CLASS__, 'robots_txt' ), 99, 2 ); add_action( 'send_headers', array( __CLASS__, 'send_header' ) ); } /** * Soll noindex gesetzt werden? * * @return bool */ public static function is_enabled() { return Wp360_Staging_Guard_Environment::is_active() && ! empty( Wp360_Staging_Guard_Settings::get()['noindex'] ); } /** * @param array $robots Direktiven. * @return array */ public static function robots( $robots ) { if ( ! self::is_enabled() || ! is_array( $robots ) ) { return $robots; } $robots['noindex'] = true; $robots['nofollow'] = true; return $robots; } /** * @param string $output Bisherige Ausgabe. * @param bool $public Ob die Website als oeffentlich gilt. * @return string */ public static function robots_txt( $output, $public ) { if ( ! self::is_enabled() ) { return $output; } return "User-agent: *\nDisallow: /\n"; } public static function send_header() { if ( self::is_enabled() && ! headers_sent() ) { header( 'X-Robots-Tag: noindex, nofollow', false ); } } }