Advertisement
Guest User

Untitled

a guest
May 2nd, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Show Recent Comments by a particular user
  4. Plugin URI: http://blog.ashfame.com/?p=876
  5. Description: Provides a shortcode which you can use to show recent comments by a particular user
  6. Author: Ashfame
  7. Author URI: http://blog.ashfame.com/
  8. License: GPL
  9. Usage:
  10. */
  11.  
  12. add_shortcode ( 'show_recent_comments', 'show_recent_comments_handler' );
  13.  
  14. function show_recent_comments_handler( $atts, $content = null )
  15. {
  16. extract( shortcode_atts( array(
  17. "count" => 10,
  18. "pretty_permalink" => 0
  19. ), $atts ));
  20.  
  21. $output = ''; // this holds the output
  22.  
  23. if ( is_user_logged_in() )
  24. {
  25. global $current_user;
  26. get_currentuserinfo();
  27.  
  28. $args = array(
  29. 'post_id' => $post_id = $GLOBALS['post']->ID, // change 145 to what you want
  30. 'user_id' => $current_user->ID,
  31. 'number' => $count, // how many comments to retrieve
  32. 'status' => 'approve'
  33.  
  34. );
  35.  
  36. $comments = get_comments( $args );
  37. if ( $comments )
  38. {
  39. $output.= "<ul>\n";
  40. foreach ( $comments as $c )
  41. {
  42. $output.= "<li>";
  43. if ( $pretty_permalink ) // uses a lot more queries (not recommended)
  44. $output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
  45. else
  46. $output.= '';
  47. $output.= $c-> comment_content;
  48.  
  49.  
  50. $output.= '';
  51. $output.= "</li>\n";
  52. }
  53. $output.= '</ul>';
  54.  
  55.  
  56.  
  57.  
  58. }
  59. }
  60. else
  61. {
  62. $output.= "<h2>You should be logged in to see your comments. Make sense?</h2>";
  63. $output.= '<h2><a href="'.get_settings('siteurl').'/wp-login.php?redirect_to='.get_permalink().'">Login Now &rarr;</a></h2>';
  64. }
  65. return $output;
  66. }
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement