PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/wp-content/plugins/wordpress-seo/admin/roles/class-role-manager-wp.php

https://bitbucket.org/carloskikea/helpet
PHP | 62 lines | 20 code | 7 blank | 35 comment | 1 complexity | c2e998c539a915709bad98a6e5c0cbba MD5 | raw file
 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 */
11final 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 = array() ) {
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		// @codingStandardsIgnoreLine
33		add_role( $role, $display_name, $capabilities );
34	}
35
36	/**
37	 * Removes a role from the system.
38	 *
39	 * @param string $role Role to remove.
40	 *
41	 * @return void
42	 */
43	protected function remove_role( $role ) {
44		remove_role( $role );
45	}
46
47	/**
48	 * Formats the capabilities to the required format.
49	 *
50	 * @param array $capabilities Capabilities to format.
51	 * @param bool  $enabled      Whether these capabilities should be enabled or not.
52	 *
53	 * @return array Formatted capabilities.
54	 */
55	protected function format_capabilities( array $capabilities, $enabled = true ) {
56		// Flip keys and values.
57		$capabilities = array_flip( $capabilities );
58
59		// Set all values to $enabled.
60		return array_fill_keys( array_keys( $capabilities ), $enabled );
61	}
62}