Advertisement
pjeaje

Only post author and commentor can view their own comments

Jan 29th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. function restrict_comments( $comments , $post_id ){
  2. global $post;
  3. $user = wp_get_current_user();
  4. if($post->post_author == $user->ID){
  5. return $comments;
  6. }
  7. foreach($comments as $comment){
  8. if( $comment->user_id == $user->ID || $post->post_author == $comment->user_id ){
  9. if($post->post_author == $comment->user_id){
  10. if($comment->comment_parent > 0){
  11. $parent_comm = get_comment( $comment->comment_parent );
  12. if( $parent_comm->user_id == $user->ID ){
  13. $new_comments_array[] = $comment;
  14. }
  15. }else{
  16. $new_comments_array[] = $comment;
  17. }
  18. }else{
  19. $new_comments_array[] = $comment;
  20. }
  21. }
  22. }
  23. return $new_comments_array; }
  24.  
  25. add_filter( 'comments_array' , 'restrict_comments' , 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement