Created
November 30, 2015 23:56
-
-
Save gabrielmerovingi/493be119d2165cf35444 to your computer and use it in GitHub Desktop.
Final code for myCRED Tutorial - http://mycred.me/tutorial/comment-appreciation-with-points/
This file contains hidden or 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
/** | |
* Insert Comment Appreciation | |
* Lets insert the mycred_send shortcode after the comment | |
* text if a user can afford to use it (and is logged in. | |
* @version 1.0.1 | |
*/ | |
add_filter( 'comment_text', 'my_custom_comment_text', 10, 2 ); | |
function my_custom_comment_text( $comment_text, $comment = NULL ) { | |
// Make sure the current user is logged in | |
if ( ! is_user_logged_in() || $comment === NULL || $comment->user_id == 0 || is_admin() ) | |
return $comment_text; | |
// Prep | |
$mycred = mycred(); | |
$cui = get_current_user_id(); | |
// Make sure the current user is not the comment author | |
if ( $cui == $comment->user_id ) return $comment_text; | |
// Make sure the current user is not excldued | |
if ( $mycred->exclude_user( $cui ) ) return $comment_text; | |
// Make sure the comment author is not excluded | |
if ( $mycred->exclude_user( $comment->user_id ) ) return $comment_text; | |
// Prep shortcode details | |
$user_id = $comment->user_id; | |
$amount = 1; | |
$label = 'Give 1 Point'; | |
$ref = 'comment_appreciation'; | |
$entry = 'Comment Appreciation'; | |
// Append shortcode to the end of the comment text | |
$add_points = '[mycred_send to="' . $user_id . '" amount="' . $amount . '" log="' . $entry . '"]' . $label . '[/mycred_send]'; | |
$comment_text .= ' | |
<div class="comment-like">' . do_shortcode( $add_points ) . '</div>'; | |
// Return result | |
return $comment_text; | |
} |
Please tell me the code to display on bbpress replay.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code works. Thank you.
$entry = 'Comment Appreciation';
In the activity and point history page ,
the person who sent it and the person who got it will be displayed in the same way.
1 The point has been sent.
2 I received a point.
Please tell me the code to be modified in this way.