Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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';
- // Make sure only the post author sees the button
- $post = get_post( $comment->comment_post_ID );
- if ( isset( $post->post_author ) && $cui != $post->post_author ) return $comment_text;
- // 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement