settings = $settings; } public function register(): void { add_filter( 'wp_robots', array( $this, 'force_noindex' ), 99 ); add_filter( 'wp_sitemaps_enabled', array( $this, 'maybe_disable_sitemap' ) ); } /** * @param array $robots * * @return array */ public function force_noindex( array $robots ): array { if ( ! $this->enabled() ) { return $robots; } $robots['noindex'] = true; $robots['nofollow'] = true; unset( $robots['index'], $robots['follow'], $robots['max-image-preview'] ); return $robots; } public function maybe_disable_sitemap( bool $enabled ): bool { return $this->enabled() ? false : $enabled; } private function enabled(): bool { return (bool) ( $this->settings->get()['hide_from_search'] ?? false ); } }