Security PHP Beginner

Disable the Theme and Plugin File Editor

Remove the built-in code editors from wp-admin so a stolen admin login can't be used to edit PHP files on your server.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
wp-config.php 6 lines
// Remove Appearance > Theme File Editor and Plugins > Plugin File Editor.
define( 'DISALLOW_FILE_EDIT', true );

// Optional: also block installing, updating and deleting plugins and themes from wp-admin.
// Only use this if you update through Git, WP-CLI or your host.
// define( 'DISALLOW_FILE_MODS', true );

Where to add this

Recommended wp-config.php Above the line that says "That's all, stop editing!" in your wp-config.php file.

WordPress ships with two code editors in wp-admin: the Theme File Editor and the Plugin File Editor. They let any administrator change PHP files on the server from a browser. If an attacker ever gets an admin login, this is the first place they go to plant a backdoor.

Where it goes

This belongs in wp-config.php, above the line that says “That’s all, stop editing!”. WordPress reads the constant when it builds the admin menus and checks capabilities, and wp-config.php is guaranteed to load before any of that. Putting it in a theme or snippets plugin usually works too, but it can load too late on some screens and it disappears if that theme or plugin is turned off.

How it works

DISALLOW_FILE_EDIT removes the edit_themes, edit_plugins and edit_files capabilities from every user, including administrators. The editor menu items disappear and visiting their URLs directly shows a permissions error.

The commented-out DISALLOW_FILE_MODS goes further and also removes installing, updating and deleting plugins and themes, and core updates from the dashboard. That’s a good fit for sites deployed from Git or managed by a host, and a bad fit for sites where someone updates plugins by clicking Update.

How to test it

Log in as an administrator and open the Appearance menu. “Theme File Editor” should be gone. Visiting /wp-admin/theme-editor.php directly should show “Sorry, you are not allowed to edit templates for this site.”

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only