diff --git a/docs/building-extensions/plugins/advanced-plugin-features.md b/docs/building-extensions/plugins/advanced-plugin-features.md new file mode 100644 index 00000000..f8d116e1 --- /dev/null +++ b/docs/building-extensions/plugins/advanced-plugin-features.md @@ -0,0 +1,33 @@ +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: + +```php +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'); + } +} +``` diff --git a/migrations/51-52/new-features.md b/migrations/51-52/new-features.md index 246c7074..b598c30b 100644 --- a/migrations/51-52/new-features.md +++ b/migrations/51-52/new-features.md @@ -16,3 +16,11 @@ This new feature adds a "total" counter at the bottom near the pagination in Joo displaying the number of items available after applying filters for easier item management. PR: [43575](https://github.com/joomla/joomla-cms/pull/43575) + + +#### New interface for Plugins `SubscriberRegistrationCheckerInterface` + +Adding interface that allows the Plugin to be checked before listener registration. +PR: https://github.com/joomla/joomla-cms/pull/43657 + +More details here [Subscriber Registration Checker](https://manual.joomla.org/docs/building-extensions/plugins/advanced-plugin-features#subscriber-registration-checker).