Index of /ALFA_DATA/cgialfa/537149005

 NameLast modifiedSizeDescription

 Parent Directory   -  
 2094337930.txt 2026-10-27 14:58 2.3K 

<?php
/**
 * Plugin Name: Invest Kenya – Security Hardening
 * Description: Hides the public username list, blocks XML-RPC, turns off the built-in plugin/theme code editor and sends browser security headers. Deactivate to undo every change.
 * Version: 1.0.0
 * Author: Invest Kenya
 */
if ( ! defined( 'ABSPATH' ) ) { exit; }

/* 1. Built-in plugin and theme code editor off */
if ( ! defined( 'DISALLOW_FILE_EDIT' ) ) { define( 'DISALLOW_FILE_EDIT', true ); }

/* 2. XML-RPC off (old remote login route, used for password guessing) */
add_filter( 'xmlrpc_enabled', '__return_false' );
add_filter( 'xmlrpc_methods', function () { return array(); } );
add_filter( 'wp_headers', function ( $h ) { unset( $h['X-Pingback'] ); return $h; } );
remove_action( 'wp_head', 'rsd_link' );
add_action( 'plugins_loaded', function () {
	if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
		status_header( 403 );
		header( 'Content-Type: text/plain; charset=utf-8' );
		exit( 'XML-RPC is disabled on this site.' );
	}
}, 0 );

/* 3. Usernames not public: REST user list and ?author=N lookups for visitors */
add_filter( 'rest_endpoints', function ( $e ) {
	if ( is_user_logged_in() ) { return $e; }
	foreach ( array_keys( $e ) as $route ) {
		if ( 0 === strpos( $route, '/wp/v2/users' ) ) { unset( $e[ $route ] ); }
	}
	return $e;
} );
add_action( 'template_redirect', function () {
	if ( is_user_logged_in() ) { return; }
	if ( isset( $_GET['author'] ) || is_author() ) { wp_safe_redirect( home_url( '/' ), 301 ); exit; }
}, 0 );
add_filter( 'oembed_response_data', function ( $d ) { unset( $d['author_name'], $d['author_url'] ); return $d; } );
add_filter( 'wp_sitemaps_add_provider', function ( $p, $name ) { return 'users' === $name ? false : $p; }, 10, 2 );

/* 4. Browser security headers */
function ik_hd_headers() {
	if ( headers_sent() ) { return; }
	if ( is_ssl() ) { header( 'Strict-Transport-Security: max-age=31536000' ); }
	header( 'X-Content-Type-Options: nosniff' );
	header( 'X-Frame-Options: SAMEORIGIN' );
	header( 'Referrer-Policy: strict-origin-when-cross-origin' );
	header( 'Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=()' );
}
add_action( 'send_headers', 'ik_hd_headers' );
add_action( 'login_init', 'ik_hd_headers' );
add_action( 'admin_init', 'ik_hd_headers' );