/wp-content/plugins/wordpress-seo/admin/capabilities/class-capability-utils.php

https://bitbucket.org/carloskikea/helpet · PHP · 54 lines · 20 code · 5 blank · 29 comment · 2 complexity · 4b7e532d6474ccbfb5769691e5d37bd1 MD5 · raw file

  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Capabilities
  6. */
  7. /**
  8. * Capability Utils collection.
  9. */
  10. class WPSEO_Capability_Utils {
  11. /**
  12. * Checks if the user has the proper capabilities.
  13. *
  14. * @param string $capability Capability to check.
  15. *
  16. * @return bool True if the user has the proper rights.
  17. */
  18. public static function current_user_can( $capability ) {
  19. if ( $capability === 'wpseo_manage_options' ) {
  20. return self::has( $capability );
  21. }
  22. return self::has_any( array( 'wpseo_manage_options', $capability ) );
  23. }
  24. /**
  25. * Checks if the current user has at least one of the supplied capabilities.
  26. *
  27. * @param array $capabilities Capabilities to check against.
  28. *
  29. * @return bool True if the user has at least one capability.
  30. */
  31. protected static function has_any( array $capabilities ) {
  32. foreach ( $capabilities as $capability ) {
  33. if ( self::has( $capability ) ) {
  34. return true;
  35. }
  36. }
  37. return false;
  38. }
  39. /**
  40. * Checks if the user has a certain capability.
  41. *
  42. * @param string $capability Capability to check against.
  43. *
  44. * @return bool True if the user has the capability.
  45. */
  46. protected static function has( $capability ) {
  47. return current_user_can( $capability );
  48. }
  49. }