WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to restrict comment-ability on a per-user/per-page basis? (10 posts)

  1. e-sushi
    Member
    Posted 4 years ago #

    Hi there!

    I sure could help a push into the right direction.

    Is there a plugin that allows me to restrict a specific subscribed user to comment on a specific page only?

    I want to be able to create something like a personal 1-on-1 chat page that only me and a specific user can comment on, while everyone else can only read but not comment on that page.

    Also (probably my real problem), it has to be scalable... meaning, I need to have this functionality for multiple users, each having "enhanced" access to their own, personal page where only they (and me, the admin) can comment.

    I would work with password-restricted pages, but I want the world to be able to read all those pages... I just need to be able to restrict comment-ability on a per-user basis.

  2. e-sushi
    Member
    Posted 4 years ago #

    I've been thinking about using a custom field with the user's nickname or something and a PHP "if" function to show the comment-posting form only when the nickname fits the page's custom field.

    Yet, after about 40 hours or shoving code and pixels, my brain just produces fruit-salad instead of a bright idea with a short code-snippet.

    Anyone? Please? Pretty Please? ;)

  3. e-sushi
    Member
    Posted 4 years ago #

    Ok, I've helped about 30 people the last 3 to 4 hours. Where's my help? 8[

  4. mrmist
    Forum Janitor
    Posted 4 years ago #

    Custom field sounds like the right way to go to me, too.

    It's not really clear what you are asking people to do, though. If you have attempted this you could put your attempt in a pastebin to show folk where you are so far.

  5. e-sushi
    Member
    Posted 4 years ago #

    So far it's all in my mind, so no code to share or show... yet.

    I'm probably just not sure how to compare a "logged in user nick" to the "custom field of the current page and/or post" the correct way. Can't be more than 3 lines of code, can it?

    (Been wp-looping so much lately that I've lost some logic I guess.)

  6. e-sushi
    Member
    Posted 4 years ago #

    Strategy:
    1. user registers and get's a page created by the admin, with his e-mail in a custom field.
    2. if user is logged in, he is allowed to see and use the comment form. No one else is allowed to use that form. (Unique e-mail should take care of seperation).
    3. all other users simply see the page and the comments. Unless they are looking at their own, custom-fielded page.

    Question:
    How do I compare the user e-mail with the e-mail in the custom field within the loop (where the comments template get's called) so that I can do a simple "if(pageemail=useremail) { comment } else { ignore }"

    It's the "get user e-mail from profile" and "get custom-field value" thingy that I somehow can't combine in my mind. What would be the code? Some tiny, small and incomplete snippets related to something like "get_xxx" would be enough and a great way to make my day! 8)

  7. e-sushi
    Member
    Posted 4 years ago #

    Ha, solved it myself. Tnx anyway @mrmist

  8. Mark / t31os
    Moderator
    Posted 4 years ago #

    Have you checked the function reference.
    http://codex.wordpress.org/Function_Reference

    Action and filter references are always handy.
    http://codex.wordpress.org/Plugin_API/Action_Reference
    http://codex.wordpress.org/Plugin_API/Filter_Reference

    Failing a codex page that gives a suitable example of whatever you're looking for, the alternative, as i often do, is to jump into the code and look at the functions directly rather then making guesses at intended usage.

    Here's some specific links with info on getting userdata..

    http://codex.wordpress.org/Function_Reference/wp_get_current_user
    http://codex.wordpress.org/Function_Reference/get_userdata

    ..and a few for custom field data..

    http://codex.wordpress.org/Function_Reference/get_post_custom
    http://codex.wordpress.org/Function_Reference/get_post_custom_keys
    http://codex.wordpress.org/Function_Reference/get_post_custom_values

    You'll find some(not all) codex pages have related links at the bottom, so often when reading one page you'll find related information simply by checking the links at the bottom of the page(s).

    Hope that helps.

  9. e-sushi
    Member
    Posted 4 years ago #

    Thank's for the heads-up. You've actually amazed me by collecting so many links for me to dig. Thank you!

    In the end, it turned out I just needed some "talking to someone" to set my mind back into logic-mode. (Ok, I have to admit a coffee helped too.)

  10. e-sushi
    Member
    Posted 4 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic