&lt;?php
/**
 * Plugin Name: GeekBlog: Query Param Hygiene
 * Description: Usuwa parametr wordfence_syncAttackData i podobne smieci z generowanych linkow paginacji, przekierowuje zasmiecone adresy paginacji na czyste, oznacza reszte jako noindex i blokuje je w robots.txt. Dodane 2026-09-21.
 * Version: 1.0
 * Author: GeekBlog
 */

defined( 'ABSPATH' ) || exit;

class GB_Query_Param_Hygiene {

	public static function junk() {
		return array(
			'wordfence_syncAttackData',
			'wordfence_lh',
			'wordfence_logHuman',
			'wfwaf-authcookie',
		);
	}

	public static function init() {
		add_filter( 'get_pagenum_link', array( __CLASS__, 'clean' ), 99 );
		add_filter( 'paginate_links', array( __CLASS__, 'clean' ), 99 );
		add_filter( 'rank_math/frontend/canonical', array( __CLASS__, 'clean' ), 99 );
		add_action( 'template_redirect', array( __CLASS__, 'guard' ), 1 );
		add_filter( 'robots_txt', array( __CLASS__, 'robots' ), 20 );
	}

	public static function clean( $url ) {
		if ( ! is_string( $url ) || false === strpos( $url, '?' ) ) {
			return $url;
		}
		return remove_query_arg( self::junk(), $url );
	}

	public static function has_junk() {
		foreach ( self::junk() as $key ) {
			if ( isset( $_GET[ $key ] ) ) {
				return true;
			}
		}
		return false;
	}

	public static function guard() {

		if ( is_admin() || is_user_logged_in() ) {
			return;
		}

		if ( ( defined( 'DOING_AJAX' ) &amp;&amp; DOING_AJAX ) || ( defined( 'DOING_CRON' ) &amp;&amp; DOING_CRON ) || ( defined( 'REST_REQUEST' ) &amp;&amp; REST_REQUEST ) ) {
			return;
		}

		if ( ! self::has_junk() ) {
			return;
		}

		$uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '';

		// Adresy paginacji z doklejonym parametrem to czysty smiec po crawlerze.
		// Wordfence odpala swoj sync tylko na biezacym adresie, wiec paginacje mozna bezpiecznie
		// sprowadzic jednym 301 do czystego adresu. Reszta dostaje tylko noindex, zeby nie
		// psuc wlasciwego mechanizmu Wordfence na stronie glownej i wpisach.
		if ( false !== strpos( $uri, '/page/' ) || is_paged() ) {

			$clean = remove_query_arg( self::junk(), home_url( $uri ) );

			if ( $clean &amp;&amp; $clean !== home_url( $uri ) ) {
				wp_safe_redirect( $clean, 301 );
				exit;
			}
		}

		if ( ! headers_sent() ) {
			header( 'X-Robots-Tag: noindex, nofollow', true );
		}
	}

	public static function robots( $output ) {

		$rules = "\n# Smieci po crawlerach i wtyczkach: nie indeksujemy i nie crawlujemy.\n";

		foreach ( self::junk() as $key ) {
			$rules .= 'Disallow: /*' . $key . "\n";
		}

		return $output . $rules;
	}
}

GB_Query_Param_Hygiene::init();
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//geekblog.net/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://geekblog.net/post-sitemap1.xml</loc>
		<lastmod>2026-09-21T07:33:22+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/post-sitemap2.xml</loc>
		<lastmod>2026-09-21T07:32:34+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/post-sitemap3.xml</loc>
		<lastmod>2026-09-21T07:31:46+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/post-sitemap4.xml</loc>
		<lastmod>2026-09-21T07:30:58+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/post-sitemap5.xml</loc>
		<lastmod>2026-09-21T07:30:50+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/post-sitemap6.xml</loc>
		<lastmod>2026-09-21T07:30:49+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/post-sitemap7.xml</loc>
		<lastmod>2026-09-21T07:30:48+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/post-sitemap8.xml</loc>
		<lastmod>2026-09-20T17:07:07+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/post-sitemap9.xml</loc>
		<lastmod>2026-09-20T15:45:57+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/post-sitemap10.xml</loc>
		<lastmod>2026-09-20T14:16:41+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://geekblog.net/page-sitemap.xml</loc>
		<lastmod>2026-09-04T09:09:11+00:00</lastmod>
	</sitemap>
<sitemap>
	<loc>https://geekblog.net/news-sitemap.xml</loc>
	<lastmod>2026-09-21T07:30:49+00:00</lastmod>
</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->