Skip to content

Instantly share code, notes, and snippets.

@hammady
Last active August 12, 2017 13:03
Show Gist options
  • Save hammady/6262d656562f83328f3136bc05b31480 to your computer and use it in GitHub Desktop.
Save hammady/6262d656562f83328f3136bc05b31480 to your computer and use it in GitHub Desktop.
WordPress + wpForo + Slack
<?php
# add the following towards the end of wpforo/wpforo.php using plugin editor (before the final })
add_filter( 'slack_get_events', function( $events ) {
$events['wpforo_after_add_topic'] = array(
'action' => 'wpforo_after_add_topic',
'description' => __( 'When a forum post is published', 'slack' ),
'default' => false,
'message' => function( $args ) {
$excerpt = wp_trim_words( strip_shortcodes( $args['body'] ), 55, '&hellip;' );
return sprintf(
/* translators: 1) URL, 2) post title, and 3) post author. */
__( 'New forum topic published: *<%1$s|%2$s>* by *%3$s*', 'slack' ) . "\n" .
'> %4$s',
$args['topicurl'],
html_entity_decode( $args['title'], ENT_QUOTES, get_bloginfo( 'charset' )),
get_the_author_meta( 'display_name', $args['userid'] ),
html_entity_decode( $excerpt, ENT_QUOTES, get_bloginfo( 'charset' ) )
);
}
);
return $events;
} );
add_filter( 'slack_get_events', function( $events ) {
$events['wpforo_after_add_post'] = array(
'action' => 'wpforo_after_add_post',
'description' => __( 'When a forum post reply is published', 'slack' ),
'default' => false,
'message' => function( $post, $topic ) {
$excerpt = wp_trim_words( strip_shortcodes( $post['body'] ), 55, '&hellip;' );
return sprintf(
/* translators: 1) URL, 2) post title, and 3) post author. */
__( 'New reply on a forum topic published: *<%1$s|%2$s>* by *%3$s*', 'slack' ) . "\n" .
'> %4$s',
$post['posturl'],
html_entity_decode( $topic['title'], ENT_QUOTES, get_bloginfo( 'charset' )),
get_the_author_meta( 'display_name', $post['userid'] ),
html_entity_decode( $excerpt, ENT_QUOTES, get_bloginfo( 'charset' ) )
);
}
);
return $events;
} );
?>
@hammady
Copy link
Author

hammady commented Aug 12, 2017

Must have these 2 plugins to work:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment