Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Created April 8, 2014 09:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielmerovingi/10103371 to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/10103371 to your computer and use it in GitHub Desktop.
Place this code snippet in your themes functions.php file to restrict myCRED from giving points for forum actions.
/**
* Restrict bbPress Forum Points
* If a forum has the custom field "NO_MYCRED_POINTS" set to "yes"
* no points are awarded for any action taken in the forum.
* @version 1.0
*/
add_filter( 'mycred_add', 'mycred_disable_bbp_forum_points', 98, 3 );
function mycred_disable_bbp_forum_points( $reply, $request, $mycred ) {
// If already declined or bbPress is not installed, bail.
if ( $reply === false || ! function_exists( 'bbp_get_topic_forum_id' ) )
return $reply;
// Only apply for bbPress
if ( in_array( $request['ref'], array( 'new_forum', 'deleted_forum', 'new_forum_topic', 'deleted_topic', 'topic_favorited', 'new_forum_reply', 'deleted_reply' ) ) ) {
// Get Forum ID
if ( in_array( $request['ref'], array( 'new_forum', 'delete_forum' ) ) )
$forum_id = $request['ref_id'];
elseif ( in_array( $request['ref'], array( 'new_forum_topic', 'deleted_topic', 'topic_favorited' ) ) )
$forum_id = bbp_get_topic_forum_id( $request['ref_id'] );
else
$forum_id = bbp_get_reply_forum_id( $request['ref_id'] );
// If forum has custom field, decline points.
if ( get_post_meta( $forum_id, 'NO_MYCRED_POINTS', true ) == 'yes' ) return false;
}
return $reply;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment