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

Yoast / wordpress-seo / 7004843404

27 Nov 2023 11:48AM UTC coverage: 49.206% (-0.03%) from 49.232%
7004843404

push

github

web-flow
Merge pull request #20858 from Yoast/improve-copy-in-the-ftc-57

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

59.26
/admin/capabilities/class-capability-utils.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Capabilities
6
 */
7

8
/**
9
 * Capability Utils collection.
10
 */
11
class WPSEO_Capability_Utils {
12

13
        /**
14
         * Checks if the user has the proper capabilities.
15
         *
16
         * @param string $capability Capability to check.
17
         *
18
         * @return bool True if the user has the proper rights.
19
         */
20
        public static function current_user_can( $capability ) {
×
21
                if ( $capability === 'wpseo_manage_options' ) {
×
22
                        return self::has( $capability );
×
23
                }
24

25
                return self::has_any( [ 'wpseo_manage_options', $capability ] );
×
26
        }
27

28
        /**
29
         * Retrieves the users that have the specified capability.
30
         *
31
         * @param string $capability The name of the capability.
32
         *
33
         * @return array The users that have the capability.
34
         */
35
        public static function get_applicable_users( $capability ) {
4✔
36
                $applicable_roles = self::get_applicable_roles( $capability );
4✔
37

38
                if ( $applicable_roles === [] ) {
4✔
39
                        return [];
2✔
40
                }
41

42
                return get_users( [ 'role__in' => $applicable_roles ] );
2✔
43
        }
44

45
        /**
46
         * Retrieves the roles that have the specified capability.
47
         *
48
         * @param string $capability The name of the capability.
49
         *
50
         * @return array The names of the roles that have the capability.
51
         */
52
        public static function get_applicable_roles( $capability ) {
6✔
53
                $roles      = wp_roles();
6✔
54
                $role_names = $roles->get_names();
6✔
55

56
                $applicable_roles = [];
6✔
57
                foreach ( array_keys( $role_names ) as $role_name ) {
6✔
58
                        $role = $roles->get_role( $role_name );
6✔
59

60
                        if ( ! $role ) {
6✔
61
                                continue;
2✔
62
                        }
63

64
                        // Add role if it has the capability.
65
                        if ( array_key_exists( $capability, $role->capabilities ) && $role->capabilities[ $capability ] === true ) {
4✔
66
                                $applicable_roles[] = $role_name;
2✔
67
                        }
68
                }
69

70
                return $applicable_roles;
6✔
71
        }
72

73
        /**
74
         * Checks if the current user has at least one of the supplied capabilities.
75
         *
76
         * @param array $capabilities Capabilities to check against.
77
         *
78
         * @return bool True if the user has at least one capability.
79
         */
80
        protected static function has_any( array $capabilities ) {
×
81
                foreach ( $capabilities as $capability ) {
×
82
                        if ( self::has( $capability ) ) {
×
83
                                return true;
×
84
                        }
85
                }
86

87
                return false;
×
88
        }
89

90
        /**
91
         * Checks if the user has a certain capability.
92
         *
93
         * @param string $capability Capability to check against.
94
         *
95
         * @return bool True if the user has the capability.
96
         */
97
        protected static function has( $capability ) {
×
98
                return current_user_can( $capability );
×
99
        }
100
}
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

© 2025 Coveralls, Inc