Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Created November 30, 2015 23:56
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/493be119d2165cf35444 to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/493be119d2165cf35444 to your computer and use it in GitHub Desktop.
/**
* 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;
}
@sammyhub
Copy link

sammyhub commented Nov 2, 2019

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.

@sammyhub
Copy link

sammyhub commented Nov 2, 2019

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