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

Yoast / wordpress-seo / 11f37ccb74cdb9a662c903f27216a1cdf1c8d9ac

19 Aug 2024 07:41AM UTC coverage: 48.692% (-5.4%) from 54.055%
11f37ccb74cdb9a662c903f27216a1cdf1c8d9ac

push

github

web-flow
Merge pull request #21541 from Yoast/fix-elementor-mutation-observer

Only handle editor changes when on the document from our form

7479 of 13543 branches covered (55.22%)

Branch coverage included in aggregate %.

0 of 6 new or added lines in 2 files covered. (0.0%)

4422 existing lines in 144 files now uncovered.

25345 of 53868 relevant lines covered (47.05%)

42392.33 hits per line

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

0.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
         */
UNCOV
36
        public function register() {
×
UNCOV
37
                $manager = WPSEO_Capability_Manager_Factory::get();
×
38

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

UNCOV
42
                $manager->register( 'wpseo_manage_options', [ 'administrator', 'wpseo_manager' ] );
×
UNCOV
43
                $manager->register( 'view_site_health_checks', [ 'wpseo_manager' ] );
×
44
        }
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
         */
UNCOV
57
        public function filter_user_has_wpseo_manage_options_cap( $allcaps, $caps, $args, $user ) {
×
58

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

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

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

UNCOV
74
                $options = WPSEO_Options::get_instance();
×
75

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

UNCOV
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
                // 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