Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » restrict comments to logged in users: solved

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 719 Views
  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    restrict comments to logged in users: solved Link to this post

    Hi, i want to enable comments on all the pages on my website but want to to set it up in such a way that only logged in users can comment. I have figured out how to hide comments from users that are not logged in but that does not help me since i want everyone to see the comments but only want logged in users to comment. Pls help

  • Willr
    Avatar
    Forum Moderator
    5497 Posts

    Re: restrict comments to logged in users: solved Link to this post

    You can require login using PageCommentInterface::set_comments_require_login(true);

  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    Re: restrict comments to logged in users: solved Link to this post

    Thanks alot for the help

  • restar
    Avatar
    Community Member
    2 Posts

    Re: restrict comments to logged in users: solved Link to this post

    Hi, sorry, I must be a real newbie here. Can you please explain this solution in a little more detail? This is exactly what I am looking to do - with one exception. I have a page type HiddenForm (as opposed to page type Page) and only want comments to require login on HiddenForm pages, not on all pages. Thanks in advance!

  • Optic Blaze
    Avatar
    Community Member
    162 Posts

    Re: restrict comments to logged in users: solved Link to this post

    Hi there,

    To enable it you will add the line to your mysite/config.php file

    So in the mysite/config.php file you will add the following

    // Set page comments to require login //
    PageCommentInterface::set_comments_require_login(true);

  • restar
    Avatar
    Community Member
    2 Posts

    Re: restrict comments to logged in users: solved Link to this post

    Thank you for your help. Unfortunately, that applied it to the whole site, not just the page type HiddenForm. Placing it in .php file for that file type did the trick however, which was awesome! But i also needed the form to be different and the single comment interface to be different, so i copied the two PageComment* .php files, replaced Page with HiddenForm in the names of the copies, searched in the files for PageComment and replaced each instance with HiddenFormComment. Also had to edit one of the core Sapphire files to allow for HiddenFormComments as well as PageComments. Of course i had to copy the two PageComment* .ss files and edit them the same way as i did the .php files, and then edited the .php file that defines the fields to only include the fields I want in the HiddenFormComments and adjusted the *singlecomment.ss file to look the way i want. Everything works well!! The only thing I still need to figure out is how i am going to get the CMS to recognize HiddenFormComments so i can edit them. Moderation isn't necessary as only logged-in users can post, anyway, and removing them is easily done from the webpage itself. But in case one ever needs to be edited, i would like to be able to see them in the CMS, as well. Any suggestions on that would be most appreciated; suppose it would have been easier to make a HiddenFormComments module after all of this!

    Also, anyone out there know if it is possible to enable html tags inside comments?

    719 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.