Menü schliessen
Created: January 19th 2024
Last updated: March 16th 2024
Categories: Common Web Development,  Php,  Wordpress
Author: Tim Fürer

WordPress: How to disable admin theme- and plugin editors

Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

WordPress provides users with the ability to edit plugin and theme files directly from the admin dashboard. While this feature offers convenience for quick fixes and customization, it also presents a significant security risk. If an unauthorized user gains access to the admin panel, they could potentially inject malicious code into plugins or themes, compromising the entire website. Additionally, accidental modifications by inexperienced users could lead to website errors or downtime.


Disabling the Editors

Thankfully, WordPress offers a simple solution to mitigate these risks by disabling the plugin and theme editors altogether. This can be achieved by adding a snippet of code to the theme's functions.php file or a custom plugin. Here's how:

<?php

function disable_file_editors() {
    define('DISALLOW_FILE_EDIT', true);
}
add_action('admin_init', 'disable_file_editors');

?>

This code snippet utilizes the admin_init hook to define the constant DISALLOW_FILE_EDIT as true, effectively disabling both the plugin and theme editors.


Benefits

  • Enhanced Security: By disabling the plugin and theme editors, you reduce the attack surface for potential hackers. Even if someone gains unauthorized access to the admin panel, they won't be able to directly modify crucial files, significantly reducing the risk of a compromise.
  • Prevention of Accidental Changes: Inexperienced users might inadvertently make changes to plugin or theme files that could break the website. Disabling the editors helps prevent such accidents, ensuring the stability of your site.
  • Encouragement of Best Practices: By disabling direct file editing, you encourage the adoption of best practices such as utilizing child themes for theme modifications and implementing version control for plugin development. These practices promote a more organized and secure development environment.

Alternatives for File Management

Disabling the plugin and theme editors doesn't mean sacrificing the ability to manage files altogether. Solutions such as FTP (File Transfer Protocol) or SFTP (SSH File Transfer Protocol) will still allow you to access your website files remotely.