Skip to content

Instantly share code, notes, and snippets.

@raazon
Created September 2, 2020 06:12
Show Gist options
  • Select an option

  • Save raazon/19e49fc6287aa1fd51d1cf724def9776 to your computer and use it in GitHub Desktop.

Select an option

Save raazon/19e49fc6287aa1fd51d1cf724def9776 to your computer and use it in GitHub Desktop.
Restrict access to admin pages
<?php defined('ABSPATH') || die('Cheatin&#8217; uh?'); // Cannot access pages directly.
/**
* Restrict access to admin pages
* @author Razon Kommar Pal
*/
add_action('admin_init', 'slug_restrict_access_for_specific_path');
function slug_restrict_access_for_specific_path()
{
$requested_url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$restrict_paths = ['themes', 'theme-editor', 'plugins', 'plugin-editor', 'plugin-install'];
if ($restrict_paths) {
foreach ($restrict_paths as $restrict_path) {
if (strpos($requested_url, $restrict_path) !== false) {
wp_die('Keep Silent! you can\'t access here for security reason');
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment