Adding Merge Tags to existing Triggers

You can add merge tags to any existing Triggers very easily. Just add this snippet to your code.

// Hook just after the Triggers are registered.
add_action( 'notification/trigger/registered', function( $trigger ) {

	// Check if registered Trigger is the one we need.
	if ( $trigger->get_slug() != 'wordpress/post/updated' ) {
		return;
	}

	$trigger->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\StringTag( array(
		'slug'        => 'new_merge_tag',
		'name'        => __( 'New Merge Tag', 'textdomain' ),
		'resolver'    => function( $trigger ) {
			return get_post_meta( $trigger->post->ID, '_my_meta_key', true );
		},
	) ) );

} );

Note: The snippet above must be called before action init 1000.

3 people considered this helpful