PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.8
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / roles / class-role-manager-wp.php

class-role-manager-wp.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.8, at admin/roles/class-role-manager-wp.php

62 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin\Roles
6 */
7
8 /**
9 * WordPress' default implementation of the Role Manager.
10 */
11 final class WPSEO_Role_Manager_WP extends WPSEO_Abstract_Role_Manager {
12
13 /**
14 * Adds a role to the system.
15 *
16 * @param string $role Role to add.
17 * @param string $display_name Name to display for the role.
18 * @param array $capabilities Capabilities to add to the role.
19 *
20 * @return void
21 */
22 protected function add_role( $role, $display_name, array $capabilities = [] ) {
23 $wp_role = get_role( $role );
24 if ( $wp_role ) {
25 foreach ( $capabilities as $capability => $grant ) {
26 $wp_role->add_cap( $capability, $grant );
27 }
28
29 return;
30 }
31
32 add_role( $role, $display_name, $capabilities );
33 }
34
35 /**
36 * Removes a role from the system.
37 *
38 * @param string $role Role to remove.
39 *
40 * @return void
41 */
42 protected function remove_role( $role ) {
43 remove_role( $role );
44 }
45
46 /**
47 * Formats the capabilities to the required format.
48 *
49 * @param array $capabilities Capabilities to format.
50 * @param bool $enabled Whether these capabilities should be enabled or not.
51 *
52 * @return array Formatted capabilities.
53 */
54 protected function format_capabilities( array $capabilities, $enabled = true ) {
55 // Flip keys and values.
56 $capabilities = array_flip( $capabilities );
57
58 // Set all values to $enabled.
59 return array_fill_keys( array_keys( $capabilities ), $enabled );
60 }
61 }
62