• Resolved lamington

    (@lamington)


    Hi. I tried my hand at creating a merge tag to truncate comment content. I clearly haven’t got it right, as it returns nothing… I wonder if you could explain where I’ve gone wrong?

    $trigger->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\StringTag( [
    'slug' => 'comment_content_short',
    'name' => __( 'Comment Short Content', 'textdomain' ),
    'resolver' => function( $trigger ) {
    $commentstuff = $trigger->{ $this->get_trigger_prop() }->comment_content;
    return wp_trim_words( $commentstuff, 10, '… read on messaging page' );
    },
    ] ) );
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Kuba Mikita

    (@kubitomakita)

    Hey, looks like it’s not compatible with Notification v9. Try this:

    $trigger->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\StringTag( [
    'slug' => 'comment_content_short',
    'name' => __( 'Comment Short Content', 'textdomain' ),
    'resolver' => function( $trigger ) {
    $commentstuff = $trigger->{ $this->getTriggerProp() }->comment_content;
    return wp_trim_words( $commentstuff, 10, '… read on messaging page' );
    },
    ] ) );
    Thread Starter lamington

    (@lamington)

    Thanks for your suggested change. Unfortunately it didn’t solve the problem. There is still no output. I’ve tested various permutations. The merge tag itself works for other queries (e.g. if I make it retrieve the author) so the PHP is good, but as soon as I use getTriggerProp there’s no output. Given that return $trigger->{$this->getTriggerProp()}->comment_content; exactly the same line as in CommentContentHtml.php I’m confused…

    Plugin Author Kuba Mikita

    (@kubitomakita)

    Oh I see the problem not, it should be $trigger instead of $this!

    $trigger->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\StringTag( [
    'slug' => 'comment_content_short',
    'name' => __( 'Comment Short Content', 'textdomain' ),
    'resolver' => function( $trigger ) {
    $commentstuff = $trigger->{ $trigger->getTriggerProp() }->comment_content;
    return wp_trim_words( $commentstuff, 10, '… read on messaging page' );
    },
    ] ) );
    Thread Starter lamington

    (@lamington)

    Sorry, but still no output. (Code copied exactly as you’ve written.)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Truncating content in email notification’ is closed to new replies.