Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from MikeNGarrett/wp-config.php
Created December 2, 2020 17:20
Show Gist options
  • Select an option

  • Save dexit/f7a2f13c088246193f74b32220054589 to your computer and use it in GitHub Desktop.

Select an option

Save dexit/f7a2f13c088246193f74b32220054589 to your computer and use it in GitHub Desktop.
Disable admin-ajax on the front-end of WordPress sites and cache the resulting 404.
<?php
if(
strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) === false &&
strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) !== false
) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', strtotime( '+5000 minutes' ) ) . ' GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', strtotime( '-5000 minutes' ) ) . ' GMT' );
header( $_SERVER["SERVER_PROTOCOL"]." 404 Not Found" );
die;
}
@seyntjim
Copy link

PHP Warning: Undefined array key "HTTP_REFERER" in /var/www/example.com/wp-config.php on line 10" while reading response. Any with for this error? I'm using php 8.1. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment