class-role-manager-vip.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Roles
  6. */
  7. /**
  8. * VIP implementation of the Role Manager.
  9. */
  10. final class WPSEO_Role_Manager_VIP extends WPSEO_Abstract_Role_Manager {
  11. /**
  12. * Adds a role to the system.
  13. *
  14. * @param string $role Role to add.
  15. * @param string $display_name Name to display for the role.
  16. * @param array $capabilities Capabilities to add to the role.
  17. *
  18. * @return void
  19. */
  20. protected function add_role( $role, $display_name, array $capabilities = [] ) {
  21. $enabled_capabilities = [];
  22. $disabled_capabilities = [];
  23. // Build lists of enabled and disabled capabilities.
  24. foreach ( $capabilities as $capability => $grant ) {
  25. if ( $grant ) {
  26. $enabled_capabilities[] = $capability;
  27. }
  28. if ( ! $grant ) {
  29. $disabled_capabilities[] = $capability;
  30. }
  31. }
  32. wpcom_vip_add_role( $role, $display_name, $enabled_capabilities );
  33. if ( $disabled_capabilities !== [] ) {
  34. wpcom_vip_remove_role_caps( $role, $disabled_capabilities );
  35. }
  36. }
  37. /**
  38. * Removes a role from the system.
  39. *
  40. * @param string $role Role to remove.
  41. *
  42. * @return void
  43. */
  44. protected function remove_role( $role ) {
  45. remove_role( $role );
  46. }
  47. }