Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Last active October 2, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielmerovingi/586b80adfca0a29f929b to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/586b80adfca0a29f929b to your computer and use it in GitHub Desktop.
Enforces a minimum character length for post and comment contents in order for points to be awarded by myCRED.
/**
* Minimum Char Length Requirement
* Enforces a minimum character length for post and comment
* contents in order for points to be awarded by myCRED.
* @version 1.0.2
*/
add_filter( 'mycred_add', 'mycred_pro_min_char_limit', 10, 3 );
function mycred_pro_min_char_limit( $run, $request, $mycred ) {
// No need to do anything if this has already been declined
if ( $run === false ) return $run;
// Only applicable to certain instances
if ( ! in_array( $request['ref'], array(
'publishing_content',
'approved_comment',
'new_forum_topic',
'new_forum_reply'
) ) ) return $run;
// Minimum length
$min = 20;
// Check comments
if ( $request['ref'] == 'approved_comment' ) {
$comment = get_comment( $request['ref_id'] );
// Decline if content is too short
if ( strlen( $comment->comment_content ) < $min )
return false;
}
// Check posts
else {
$post = get_post( $request['ref_id'] );
// Decline if content is too short
if ( strlen( $post->post_content ) < $min )
return false;
}
return $run;
}
@sanchycomms
Copy link

I keep getting error whenever i put this code in the functions.php what do i need to do
Thanks

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