PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
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 / capabilities / class-abstract-capability-manager.php

class-abstract-capability-manager.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 19.0, at admin/capabilities/class-abstract-capability-manager.php

90 lines 2.2 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\Capabilities
6 */
7
8 /**
9 * Abstract Capability Manager shared code.
10 */
11 abstract class WPSEO_Abstract_Capability_Manager implements WPSEO_Capability_Manager {
12
13 /**
14 * Registered capabilities.
15 *
16 * @var array
17 */
18 protected $capabilities = [];
19
20 /**
21 * Registers a capability.
22 *
23 * @param string $capability Capability to register.
24 * @param array $roles Roles to add the capability to.
25 * @param bool $overwrite Optional. Use add or overwrite as registration method.
26 */
27 public function register( $capability, array $roles, $overwrite = false ) {
28 if ( $overwrite || ! isset( $this->capabilities[ $capability ] ) ) {
29 $this->capabilities[ $capability ] = $roles;
30
31 return;
32 }
33
34 // Combine configurations.
35 $this->capabilities[ $capability ] = array_merge( $roles, $this->capabilities[ $capability ] );
36
37 // Remove doubles.
38 $this->capabilities[ $capability ] = array_unique( $this->capabilities[ $capability ] );
39 }
40
41 /**
42 * Returns the list of registered capabilitities.
43 *
44 * @return string[] Registered capabilities.
45 */
46 public function get_capabilities() {
47 return array_keys( $this->capabilities );
48 }
49
50 /**
51 * Returns a list of WP_Role roles.
52 *
53 * The string array of role names are converted to actual WP_Role objects.
54 * These are needed to be able to use the API on them.
55 *
56 * @param array $roles Roles to retrieve the objects for.
57 *
58 * @return WP_Role[] List of WP_Role objects.
59 */
60 protected function get_wp_roles( array $roles ) {
61 $wp_roles = array_map( 'get_role', $roles );
62
63 return array_filter( $wp_roles );
64 }
65
66 /**
67 * Filter capability roles.
68 *
69 * @param string $capability Capability to filter roles for.
70 * @param array $roles List of roles which can be filtered.
71 *
72 * @return array Filtered list of roles for the capability.
73 */
74 protected function filter_roles( $capability, array $roles ) {
75 /**
76 * Filter: Allow changing roles that a capability is added to.
77 *
78 * @api array $roles The default roles to be filtered.
79 */
80 $filtered = apply_filters( $capability . '_roles', $roles );
81
82 // Make sure we have the expected type.
83 if ( ! is_array( $filtered ) ) {
84 return [];
85 }
86
87 return $filtered;
88 }
89 }
90