Xenforo 2.1 How to set privacy response ?

Erely

Member
Registered
Joined
Aug 31, 2019
Messages
16
Points
3

Reputation:

I want to implement the threads privacy reply function. The information that the threads replies to is only visible to the poster and administrator.
 

Citizen0

Collaborate
Collaborate
Registered
Joined
Jan 20, 2019
Messages
32
Points
33

Reputation:

u can make it easy with \XF\Entity
You need to extend XFCP_Post

PHP:
<?php

namespace Test\Demo\XF\Entity;

use XF\Mvc\Entity\Entity;

class Post extends XFCP_Post
{
    public function canView(&$error = null)
    {
        //get visitor
        $visitor = \XF::visitor();
        //get parent method
        $canView = parent::canView();
         if (!$canView)
        {
            if (!$this->Thread || !$this->Thread->canView($error))
            {
                return false;
            }
             if ($visitor->user_id == $this->Thread->user_id)
            {
                // view moderated posts
                if ($this->message_state == 'moderated')
                {
                    return $visitor->hasNodePermission($this->Thread->node_id, 'yourPermission');
                }

                // view deleted posts
                if ($this->message_state == 'deleted')
                {
                    return $visitor->hasNodePermission($this->Thread->node_id, 'yourPermission');
                }
            }
         }
        return $canView;
}
it's for example
 
Last edited:

Erely

Member
Registered
Joined
Aug 31, 2019
Messages
16
Points
3

Reputation:

u can make it easy with \XF\Entity
You need to extend XFCP_Post

PHP:
<?php

namespace Test\Demo\XF\Entity;

use XF\Mvc\Entity\Entity;

class Post extends XFCP_Post
{
    public function canView(&$error = null)
    {
        //get visitor
        $visitor = \XF::visitor();
        //get parent method
        $canView = parent::canView();
         if (!$canView)
        {
            if (!$this->Thread || !$this->Thread->canView($error))
            {
                return false;
            }
             if ($visitor->user_id == $this->Thread->user_id)
            {
                // view moderated posts
                if ($this->message_state == 'moderated')
                {
                    return $visitor->hasNodePermission($this->Thread->node_id, 'yourPermission');
                }

                // view deleted posts
                if ($this->message_state == 'deleted')
                {
                    return $visitor->hasNodePermission($this->Thread->node_id, 'yourPermission');
                }
            }
         }
        return $canView;
}
it's for example
Citizen0OK,Thanks,
 
Top