Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yuriinalivaiko/531e8bbae6df5ffdd5b0b73840eed2d9 to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/531e8bbae6df5ffdd5b0b73840eed2d9 to your computer and use it in GitHub Desktop.
These code snippets add custom placeholders {post_content} and {comment_content} for the email notifications in the "Ultimate Member - Groups" extension.
<?php
/**
* Add custom placeholder {comment_content} for the "Groups - New comment" email template.
*/
add_action( 'um_groups_after_wall_comment_published', 'um_custom_tags_patterns_group_comment_on', 8, 4 );
add_action( 'um_groups_after_wall_comment_published', 'um_custom_tags_patterns_group_comment_off', 12, 4 );
function um_custom_tags_patterns_group_comment_on( $commentid, $comment_parent, $post_id, $user_id ){
$GLOBALS['um_groups_after_wall_comment_published_id'] = $commentid;
add_filter( 'um_template_tags_patterns_hook', 'um_custom_tags_patterns_group_comment', 10, 1 );
add_filter( 'um_template_tags_replaces_hook', 'um_custom_tags_replaces_group_comment', 10, 1 );
}
function um_custom_tags_patterns_group_comment_off( $commentid, $comment_parent, $post_id, $user_id ){
unset( $GLOBALS['um_groups_after_wall_comment_published_id'] );
remove_filter( 'um_template_tags_patterns_hook', 'um_custom_tags_patterns_group_comment', 10 );
remove_filter( 'um_template_tags_replaces_hook', 'um_custom_tags_replaces_group_comment', 10 );
}
function um_custom_tags_patterns_group_comment( $search ) {
$search[] = '{comment_content}';
return $search;
}
function um_custom_tags_replaces_group_comment( $replace ) {
if ( ! empty( $GLOBALS['um_groups_after_wall_comment_published_id'] ) ) {
$comment = get_comment( $GLOBALS['um_groups_after_wall_comment_published_id'] );
}
$replace[] = empty( $comment ) ? '' : wp_strip_all_tags( $comment->comment_content );
return $replace;
}
<?php
/**
* Add custom placeholder {post_content} for the "Groups - New post" email template.
*/
add_action( 'um_groups_after_wall_post_published', 'um_custom_tags_patterns_group_post_on', 48, 3 );
add_action( 'um_groups_after_wall_post_published', 'um_custom_tags_patterns_group_post_off', 52, 3 );
function um_custom_tags_patterns_group_post_on( $post_id, $author_id, $wall_id ){
$GLOBALS['um_groups_after_wall_post_published_id'] = $post_id;
add_filter( 'um_template_tags_patterns_hook', 'um_custom_tags_patterns_group_post', 10, 1 );
add_filter( 'um_template_tags_replaces_hook', 'um_custom_tags_replaces_group_post', 10, 1 );
}
function um_custom_tags_patterns_group_post_off( $post_id, $author_id, $wall_id ){
unset( $GLOBALS['um_groups_after_wall_post_published_id'] );
remove_filter( 'um_template_tags_patterns_hook', 'um_custom_tags_patterns_group_post', 10 );
remove_filter( 'um_template_tags_replaces_hook', 'um_custom_tags_replaces_group_post', 10 );
}
function um_custom_tags_patterns_group_post( $search ) {
$search[] = '{post_content}';
return $search;
}
function um_custom_tags_replaces_group_post( $replace ) {
if ( ! empty( $GLOBALS['um_groups_after_wall_post_published_id'] ) ) {
$post = get_post( $GLOBALS['um_groups_after_wall_post_published_id'] );
}
$replace[] = empty( $post ) ? '' : wp_strip_all_tags( $post->post_content );
return $replace;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment