How to disable the theme and plugin file editor in WordPress
Published View as Markdown
Disable the file editor in WordPress two ways: the DISALLOW_FILE_EDIT constant in wp-config.php, or a switch you can undo from the dashboard. Plus how to check.
WordPress ships with two code editors inside the dashboard. Anyone with an administrator account can open a theme’s or plugin’s PHP files in a browser tab, change them and save. A stolen administrator login is one edit away from running its own code on your server, and a typo saved into functions.php can take the site down.
Many sites don’t use them. Here is how to disable the file editor in WordPress, two ways, and how to check it worked.
Where the file editors are
With a classic theme, Theme File Editor is under Appearance and Plugin File Editor is under Plugins. With a block theme, both are under Tools. On a multisite network only super admins have them.
If you are an administrator and can’t find either one, they are already off. Some hosts switch them off for you.
Disable the file editor with DISALLOW_FILE_EDIT
Add one line to wp-config.php, above the line that says to stop editing:
define( 'DISALLOW_FILE_EDIT', true );
Or set it with WP-CLI:
wp config set DISALLOW_FILE_EDIT true --raw
WordPress then refuses the three file-editing capabilities: edit_themes, edit_plugins and edit_files. That applies to every user, super admins included. Installs, updates and activations work as before.
The catch is the way back. The constant lives in a file, so switching the editors on again means editing wp-config.php over SFTP, SSH or a hosting file manager. Someone who only has a wp-admin login can’t undo it from the dashboard.
Disable the file editor with a switch you can undo
Adminkeep is a free plugin of small features with one switch each. One of them removes the theme and plugin file editors without touching wp-config.php.
- Go to Settings → Adminkeep.
- Switch on Disable File Editing. There is nothing else to set.
From WP-CLI:
wp adminkeep feature enable disable_file_edit
The switch refuses the same three capabilities as the constant, so the result in the dashboard is the same, super admins included. The difference is that an administrator can switch it off again from the same screen. On a multisite network it has to be on for the main site; the configuration docs explain why.
If the constant is already set, WordPress keeps enforcing it whatever the switch says. The two don’t conflict.
Check that it worked
- Theme File Editor and Plugin File Editor are gone from the menus.
- Open
/wp-admin/theme-editor.phpand/wp-admin/plugin-editor.phpdirectly. WordPress refuses to load either page and says you are not allowed.
What it does not do
- It only closes the dashboard route. Anyone with FTP, SSH or WP-CLI access can still change files.
- It doesn’t stop new code arriving. An administrator can still install a plugin or upload a ZIP. How to block plugin installs covers that.
- The switch is only as safe as the admin login. Whoever can reach the settings screen can turn it off, and that includes someone using a stolen administrator account. If that is the risk you plan for, use the constant.
There is a second constant with a similar name, DISALLOW_FILE_MODS, which also stops installs and updates. DISALLOW_FILE_MODS vs DISALLOW_FILE_EDIT compares the two before you pick.
Questions people ask
What does define( 'DISALLOW_FILE_EDIT', true ) do in WordPress?
It removes the Theme File Editor and the Plugin File Editor from the dashboard for every user, administrators included. WordPress refuses the edit_themes, edit_plugins and edit_files capabilities, so the menu items go and the editor screens refuse to load. Installing, updating, activating and deactivating plugins and themes still work.
Where is the theme file editor in WordPress?
With a classic theme, Theme File Editor is under Appearance and Plugin File Editor is under Plugins. With a block theme, both are under Tools. If you are an administrator on a single site and neither is there, the editors are already switched off, by the constant, a plugin or your host.
Does disabling the file editor stop plugin updates?
No. DISALLOW_FILE_EDIT only removes the two code editors. Installs and updates keep working. The constant that also stops installs and updates is DISALLOW_FILE_MODS.