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.
// 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 );
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.
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.
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.
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.”