Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 1007 Bytes

File metadata and controls

33 lines (25 loc) · 1007 Bytes

Advanced Plugin features

Subscriber Registration Checker

Subscriber Registration Checker Joomla\CMS\Event\SubscriberRegistrationCheckerInterface interface allows the Plugin to be checked before listener registration. This allows the plugin to be registered only when special conditions are met, e.g., only for specific applications.

Example:

Creating the plugin that will be run only for Administrator or Api application:

use Joomla\CMS\Event\SubscriberRegistrationCheckerInterface;
use Joomla\CMS\Plugin\CMSPlugin;

class MyExamplePlugin extends CMSPlugin implements SubscriberRegistrationCheckerInterface
{
    //... rest of the plugin code
    
    /**
     * Check whether the Subscriber (or event listener) should be registered.
     *
     * @return bool
     */
    public function shouldRegisterListeners(): bool
    {
        $app = $this->getApplication();
        
        return $app->isClient('administrator') || $app->isClient('api');
    }
}