• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 6987097851

25 Nov 2023 04:49AM UTC coverage: 49.206% (-0.1%) from 49.302%
6987097851

push

github

web-flow
Merge pull request #20878 from Yoast/JRF/ghactions-minor-tweak

GH Actions: update a few links in inline comments

15305 of 31104 relevant lines covered (49.21%)

4.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/admin/capabilities/class-register-capabilities.php
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
                 * 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 );
×
29
        }
30

31
        /**
32
         * Registers the capabilities.
33
         *
34
         * @return void
35
         */
36
        public function register() {
4✔
37
                $manager = WPSEO_Capability_Manager_Factory::get();
4✔
38

39
                $manager->register( 'wpseo_bulk_edit', [ 'editor', 'wpseo_editor', 'wpseo_manager' ] );
4✔
40
                $manager->register( 'wpseo_edit_advanced_metadata', [ 'editor', 'wpseo_editor', 'wpseo_manager' ] );
4✔
41

42
                $manager->register( 'wpseo_manage_options', [ 'administrator', 'wpseo_manager' ] );
4✔
43
                $manager->register( 'view_site_health_checks', [ 'wpseo_manager' ] );
4✔
44
        }
2✔
45

46
        /**
47
         * Revokes the 'wpseo_manage_options' capability from administrator users if it should
48
         * only be granted to network administrators.
49
         *
50
         * @param array   $allcaps An array of all the user's capabilities.
51
         * @param array   $caps    Actual capabilities being checked.
52
         * @param array   $args    Optional parameters passed to has_cap(), typically object ID.
53
         * @param WP_User $user    The user object.
54
         *
55
         * @return array Possibly modified array of the user's capabilities.
56
         */
57
        public function filter_user_has_wpseo_manage_options_cap( $allcaps, $caps, $args, $user ) {
12✔
58

59
                // We only need to do something if 'wpseo_manage_options' is being checked.
60
                if ( ! in_array( 'wpseo_manage_options', $caps, true ) ) {
12✔
61
                        return $allcaps;
×
62
                }
63

64
                // If the user does not have 'wpseo_manage_options' anyway, we don't need to revoke access.
65
                if ( empty( $allcaps['wpseo_manage_options'] ) ) {
12✔
66
                        return $allcaps;
×
67
                }
68

69
                // If the user does not have 'delete_users', they are not an administrator.
70
                if ( empty( $allcaps['delete_users'] ) ) {
12✔
71
                        return $allcaps;
4✔
72
                }
73

74
                $options = WPSEO_Options::get_instance();
8✔
75

76
                if ( $options->get( 'access' ) === 'superadmin' && ! is_super_admin( $user->ID ) ) {
8✔
77
                        unset( $allcaps['wpseo_manage_options'] );
2✔
78
                }
79

80
                return $allcaps;
8✔
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
                // User must be of role wpseo_manager.
100
                if ( ! in_array( 'wpseo_manager', $user->roles, true ) ) {
×
101
                        return $caps;
×
102
                }
103

104
                // Remove manage_options cap requirement if requested cap is manage_privacy_options.
105
                if ( $cap === 'manage_privacy_options' ) {
×
106
                        return array_diff( $caps, [ 'manage_options' ] );
×
107
                }
108

109
                return $caps;
×
110
        }
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc