Advertisement
alchymyth

author comments plugin

May 2nd, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. "theid" => $post_id = $GLOBALS['post']->ID,
  19. "pretty_permalink" => 0
  20. ), $atts ));
  21.  
  22. $output = ''; // this holds the output
  23.  
  24. if ( is_user_logged_in() )
  25. {
  26. global $current_user;
  27. get_currentuserinfo();
  28.  
  29. $args = array(
  30. 'post_id' => $theid, // the id
  31. 'user_id' => $current_user->ID,
  32. 'number' => $count, // how many comments to retrieve
  33. 'status' => 'approve'
  34.  
  35. );
  36.  
  37. $comments = get_comments( $args );
  38. if ( $comments )
  39. {
  40. $output.= "<ul>\n";
  41. foreach ( $comments as $c )
  42. {
  43. $output.= "<li>";
  44. if ( $pretty_permalink ) // uses a lot more queries (not recommended)
  45. $output.= '<a href="'.get_comment_link( $c->comment_ID ).'">';
  46.  
  47. $output.= apply_filters('comment_text',$c-> comment_content);
  48.  
  49. if ( $pretty_permalink ) $output.= '</a>';
  50. $output.= "</li>\n";
  51. }
  52. $output.= '</ul>';
  53.  
  54.  
  55. }
  56. else
  57. {
  58. $output.= "<ul>\n<li>";
  59. $output.= "<p>some certain text for no comments</p>";
  60. $output.= "</li>\n</ul>";
  61. }
  62. }
  63. else
  64. {
  65. $output.= "Please login to view your team.";
  66. $output.= '<a href="'.get_settings('siteurl').'/wp-login.php?redirect_to='.get_permalink().'">Click here.</a></h2>';
  67. }
  68. return $output;
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement