How to Disable Theme Plugin Editor and Plugin Core Updates in WordPress

WPTurbo » Snippets » How to Disable Theme Plugin Editor and Plugin Core Updates in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you tired of accidentally making unintended changes to your WordPress theme or plugins? Or maybe you’re concerned about keeping your website secure by regularly updating your plugins? In this article, we will discuss how to disable the theme and plugin editors in WordPress, as well as how to prevent core updates for specific plugins. By implementing these techniques, you can ensure that your website remains stable, secure, and free from accidental modifications.

					function wpturbo_disable_theme_plugin_editor() {
    define('DISALLOW_FILE_EDIT', true);
}

add_action('admin_init', 'wpturbo_disable_theme_plugin_editor');

function wpturbo_disable_plugin_core_updates($value) {
    unset($value->response['hello.php']); // replace hello.php with your plugin file
    return $value;
}

add_filter('site_transient_update_plugins', 'wpturbo_disable_plugin_core_updates');
				

The code snippet provided here demonstrates how to disable the theme and plugin editor in WordPress, as well as how to prevent core updates for specific plugins.

The first function, wpturbo_disable_theme_plugin_editor(), uses the define() function to set the constant DISALLOW_FILE_EDIT to true. This constant is recognized by WordPress and prevents users from accessing the theme and plugin editors in the WordPress admin dashboard. By disabling these editors, you can enhance the security of your WordPress site as it prevents unauthorized access and modifications to the code.

The add_action() function is then used to hook the wpturbo_disable_theme_plugin_editor() function to the admin_init action. This ensures that the function is executed at the initialization of the admin area, effectively disabling the theme and plugin editors.

Next, we have the wpturbo_disable_plugin_core_updates() function. This function is used to prevent core updates for specific plugins. In the example provided, the function removes the update response for the 'hello.php' file, which represents the "Hello Dolly" plugin. You can replace 'hello.php' with the filename of the plugin you want to exclude from core updates. By removing the update response for a specific plugin, you are essentially blocking any updates for that plugin.

The add_filter() function is then used to hook the wpturbo_disable_plugin_core_updates() function to the site_transient_update_plugins filter. This filter is responsible for providing information about available plugin updates. By implementing this filter, we intercept the update response and remove the update for the specified plugin, effectively preventing the core update for that plugin.

By utilizing these two functions and their respective hooks, you can disable the theme and plugin editor in WordPress and prevent core updates for specific plugins. This can help you maintain better control over your WordPress site’s code and ensure that your plugins remain in the desired state without being automatically updated.

Register an account to save your snippets or go Pro to get more features.