Ask your WordPress questions! Pay money and get answers fast! (more info)

Comment privacy WordPress

  • SOLVED

I have a snippet of code that achieve the ability for the poster and commenter to post and read each others comments privately and without anyone else being able to read them.

1. I would like a snippet that expands on the snippet below so that it has a checkbox near the comment submit button that says "make this comment private"
2. The checkbox and text to have css classes attached to each element for custom styling.
3. comment the snippet to show me how to make the checkbox either checked or unchecked by default.

thanks...


Here it is ...
1. <strong>Only post author and commentor can view their own comments
</strong>
function restrict_comments( $comments , $post_id ){

global $post;

$user = wp_get_current_user();

if($post->post_author == $user->ID){

return $comments;

}

foreach($comments as $comment){

if( $comment->user_id == $user->ID || $post->post_author == $comment->user_id ){

if($post->post_author == $comment->user_id){

if($comment->comment_parent > 0){

$parent_comm = get_comment( $comment->comment_parent );

if( $parent_comm->user_id == $user->ID ){

$new_comments_array[] = $comment;

}

}else{

$new_comments_array[] = $comment;

}

}else{

$new_comments_array[] = $comment;

}

}

}

return $new_comments_array; }



add_filter( 'comments_array' , 'restrict_comments' , 10, 2 );


Answers (1)

2015-01-30

Reigel Gallarde answers:

I have a question, what does "make this comment private" do afterwards?


pjeaje comments:

it does what the snippet tells it to do.


Reigel Gallarde comments:

You mean you want an option to disable/enable this snippet?


pjeaje comments:

yes


pjeaje comments:

Hang on, I don't think it can be done on a per thread basis. It must be site wide.


pjeaje comments:

Sorry i don't think what i'm asking can be done


Reigel Gallarde comments:

hmm... let me know what you are up to.. I have an idea of what you want but I'm not sure... maybe it can be done...


pjeaje comments:

What did you have in mind?


Reigel Gallarde comments:

What I understand is when you comment, then you have the option so that only one who can read your comment is the poster...

sample, when I comment, I check "make this comment private" and then only the poster and me can read my comment... and we can have a private conversation...


pjeaje comments:

Yes, but on a comment by comment, and user by user basis... you would need to create comment metadata?


Reigel Gallarde comments:

like this?