Answers.Body: <p>This can be easy, write a module which can't be disabled or uninstall. See what's difference between module and plugin <a href="https://docs.craftcms.com/v3/extend/#modules-vs-plugins" rel="nofollow noreferrer">https://docs.craftcms.com/v3/extend/#modules-vs-plugins</a> or <a href="https://nystudio107.com/blog/enhancing-a-craft-cms-3-website-with-a-custom-module" rel="nofollow noreferrer">https://nystudio107.com/blog/enhancing-a-craft-cms-3-website-with-a-custom-module</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-14T18:16:14.523Z
Answers.LastActivityDate: 2018-10-14T18:16:14.523Z
Answers.UserDisplayName: lenka
Answers.Body: <p>Yes you can disable the ability to delete the plugin.</p>
  
  <p>First of all you can overwrite the function <a href="https://github.com/craftcms/cms/blob/develop/src/base/Plugin.php#L158" rel="nofollow noreferrer">uninstall</a> and just return false so it won't be removed. </p>
  
  <p>Furthermore you could use the event <a href="https://github.com/craftcms/cms/blob/develop/src/services/Plugins.php#L421" rel="nofollow noreferrer">EVENT_AFTER_DISABLE_PLUGIN</a> to enable it again. However: it seems like a simple module is better for this job instead of a plugin since they can't be uninstalled or deleted </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-14T14:57:48.597Z
Answers.LastActivityDate: 2018-10-14T14:57:48.597Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I am developing a site with a customer logged in area. I don't want anyone to access the section if they are logged out and instead redirect them to the login form. </p>
  
  <p>I could just add {% requireLogin %} to the top of all the member templates, but its open to error, especially if we have loads. I am concerned we may forget to add it, accidentally delete the line one day. Then private pages are public, not good. </p>
  
  <p>So I thought I would add the function to a plugin I have created for this site, to remove it from the template, and I can also target the whole /account/ segment where member templates are located.</p>
  
  <p>BUT, the plugin can be uninstalled or disabled. Various people will be Admins, and there is always the possibility someone could disable this for some reason, and then all private pages become public!</p>
  
  <p>So can we disable the ability to disable and uninstall plugins in the CP? The plugin will contain this and other site essential functions that we cant just have someone delete. They need to be fixed into the system to prevent accidental disabling. </p>
  
  <p>If not, is there an alternative way to add functions without using a plugin or controller, so we can override core actions like this without any CP control. </p>
  
  <p>Thanks!</p>
  
Tags: <plugin-development><login><controller>
Title: How to disable plugin Disable and Uninstall?
ThreadText: # How to disable plugin Disable and Uninstall?
  
  (Asked by: username_0 on 2018-10-14)
  
  I am developing a site with a customer logged in area. I don't want anyone to access the section if they are logged out and instead redirect them to the login form.
  
  I could just add {% requireLogin %} to the top of all the member templates, but its open to error, especially if we have loads. I am concerned we may forget to add it, accidentally delete the line one day. Then private pages are public, not good.
  
  So I thought I would add the function to a plugin I have created for this site, to remove it from the template, and I can also target the whole /account/ segment where member templates are located.
  
  BUT, the plugin can be uninstalled or disabled. Various people will be Admins, and there is always the possibility someone could disable this for some reason, and then all private pages become public!
  
  So can we disable the ability to disable and uninstall plugins in the CP? The plugin will contain this and other site essential functions that we cant just have someone delete. They need to be fixed into the system to prevent accidental disabling.
  
  If not, is there an alternative way to add functions without using a plugin or controller, so we can override core actions like this without any CP control.
  
  Thanks!
  
  **Tags:** plugin-development, login, controller
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-10-14. Score: 2
  
  This can be easy, write a module which can't be disabled or uninstall. See what's difference between module and plugin <https://docs.craftcms.com/v3/extend/#modules-vs-plugins> or <https://nystudio107.com/blog/enhancing-a-craft-cms-3-website-with-a-custom-module>
  
  
  ---
  
  ### Answer by username_2 on 2018-10-14. Score: 1
  
  Yes you can disable the ability to delete the plugin.
  
  First of all you can overwrite the function [uninstall](https://github.com/craftcms/cms/blob/develop/src/base/Plugin.php#L158) and just return false so it won't be removed.
  
  Furthermore you could use the event [EVENT\_AFTER\_DISABLE\_PLUGIN](https://github.com/craftcms/cms/blob/develop/src/services/Plugins.php#L421) to enable it again. However: it seems like a simple module is better for this job instead of a plugin since they can't be uninstalled or deleted
  
  
  ---
  
  