Created
December 8, 2020 21:51
-
-
Save hgrimelid/598153cf2b4a570dd6dea86091dfae96 to your computer and use it in GitHub Desktop.
Wordpress: Remove access to and hide theme editor
This file contains 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 | |
/** | |
* This comes in handy in cases where you can't set `DISALLOW_FILE_MODS` to `true` | |
*/ | |
/** | |
* Remove access to page for all users | |
*/ | |
add_action('current_screen', function () { | |
$restricted_screens = [ | |
'theme-editor', | |
]; | |
$current_screen_id = get_current_screen()->id; | |
foreach ($restricted_screens as $restricted_screen) { | |
if ($restricted_screen === $current_screen_id) { | |
wp_die('You are not allowed to access this page.'); | |
} | |
} | |
}); | |
/** | |
* Remove page from menu | |
*/ | |
add_action('admin_menu', function () { | |
remove_submenu_page('themes.php', 'theme-editor.php'); | |
}, 999); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment