Support » Plugin: Notification - Custom Notifications and Alerts for WordPress » {post_content} in notification always “plain text”, want HTML

  • Resolved Larry Daniele

    (@larrydaniele)


    I’m working with the ‘Notifications’ plugin v5.2.3 and ‘Notifications : Conditionals’ v1.0.2 on a WordPress 4.9.7 site and I have email Settings > Notifications > Message type set to ‘HTML’. However, the email’s {post_content} gets stripped of HTML (paragraph breaks, images, etc.) and returns plain text.

    Thinking I might have a conflict with a different installed plugin, I installed Notifications 5.2.3 on a fresh WordPress install and still get the same results.

    How can I get HTML post contents into a Notification email?

    Thanks for your help with this!

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

    (@kubitomakita)

    Hi Larry,

    You can use this snippet:

    add_action( 'notification/trigger/registered', function( $trigger ) {
    
    	if ( ! preg_match( '/wordpress\/(.*)\/(updated|trashed|published|drafted|added|pending)/', $trigger->get_slug() ) ) {
            return;
        }
    
    	$trigger->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\HTMLTag( array(
    		'slug'        => 'post_content_html',
    		'name'        => __( 'Post content HTML', 'notification' ),
    		'description' => __( 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!', 'notification' ),
    		'example'     => true,
    		'resolver'    => function( $trigger ) {
    			return apply_filters( 'the_content', $trigger->{ $trigger->get_post_type() }->post_content );
    		},
    	) ) );
    
    } );

    It will add the new merge tag: post_content_html to the post triggers.

    You can paste this snippet in your theme’s functions.php file.

    Thanks Kuba! I’ll give it try.

    We tried the above code and got a server “500” error. Traced it to “HTMLTag” which needed to be changed to “HtmlTag”. Here’s code that worked for us:

    
    add_action( 'notification/trigger/registered', function( $trigger ) {
    
    	if ( ! preg_match( '/wordpress\/(.*)\/(updated|trashed|published|drafted|added|pending)/', $trigger->get_slug() ) ) {
            return;
        }
    
    	$trigger->add_merge_tag( new BracketSpace\Notification\Defaults\MergeTag\HtmlTag( array(
    		'slug'        => 'post_content_html',
    		'name'        => __( 'Post content HTML', 'notification' ),
    		'description' => __( 'Outputs post content as HTML', 'notification' ),
    		'example'     => true,
    		'resolver'    => function( $trigger ) {
    			return apply_filters( 'the_content', $trigger->{ $trigger->get_post_type() }->post_content );
    		},
    	) ) );
    
    } );
    

    Thanks again for your help!

    • This reply was modified 9 months, 1 week ago by  Larry Daniele. Reason: Fixed code block coding
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘{post_content} in notification always “plain text”, want HTML’ is closed to new replies.