PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.3
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-register-capabilities.php

class-register-capabilities.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.3, at admin/capabilities/class-register-capabilities.php

78 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 * Capabilities registration class.
10 */
11 class WPSEO_Register_Capabilities implements WPSEO_WordPress_Integration {
12
13 /**
14 * Registers the hooks.
15 *
16 * @return void
17 */
18 public function register_hooks() {
19 add_action( 'wpseo_register_capabilities', [ $this, 'register' ] );
20
21 if ( is_multisite() ) {
22 add_action( 'user_has_cap', [ $this, 'filter_user_has_wpseo_manage_options_cap' ], 10, 4 );
23 }
24 }
25
26 /**
27 * Registers the capabilities.
28 *
29 * @return void
30 */
31 public function register() {
32 $manager = WPSEO_Capability_Manager_Factory::get();
33
34 $manager->register( 'wpseo_bulk_edit', [ 'editor', 'wpseo_editor', 'wpseo_manager' ] );
35 $manager->register( 'wpseo_edit_advanced_metadata', [ 'editor', 'wpseo_editor', 'wpseo_manager' ] );
36
37 $manager->register( 'wpseo_manage_options', [ 'administrator', 'wpseo_manager' ] );
38 $manager->register( 'view_site_health_checks', [ 'wpseo_manager' ] );
39 }
40
41 /**
42 * Revokes the 'wpseo_manage_options' capability from administrator users if it should
43 * only be granted to network administrators.
44 *
45 * @param array $allcaps An array of all the user's capabilities.
46 * @param array $caps Actual capabilities being checked.
47 * @param array $args Optional parameters passed to has_cap(), typically object ID.
48 * @param WP_User $user The user object.
49 *
50 * @return array Possibly modified array of the user's capabilities.
51 */
52 public function filter_user_has_wpseo_manage_options_cap( $allcaps, $caps, $args, $user ) {
53
54 // We only need to do something if 'wpseo_manage_options' is being checked.
55 if ( ! in_array( 'wpseo_manage_options', $caps, true ) ) {
56 return $allcaps;
57 }
58
59 // If the user does not have 'wpseo_manage_options' anyway, we don't need to revoke access.
60 if ( empty( $allcaps['wpseo_manage_options'] ) ) {
61 return $allcaps;
62 }
63
64 // If the user does not have 'delete_users', they are not an administrator.
65 if ( empty( $allcaps['delete_users'] ) ) {
66 return $allcaps;
67 }
68
69 $options = WPSEO_Options::get_instance();
70
71 if ( $options->get( 'access' ) === 'superadmin' && ! is_super_admin( $user->ID ) ) {
72 unset( $allcaps['wpseo_manage_options'] );
73 }
74
75 return $allcaps;
76 }
77 }
78