Advertisement
Guest User

Untitled

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