functions.php 928 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * All helper functions are bundled here
  4. */
  5. /**
  6. * Only site announcement editors can access this part
  7. *
  8. * @return void
  9. */
  10. function site_announcements_editor_gatekeeper() {
  11. elgg_gatekeeper();
  12. if (!site_announcements_is_editor()) {
  13. register_error(elgg_echo('limited_access'));
  14. forward(REFERER);
  15. }
  16. }
  17. /**
  18. * Check if a user is an editor
  19. *
  20. * @param ElggUser $user (optional) the user to check, defaults to loggedin user
  21. *
  22. * @return bool
  23. */
  24. function site_announcements_is_editor(ElggUser $user = null) {
  25. if (empty($user) || !($user instanceof ElggUser)) {
  26. $user = elgg_get_logged_in_user_entity();
  27. }
  28. if (empty($user)) {
  29. return false;
  30. }
  31. // admins are always editors
  32. if ($user->isAdmin()) {
  33. return true;
  34. }
  35. // check normal users
  36. $setting = elgg_get_plugin_user_setting('editor', $user->getGUID(), 'site_announcements');
  37. if (!empty($setting)) {
  38. return true;
  39. }
  40. return false;
  41. }