# Allow sending Private Messages to Staff

**URL:** <https://meta.discourse.org/t/allow-sending-private-messages-to-staff/75366>\
**Category:** Feature\
**Created:** [2017 年 12 月 4 日午後 8:00 UTC](https://meta.discourse.org/t/allow-sending-private-messages-to-staff/75366 "2017-12-04T20:00:58Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [2017 年 12 月 5 日午後 7:42 UTC](https://meta.discourse.org/t/allow-sending-private-messages-to-staff/75366/6 "2017-12-05T19:42:01Z")

</div>

Thanks, @angus!

Here’s what I ended up with. If I were better at understanding the distributed properties of `and` and `or`, I’d have moved `target.staff?` outside of those three expressions, but this seems to do what I wanted. My scant tests show that it allows sending to an admin and if you send to an admin **and** another user, it is denied.

```plaintext

after_initialize do
  add_to_class('guardian', :can_send_private_message?) do |target|
    target.is_a?(User) &&
      # User is authenticated
      authenticated? &&
      # Have to be a basic level at least
      (target.staff? || @user.has_trust_level?(SiteSetting.min_trust_to_send_messages)) &&
      # User disabled private message
      (target.staff? || is_staff? || target.user_option.allow_private_messages) &&
      # PMs are enabled
      (target.staff? || is_staff? || SiteSetting.enable_private_messages)
  end
end

```

it doesn’t quite meet my standards for posting to #plugins just yet, but if anyone stumbles here and wants to do this, here’s this:

[https://github.com/pfaffman/discourse-allow-pm-to-staff](https://github.com/pfaffman/discourse-allow-pm-to-staff)

---

_[View the full topic](https://meta.discourse.org/t/allow-sending-private-messages-to-staff/75366)._
