Support » Plugin: Notification - Custom Notifications and Alerts for WordPress » Custom Merge Tag for User-Meta

  • Resolved ldeschenes


    I locked at your documentation for “Adding custom Merge Tag”

    Could you please tell me how I could modify the propose code snippet in order to make a “Custom Merge Tag” for a specific User-Meta.

    Example : User-meta “Appartement”
    I get the “Appartement” using the following code:
    $user_id = get_current_user_id();
    $key = ‘appartement’;
    $single = true;
    $appartement = get_user_meta( $user_id, $key, $single );

    How do I incorporate my code into your code snippet to make it work ?


Viewing 2 replies - 1 through 2 (of 2 total)
  • ldeschenes


    I did try the code at the bottom to no success.
    Any idea what is wrong ?

    // Hook into an action when Merge Tags are attached to Trigger.
    add_action( 'notification/trigger/merge_tags', function( $trigger ) {
    // Check if registered Trigger is the one you need.
    if ( 'user/profile_updated' !== $trigger->get_slug() ) {
    // Pay attention to the Tag type you are defining.
    // If you want to output an HTML, use HtmlTag instead.
    $trigger->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\StringTag( [
    'slug' => 'user_appartement',
    'name' => __( 'User Appartement', 'textdomain' ),
    'resolver' => function( $trigger ) {
    return get_user_meta( $trigger->{ $trigger->get_current_user_id() }->ID, 'appartement', true );
    ] ) );
    } );
    Plugin Author Kuba Mikita


    Well, there’s no get_current_user_id() on the $trigger object. To get the user ID you’d need to do it like this in the resolver:

    return get_user_meta( $trigger->user_object->ID, 'appartement', true );

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.