Support » Plugin: Notification - Custom Notifications and Alerts for WordPress » Fire notification on WP native actions

  • Resolved Damir Tahiri

    (@tahireu)


    Hi,

    How can I create a trigger which will fire a notification on native WP actions like wp_loaded or init ?

    I am following this article:
    https://www.smashingmagazine.com/2018/07/wordpress-notifications-made-easy/

    But when I add something like this to my functions.php file, I do see a new trigger called “Outbid” in the wp-admin, but nothing is happening on wp_loaded:

    class Outbid extends \BracketSpace\Notification\Abstracts\Trigger {
    
        public function __construct() {
    
            // Add slug and the title.
            parent::__construct(
                'outbid',
                __( 'Outbid', 'outbid' )
            );
    
            // Hook to the action.
            $this->add_action( 'wp_loaded' );
    
        }
    
        public function merge_tags() {}
    
    }
    register_trigger( new Outbid() );

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Kuba Mikita

    (@kubitomakita)

    Hi,

    please use this up-to-date documentation: https://docs.bracketspace.com/notification/developer/triggers/custom-trigger

    In general, having an action wp_loaded should successfully trigger the notification (if you add any in the wp-admin), but keep in mind it will run on every page load and every ajax request, etc.

    So you must:
    – register the trigger
    – add a valid notification via wp-admin
    – only then the trigger will be executed

    Thread Starter Damir Tahiri

    (@tahireu)

    Thanks for the quick answer! I made it with the latest/updated code and wp_loaded action, but it’s still not working, for example, init, or plugins_loaded.

    Actually, I need it for the woocommerce_simple_auctions_outbid action (https://wpgenie.org/woocommerce-simple-auctions/documentation/ plugin), but I didn’t wanted to confuse you with it – I am guessing that if it works with the WP native actions, it will work with this one also.

    • This reply was modified 2 years, 4 months ago by Damir Tahiri.
    Plugin Author Kuba Mikita

    (@kubitomakita)

    Yeah, the init and pluging_loaded are too early actions. The Notification plugin is not initialized at this stage. It loads all the triggers on init 1000 and that’s the earliest action.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Fire notification on WP native actions’ is closed to new replies.