Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. add_shortcode ( 'show_recent_comments', 'show_recent_comments_handler' );
  2.  
  3. function show_recent_comments_handler( $atts, $content = null )
  4. {
  5. extract( shortcode_atts( array(
  6. "count" => 10,
  7. "pretty_permalink" => 0
  8. ), $atts ));
  9.  
  10. $output = ''; // this holds the output
  11.  
  12. if ( is_user_logged_in() )
  13. {
  14. global $current_user;
  15. get_currentuserinfo();
  16.  
  17. $args = array(
  18. 'user_id' => $current_user->ID,
  19. 'number' => $count, // how many comments to retrieve
  20. 'status' => 'approve'
  21. );
  22.  
  23. $comments = get_comments( $args );
  24. if ( $comments )
  25. {
  26. $output.= "<ul>n";
  27. foreach ( $comments as $c )
  28. {
  29. $output.= '<li>';
  30. if ( $pretty_permalink ) // uses a lot more queries (not recommended)
  31. $output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
  32. else
  33.  
  34. $output.= '<a href="'.get_settings('siteurl').'/?p='.$c->comment_post_ID.'#comment-'.$c->comment_ID.'">';
  35. $output.= $c->comment_content;
  36. $output.= '</a>';
  37.  
  38. $output.= "</li>n";
  39. }
  40. $output.= '</ul>';
  41. }
  42. }
  43. else
  44. {
  45. $output.= "<p class='button-com2'>Please login first.</p>";
  46. }
  47. return $output;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement