TwelvestoneBack End

Wordpress: only allow a user to comment once


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
X-DUD!!!11~~
 
2011-02-02

Any ideas on how to make this happen?

It seems easy enough: "If the user has already commented on this post, don't show the comments form."

Or would that require loops and inflict crazy load on the server/database?

the real me
 
2011-02-02

It depends I suppose. Do they have to be registered to post a comment? If not there probably isn't an easy straight forward way.

X-DUD!!!11~~
 
2011-02-03

Yes they do! It's a member-only site. We could even log by IP, cookie, etc if we needed to...

Stickman
 
2011-02-03

I'm guessing this is going to require hacking at the comments.php file in your theme. Looks like it loads and parses all the comments in there in a for-each loop, shouldn't be too hard to keep a check if a comment's been posted by the currently-logged-in user and decide whether or not to show the form.

X-DUD!!!11~~
 
2011-02-03

hmm, cool!

I don't suppose you have in your bookmarks a compendium of all PHP functions that exist inside Wordpress?

X-DUD!!!11~~
 
2011-02-04

Sweet! http://codex.wordpress.org/Function_Reference/count_user_posts -- now if I can get that specific to a single posting... that'd totally negate loops and server strain.

the real me
 
2011-02-04

yeah, no need for an extra loop. you could just do something like...

$count = $wpdb->query("SELECT user_id FROM wp_comments WHERE user_id=$current_user->ID AND comment_post_ID=$post_id");

... probably

assuming you are in "the loop" and have the current user logged in, $count will be the number of comments they've made on the current post.

that's just out of my ass though, i haven't tested it or anything.

Stickman
 
2011-02-04

I think you missed the point of what I was saying.

If you look at the code, you'll see it loops over the existing comments (to render them). All you'd need to do would be to add in a check (in the existing loop) to see if the comment was made by the logged-in user, and then when it comes to rendering the form (or not) just see if the check was true or not. No need for db access or anything beyond a couple of extra if() statements.

the real me
 
2011-02-04

Originally posted by: Stickman I think you missed the point of what I was saying.

If you look at the code, you'll see it loops over the existing comments (to render them). All you'd need to do would be to add in a check (in the existing loop) to see if the comment was made by the logged-in user, and then when it comes to rendering the form (or not) just see if the check was true or not. No need for db access or anything beyond a couple of extra if() statements.

Ah yeah, I just glanced over your response and was responding to Xdude looking to get the count. That's much easier, and save a db hit.

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

Wordpress: only allow a user to comment once