How to Completely Disable Editors and Plugin Modifications in WordPress

Home » Snippets » How to Completely Disable Editors and Plugin Modifications 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 looking to gain more control over your WordPress website by disabling the editors and plugin modifications entirely? Whether you want to restrict access to certain features for security reasons or streamline the website’s management, disabling editors and plugin modifications can be an effective solution. In this article, we will guide you through the steps to disable editors and plugin modifications entirely on your WordPress site. By implementing these measures, you can ensure a more secure and streamlined website management experience.

					function wpturbo_disable_editors_and_plugins() {
   if ( current_user_can( 'activate_plugins' ) ) {
      return;
   }
   remove_submenu_page( 'themes.php', 'theme-editor.php' );
   remove_submenu_page( 'plugins.php', 'plugin-editor.php' );
}
add_action( 'admin_menu', 'wpturbo_disable_editors_and_plugins', 999 );
				

The code snippet above allows you to disable the editors and plugin modifications entirely in the WordPress admin dashboard.

The wpturbo_disable_editors_and_plugins() function is defined at the beginning of the snippet. This function is responsible for checking if the current user has the capability to activate plugins. If the user has the activate_plugins capability, the function will simply return and do nothing. This is important because we want to allow administrators, who have this capability, to access the editors and plugin modifications.

The next lines of code, remove_submenu_page( 'themes.php', 'theme-editor.php' ); and remove_submenu_page( 'plugins.php', 'plugin-editor.php' );, are used to remove the submenu pages for the theme editor and plugin editor.

The remove_submenu_page() function accepts two parameters: the first parameter is the parent menu slug, and the second parameter is the submenu slug. In this case, themes.php and plugins.php are the parent menu slugs, and theme-editor.php and plugin-editor.php are the submenu slugs for the theme editor and plugin editor, respectively.

By removing these submenu pages, you effectively disable the ability to access the theme editor and plugin editor from the WordPress admin dashboard.

The last line of code, add_action( 'admin_menu', 'wpturbo_disable_editors_and_plugins', 999 );, hooks the wpturbo_disable_editors_and_plugins() function to the admin_menu action. By using a high priority of 999, we ensure that the function is executed at the appropriate time when the admin menu is being generated.

Overall, this code snippet is a simple and effective way to disable the editors and plugin modifications in the WordPress admin dashboard for users who do not have the activate_plugins capability.

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