Advertisement
designbymerovingi

Comment App for Post Authors

Feb 10th, 2016
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 KB | None | 0 0
  1. /**
  2.  * Insert Comment Appreciation
  3.  * Lets insert the mycred_send shortcode after the comment
  4.  * text if a user can afford to use it (and is logged in.
  5.  * @version 1.0.1
  6.  */
  7. add_filter( 'comment_text', 'my_custom_comment_text', 10, 2 );
  8. function my_custom_comment_text( $comment_text, $comment = NULL ) {
  9.  
  10.     // Make sure the current user is logged in
  11.     if ( ! is_user_logged_in() || $comment === NULL || $comment->user_id == 0 || is_admin() )
  12.     return $comment_text;
  13.    
  14.     // Prep
  15.     $mycred = mycred();
  16.     $cui = get_current_user_id();
  17.    
  18.     // Make sure the current user is not the comment author
  19.     if ( $cui == $comment->user_id ) return $comment_text;
  20.    
  21.     // Make sure the current user is not excldued
  22.     if ( $mycred->exclude_user( $cui ) ) return $comment_text;
  23.    
  24.     // Make sure the comment author is not excluded
  25.     if ( $mycred->exclude_user( $comment->user_id ) ) return $comment_text;
  26.    
  27.     // Prep shortcode details
  28.     $user_id = $comment->user_id;
  29.     $amount  = 1;
  30.     $label   = 'Give 1 Point';
  31.     $ref     = 'comment_appreciation';
  32.     $entry   = 'Comment Appreciation';
  33.  
  34.     // Make sure only the post author sees the button
  35.     $post = get_post( $comment->comment_post_ID );
  36.     if ( isset( $post->post_author ) && $cui != $post->post_author ) return $comment_text;
  37.  
  38.     // Append shortcode to the end of the comment text
  39.     $add_points = '[mycred_send to="' . $user_id . '" amount="' . $amount . '" log="' . $entry . '"]' . $label . '[/mycred_send]';
  40.     $comment_text .= '
  41.     <div class="comment-like">' . do_shortcode( $add_points ) . '</div>';
  42.  
  43.     // Return result
  44.     return $comment_text;
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement