PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.5
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-capability-manager-integration.php

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

120 lines 3.0 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 * Integrates Yoast SEO capabilities with third party role manager plugins.
10 *
11 * Integrates with: Members
12 * Integrates with: User Role Editor
13 */
14 class WPSEO_Capability_Manager_Integration implements WPSEO_WordPress_Integration {
15
16 /**
17 * Capability manager to use.
18 *
19 * @var WPSEO_Capability_Manager
20 */
21 public $manager;
22
23 /**
24 * WPSEO_Capability_Manager_Integration constructor.
25 *
26 * @param WPSEO_Capability_Manager $manager The capability manager to use.
27 */
28 public function __construct( WPSEO_Capability_Manager $manager ) {
29 $this->manager = $manager;
30 }
31
32 /**
33 * Registers the hooks.
34 *
35 * @return void
36 */
37 public function register_hooks() {
38 add_filter( 'members_get_capabilities', [ $this, 'get_capabilities' ] );
39 add_action( 'members_register_cap_groups', [ $this, 'action_members_register_cap_group' ] );
40
41 add_filter( 'ure_capabilities_groups_tree', [ $this, 'filter_ure_capabilities_groups_tree' ] );
42 add_filter( 'ure_custom_capability_groups', [ $this, 'filter_ure_custom_capability_groups' ], 10, 2 );
43 }
44
45 /**
46 * Get the Yoast SEO capabilities.
47 * Optionally append them to an existing array.
48 *
49 * @param array $caps Optional existing capability list.
50 * @return array
51 */
52 public function get_capabilities( array $caps = [] ) {
53 if ( ! did_action( 'wpseo_register_capabilities' ) ) {
54 do_action( 'wpseo_register_capabilities' );
55 }
56
57 return array_merge( $caps, $this->manager->get_capabilities() );
58 }
59
60 /**
61 * Add capabilities to its own group in the Members plugin.
62 *
63 * @see members_register_cap_group()
64 */
65 public function action_members_register_cap_group() {
66 if ( ! function_exists( 'members_register_cap_group' ) ) {
67 return;
68 }
69
70 // Register the yoast group.
71 $args = [
72 'label' => esc_html__( 'Yoast SEO', 'wordpress-seo' ),
73 'caps' => $this->get_capabilities(),
74 'icon' => 'dashicons-admin-plugins',
75 'diff_added' => true,
76 ];
77 members_register_cap_group( 'wordpress-seo', $args );
78 }
79
80 /**
81 * Adds Yoast SEO capability group in the User Role Editor plugin.
82 *
83 * @see URE_Capabilities_Groups_Manager::get_groups_tree()
84 *
85 * @param array $groups Current groups.
86 *
87 * @return array Filtered list of capabilty groups.
88 */
89 public function filter_ure_capabilities_groups_tree( $groups = [] ) {
90 $groups = (array) $groups;
91
92 $groups['wordpress-seo'] = [
93 'caption' => 'Yoast SEO',
94 'parent' => 'custom',
95 'level' => 3,
96 ];
97
98 return $groups;
99 }
100
101 /**
102 * Adds capabilities to the Yoast SEO group in the User Role Editor plugin.
103 *
104 * @see URE_Capabilities_Groups_Manager::get_cap_groups()
105 *
106 * @param array $groups Current capability groups.
107 * @param string $cap_id Capability identifier.
108 *
109 * @return array List of filtered groups.
110 */
111 public function filter_ure_custom_capability_groups( $groups = [], $cap_id = '' ) {
112 if ( in_array( $cap_id, $this->get_capabilities(), true ) ) {
113 $groups = (array) $groups;
114 $groups[] = 'wordpress-seo';
115 }
116
117 return $groups;
118 }
119 }
120