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

https://bitbucket.org/carloskikea/helpet · PHP · 72 lines · 33 code · 9 blank · 30 comment · 1 complexity · 8793cf1a470323ee882028440aa1714e MD5 · raw file

  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Capabilities
  6. */
  7. /**
  8. * VIP implementation of the Capability Manager.
  9. */
  10. final class WPSEO_Capability_Manager_VIP extends WPSEO_Abstract_Capability_Manager {
  11. /**
  12. * Adds the registered capabilities to the system.
  13. *
  14. * @return void
  15. */
  16. public function add() {
  17. $role_capabilities = array();
  18. foreach ( $this->capabilities as $capability => $roles ) {
  19. $role_capabilities = $this->get_role_capabilities( $role_capabilities, $capability, $roles );
  20. }
  21. foreach ( $role_capabilities as $role => $capabilities ) {
  22. wpcom_vip_add_role_caps( $role, $capabilities );
  23. }
  24. }
  25. /**
  26. * Removes the registered capabilities from the system
  27. *
  28. * @return void
  29. */
  30. public function remove() {
  31. // Remove from any role it has been added to.
  32. $roles = wp_roles()->get_names();
  33. $roles = array_keys( $roles );
  34. $role_capabilities = array();
  35. foreach ( array_keys( $this->capabilities ) as $capability ) {
  36. // Allow filtering of roles.
  37. $role_capabilities = $this->get_role_capabilities( $role_capabilities, $capability, $roles );
  38. }
  39. foreach ( $role_capabilities as $role => $capabilities ) {
  40. wpcom_vip_remove_role_caps( $role, $capabilities );
  41. }
  42. }
  43. /**
  44. * Returns the roles which the capability is registered on.
  45. *
  46. * @param array $role_capabilities List of all roles with their capabilities.
  47. * @param string $capability Capability to filter roles for.
  48. * @param array $roles List of default roles.
  49. *
  50. * @return array List of capabilities.
  51. */
  52. protected function get_role_capabilities( $role_capabilities, $capability, $roles ) {
  53. // Allow filtering of roles.
  54. $filtered_roles = $this->filter_roles( $capability, $roles );
  55. foreach ( $filtered_roles as $role ) {
  56. if ( ! isset( $add_role_caps[ $role ] ) ) {
  57. $role_capabilities[ $role ] = array();
  58. }
  59. $role_capabilities[ $role ][] = $capability;
  60. }
  61. return $role_capabilities;
  62. }
  63. }