functions.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace MFP\BlockUsers;
  3. /**
  4. * Unblocks $blocked_user as blocked by $blocking_user.
  5. *
  6. * @param ElggUser $blocked_user
  7. * @param ElggUser $blocking_user
  8. * @return bool
  9. */
  10. function block_user(\ElggUser $blocked_user, \ElggUser $blocking_user) {
  11. if (!$blocked_user instanceof \ElggUser) {
  12. return false;
  13. }
  14. if ($blocking_user && ! ($blocking_user instanceof \ElggUser)) {
  15. return false;
  16. } elseif (!$blocking_user) {
  17. $blocking_user = elgg_get_logged_in_user_entity();
  18. }
  19. // can't block admins
  20. if ($blocked_user->isAdmin()) {
  21. return false;
  22. }
  23. return add_entity_relationship($blocking_user->getGUID(), 'blocked', $blocked_user->getGUID());
  24. }
  25. /**
  26. * Unblocks $blocked_user as blocked by $blocking_user.
  27. *
  28. * @param ElggUser $blocked_user
  29. * @param ElggUser $blocking_user
  30. * @return type bool
  31. */
  32. function unblock_user(\ElggUser $blocked_user, \ElggUser $blocking_user) {
  33. return remove_entity_relationship($blocking_user->getGUID(), 'blocked', $blocked_user->getGUID());
  34. }
  35. /**
  36. * Is $blocked_user blocked by $blocking_user?
  37. *
  38. * @param ElggUser $blocked_user
  39. * @param ElggUser $blocking_user
  40. * @return type bool
  41. */
  42. #### 2016-01-13 ikujam - avoid warning if argument is group
  43. #function is_blocked(\ElggUser $blocked_user, \ElggUser $blocking_user) {
  44. function is_blocked($blocked_user, $blocking_user) {
  45. if (!($blocked_user instanceof \ElggUser) || !($blocking_user instanceof \ElggUser)) {
  46. return false;
  47. }
  48. return (bool) check_entity_relationship($blocking_user->getGUID(), 'blocked', $blocked_user->getGUID());
  49. }