1

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!

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

1

Yes you can disable the ability to delete the plugin.

First of all you can overwrite the function uninstall and just return false so it won't be removed.

Furthermore you could use the event EVENT_AFTER_DISABLE_PLUGIN 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.