PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.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
← All changes | admin/capabilities/class-register-capabilities.php +38 -0 18.428.5 View file →
@@ -20,8 +20,13 @@
20 20
21 21 if ( is_multisite() ) {
22 22 add_action( 'user_has_cap', [ $this, 'filter_user_has_wpseo_manage_options_cap' ], 10, 4 );
23 23 }
24 +
25 + /**
26 + * Maybe add manage_privacy_options capability for wpseo_manager user role.
27 + */
28 + add_filter( 'map_meta_cap', [ $this, 'map_meta_cap_for_seo_manager' ], 10, 2 );
24 29 }
25 30
26 31 /**
27 32 * Registers the capabilities.
@@ -72,6 +77,39 @@
72 77 unset( $allcaps['wpseo_manage_options'] );
73 78 }
74 79
75 80 return $allcaps;
81 + }
82 +
83 + /**
84 + * Maybe add manage_privacy_options capability for wpseo_manager user role.
85 + *
86 + * @param string[] $caps Primitive capabilities required of the user.
87 + * @param string[] $cap Capability being checked.
88 + *
89 + * @return string[] Filtered primitive capabilities required of the user.
90 + */
91 + public function map_meta_cap_for_seo_manager( $caps, $cap ) {
92 + $user = wp_get_current_user();
93 +
94 + // No multisite support.
95 + if ( is_multisite() ) {
96 + return $caps;
97 + }
98 +
99 + if ( ! is_array( $user->roles ) ) {
100 + return $caps;
101 + }
102 +
103 + // User must be of role wpseo_manager.
104 + if ( ! in_array( 'wpseo_manager', $user->roles, true ) ) {
105 + return $caps;
106 + }
107 +
108 + // Remove manage_options cap requirement if requested cap is manage_privacy_options.
109 + if ( $cap === 'manage_privacy_options' ) {
110 + return array_diff( $caps, [ 'manage_options' ] );
111 + }
112 +
113 + return $caps;
76 114 }
77 115 }