Skip to content

Instantly share code, notes, and snippets.

@hgrimelid
Created December 8, 2020 21:51
Show Gist options
  • Save hgrimelid/598153cf2b4a570dd6dea86091dfae96 to your computer and use it in GitHub Desktop.
Save hgrimelid/598153cf2b4a570dd6dea86091dfae96 to your computer and use it in GitHub Desktop.
Wordpress: Remove access to and hide theme editor
<?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