Last active
October 2, 2015 14:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I keep getting error whenever i put this code in the functions.php what do i need to do
Thanks