Monsieur Zartosht

Monsieur Zartosht

Who am I?

A very simple blog that belongs to a very simple full-stack web developer about his daily life and struggles through coding. here you will find many things such as music, movies, and code (lots of codes!)


What I write about


Recent Posts

How to actually disable disabled plugins in OctoberCMS

I came across a problem that when I'm developing plugins for OctoberCMS after I finished working with them, normally I disable them and got to create a new one. Okay? the problem is they still exist! all the routes, navigation menus, and everything still exists even after disabling them!

Table of contents

    Hi,

    In the last couple of months, I found a great CMS called OctberCMS. It is working with Laravel and you can build totally complex websites and apps at no time!

    October is a free, open-source, self-hosted CMS platform based on the Laravel PHP Framework. Thousands of digital studios and freelancers all over the world love October for its simplicity, flexibility, and modern design. Their clients are happy because October saves them both time and money.

    October CMS

    Disabled OctoberCMS plugins are still working

    If you got to the panel and disable any plugins, it says that the plugins are disabled but believe! they're not! they are still working, all the routes, controllers, middlewares and navigation menus!

    I searched a lot about this problem but I didn't found a proper answer to this problem, then I tried to make a way to at least control my own plugins to stop working after they are disabled.

    First, make a protected attribute in your Plugin class and call it isDisabled:

    protected $isDisabled;

    Then in the Plugin constructor do the following:

        public function __construct($app)
        {
            try {
                $this->isDisabled = PluginVersion::where("code", "Acme.Blog")->first()->is_disabled ? TRUE : FALSE;
            } catch (\Exception $exception) {
                $this->isDisabled = TRUE;
            }
            parent::__construct($app);
        }

    with this, now you know if your plugin is disabled or not!

    Then at the beginning of both boot and register methods add this:

        public function register()
        {
            if ($this->isDisabled) return;
    
            // Rest of your code goes here
        }
    
        public function boot()
        {
            if ($this->isDisabled) return;
    
            // Rest of your code goes here
        }

    By doing so, you prevent your plugin to be present in the app when you obviously disabled it!

    I don't know if what I've done was a good idea or not, but at least it solved my problem, Hope to fix yours too.


    Posted in CMS , OctoberCMS , PHP on by

    Share this post: