Created
September 2, 2020 06:12
-
-
Save raazon/19e49fc6287aa1fd51d1cf724def9776 to your computer and use it in GitHub Desktop.
Restrict access to admin pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php defined('ABSPATH') || die('Cheatin’ 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