Hooks

Hooks: Lifecycle and Bootstrap

5 min read

These hooks run during plugin bootstrap, activation/deactivation, database maintenance, and global service registration. They are the right place to register your own services or react to plugin lifecycle events.

Source: Plugin.php, Maintenance.php, infrastructure service providers. Index: Hook Reference Hub. Boot order: Getting Started for Developers.

Plugin lifecycle (actions)

HookParametersDescription
notifal/initializednoneCore plugin class finished initializing; safe to call notifal_app() and register module hooks
notifal/readynonePlugin fully loaded and ready
notifal/activatednoneFires on plugin activation (Maintenance.php)
notifal/deactivatednoneFires on plugin deactivation
notifal/uninstallingnoneFires during uninstall cleanup
notifal/deactivation/feedback_submittedarray $feedback_dataDeactivation survey submitted
notifal/deactivation/feedback_skippedarray $site_dataDeactivation survey skipped
notifal/onpage_post_type/registerednoneOn-page notification CPT registered

Pro equivalent: notifal_pro/initialized (see Pro Integration Bridge).

Infrastructure and module services (filters)

Register or replace service classes before they are booted.

HookParametersDescription
notifal/infrastructure/servicesstring[] $servicesGlobal infrastructure service class names (admin menu, shared assets, etc.)
notifal/onpage/servicesstring[] $servicesOnPageNotification module services
notifal/templates/servicesstring[] $servicesTemplates module services
notifal/tags/servicesstring[] $servicesTags domain services
notifal/settings/servicesstring[] $servicesSettings domain services
notifal/deactivation/servicesstring[] $servicesDeactivation popup services
notifal/campaign/servicesstring[] $servicesCampaign module services

Each entry is a fully qualified class name with a static or instance register() method. See Architecture Overview for the service provider pattern.

Post type registration (filters)

HookParametersDescription
notifal/onpage_post_type/argsarray $argsOn-page notification CPT registration arguments
notifal/template_post_type/argsarray $argsTemplate CPT registration arguments
notifal/post_type_discovery/excluded_typesstring[] $excludedTypesPost types excluded from tag-generation discovery

Database migrations and cleanup (actions)

HookParametersDescription
notifal/database/migrations/before_runnoneBefore global database migrations
notifal/database/migrations/after_runnoneAfter global database migrations
notifal/database/cleanup/completednoneAfter old data cleanup finishes
notifal/database/cleanup_old_dataint $daysOldTrigger cleanup of data older than N days
notifal/onpage/database/migrations/before_runstring $fromVersion, string $toVersionBefore OnPage module migrations
notifal/onpage/database/migrations/after_runstring $fromVersion, string $toVersionAfter OnPage module migrations
notifal/onpage/database/cleanup/completednoneAfter OnPage-specific DB cleanup
notifal/onpage/database/tables_cleaned_upnoneAfter OnPage table cleanup; extend with custom cleanup

Database table registry (filter)

HookParametersDescription
notifal/database/table_namesarray $tablesRegister custom table names for maintenance operations

Event queue and cron (actions)

Background processing for tracking and related events.

HookParametersDescription
notifal/onpage/event/before_queuearray $eventDataBefore an event is queued
notifal/onpage/event/after_queueint $queueId, array $eventDataAfter an event is queued
notifal/onpage/event/processing/beforeint $batchSizeBefore processing a batch of queued events
notifal/onpage/event/processing/afterint $processedCount, int $errorCount, float $processingTimeAfter batch processing (time in ms)
notifal/onpage/cron/processing/completedarray $resultAfter cron event processing run
notifal/onpage/cron/cleanup/completedarray $resultAfter cron queue cleanup
notifal/campaign/cron/end_date_expiry_completedint $updated_countAfter hourly job marks expired campaigns inactive

Related filters: notifal/onpage/event/queue_data, notifal/onpage/tracking/use_queue in Analytics and Tracking.

Global settings (actions and filters)

HookTypeParametersDescription
notifal/setting/updatedactionstring $key, mixed $valueA setting value was saved
notifal/settings/resetactionnoneAll settings reset to defaults
notifal/generated_tags/savedactionnoneGenerated custom post type tags saved
notifal/generated_tags/removedactionnoneGenerated tags removed

Settings page UI hooks live in Admin UI Extension.

Frontend asset registration (actions)

HookParametersDescription
notifal/frontend/assets/before_registernoneBefore frontend scripts/styles are registered
notifal/frontend/assets/after_registernoneAfter frontend registration
notifal/frontend/assets/before_enqueuenoneBefore conditional frontend enqueue
notifal/frontend/assets/after_enqueuenoneAfter conditional frontend enqueue

On-page-specific load decisions: notifal/onpage/frontend/should_load_assets and related filters in Notifications and Eligibility.

Gutenberg block rendering (actions)

Dynamic hook pattern: append the block slug to the base constant.

Base hookParametersDescription
notifal/block/render/before + _{block_slug}variesBefore a Notifal block renders on the frontend
notifal/block/render/after + _{block_slug}variesAfter a Notifal block renders

Toast notifications (filter)

Admin redirect toast messages after save actions.

HookParametersDescription
notifal/toast/typestring $typeToast type (success, error, etc.)
notifal/toast/messagestring $messageToast message before query string storage

Action: notifal/toast/dispatched (final message, type, redirect URL) , documented in Admin UI Extension.

Campaign settings (filter)

HookParametersDescription
notifal/campaign/settingsarray $settingsCampaign settings before use or storage

Campaign save/status actions are in Notifications and Eligibility.

Hooks series

  1. Hook Reference Hub
  2. Hooks: Lifecycle and Bootstrap (you are here)
  3. Hooks: Notifications and Eligibility
  4. Hooks: Templates and Rendering
  5. Hooks: Tags and Dynamic Data
  6. Hooks: Display Rules and Content Source
  7. Hooks: Analytics and Tracking
  8. Hooks: Admin UI Extension
  9. Hooks: Pro Integration Bridge