• I have a custom post type “public notice” whereby subscribers and paid members can create posts of that post type. However, I want to enable the comments section on posts created by paid members with the user role of “member” and disable it on posts created by free subscribers with the role of “subscriber”. Is this possible?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You could use the “comments_open” filter to force it to appear to be closed for certain users even though it’ll be open for the right users. Your callback is passed 2 parameters, open status and the post ID that we’re checking for. If you are passed false status, then comments are truly closed and you should return false without further analysis.

    If comments are otherwise open, check for one of the current user’s capabilities with current_user_can(). If they don’t have the requisite capability for the member role, return false. If they have the right capability, return true.

    Thread Starter cybercli

    (@cybercli)

    Thank you for the idea! I’m not a coder but it makes perfect sense to still show previous comments if the post author member downgrades to subscriber. I have Code Snippets installed and was going to add it there but have no idea what I’m doing with code. lol Do you have a services page I can pay you on?

    Moderator bcworkz

    (@bcworkz)

    I appreciate your willingness to pay for my time, but accepting compensation for help related to these forums is against our guidelines. What you could do is hire someone through resources like https://jobs.wordpress.net/ or https://jetpack.pro/. I recommend ignoring any unsolicited offers of paid help that result from this topic. People who do that do not have your best interests at heart.

    Feel free to pass my suggestions on to whom ever you end up hiring.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Enable post comments in WordPress based on author role’ is closed to new replies.