Comments can be hidden to non-staff members. This can be used to require approval by staff before comments are shown, or as a way for staff to reactively hide comments deemed undesirable and unsuitable for public display.
How to implement hiding/approving
First, you will need to implement the hiding/approving interface in your comment model, like so:
implements \IPS\Content\Hideable
Next, add either a hidden or approved key to your $databaseColumnMap property, with the value being the name of the database column that stores the hidden status of your comments.
Optionally, you can also add an additional key, unapproved_comments to the content item model, whose value should be the column name that stores a count of the number of unapproved comments on each item.
If a user or their group is configured to require approval of content they post, comments will be hidden automatically for you. You can override the moderateNewComments() method of the content item class if you want to change this behavior, for example to require all content within certain nodes to be approved regardless of the user's permissions. Don't forget to call the parent method.
public static function moderateNewComments( \IPS\Member $member ) { if ( $this->item()->container()->bitoptions[‘moderation’] and !static::modPermission( 'unhide', $member, $this->item()->container() ) ) { return TRUE; } return parent::moderateNewComments( $member ); }
Values stored for hidden status
When checking the hidden status of an item, there are three possible values; they depend on whether your model uses hidden or approved in the $databaseColumnMap.
Element |
Value if hidden (normal, default) |
Value if hidden (and was previously unhidden) |
Value if pending approval |
---|---|---|---|
hidden | 0 | -1 | 1 |
approved | 1 | -1 | 0 |
Additional model methods available
Returns the status of the comment:
- -1 indicates the comment is now hidden, but was previous unhidden (i.e. it has changed state)
- 0 indicates the comment is unhidden (the default status)
- 1 indicates the comment is hidden and was automatically set as hidden at the time of posting (i.e. it hasn't changed state)
Indicates whether the user can hide the comment. This method takes into account whether the comment is already hidden.
-
$member (\IPS\Member, optional)
The member whose permissions will be used when checking. By default, the currently-logged in member will be used.
Indicates whether the user can unhide the comment. This method takes into account whether the comment is already visible.
-
$member (\IPS\Member, optional)
The member whose permissions will be used when checking. By default, the currently-logged in member will be used.
An additional method is also available on the content item model:
Indicates whether the user can view hidden comments on the item.
-
$member (\IPS\Member, optional)
The member whose permissions will be used when checking. By default, the currently-logged in member will be used.
Behavior changes after implementation
- loadAndCheckPerms() will now throw an OutOfRangeException if a hidden content item is loaded and the currently logged in user does not have permission to view is hidden content.
- Hidden comments will only show to users who have permission to view hidden comments.
- Users with appropriate moderator permission will see buttons to hide/unhide in comments.
- Users who are set to have all new content moderated will have their comments hidden until it is manually approved.
Report Document