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

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

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

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

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

0.0
/admin/class-yoast-network-settings-api.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Admin\Network
6
 */
7

8
/**
9
 * Implements a network settings API for the plugin's multisite settings.
10
 */
11
class Yoast_Network_Settings_API {
12

13
        /**
14
         * Registered network settings.
15
         *
16
         * @var array
17
         */
18
        private $registered_settings = [];
19

20
        /**
21
         * Options whitelist, keyed by option group.
22
         *
23
         * @var array
24
         */
25
        private $whitelist_options = [];
26

27
        /**
28
         * The singleton instance of this class.
29
         *
30
         * @var Yoast_Network_Settings_API
31
         */
32
        private static $instance = null;
33

34
        /**
35
         * Registers a network setting and its data.
36
         *
37
         * @param string $option_group The group the network option is part of.
38
         * @param string $option_name  The name of the network option to sanitize and save.
39
         * @param array  $args         {
40
         *     Optional. Data used to describe the network setting when registered.
41
         *
42
         *     @type callable $sanitize_callback A callback function that sanitizes the network option's value.
43
         *     @type mixed    $default           Default value when calling `get_network_option()`.
44
         * }
45
         *
46
         * @return void
47
         */
UNCOV
48
        public function register_setting( $option_group, $option_name, $args = [] ) {
×
49

UNCOV
50
                $defaults = [
×
UNCOV
51
                        'group'             => $option_group,
×
UNCOV
52
                        'sanitize_callback' => null,
×
UNCOV
53
                ];
×
UNCOV
54
                $args     = wp_parse_args( $args, $defaults );
×
55

UNCOV
56
                if ( ! isset( $this->whitelist_options[ $option_group ] ) ) {
×
UNCOV
57
                        $this->whitelist_options[ $option_group ] = [];
×
58
                }
59

UNCOV
60
                $this->whitelist_options[ $option_group ][] = $option_name;
×
61

UNCOV
62
                if ( ! empty( $args['sanitize_callback'] ) ) {
×
UNCOV
63
                        add_filter( "sanitize_option_{$option_name}", [ $this, 'filter_sanitize_option' ], 10, 2 );
×
64
                }
65

UNCOV
66
                if ( array_key_exists( 'default', $args ) ) {
×
UNCOV
67
                        add_filter( "default_site_option_{$option_name}", [ $this, 'filter_default_option' ], 10, 2 );
×
68
                }
69

UNCOV
70
                $this->registered_settings[ $option_name ] = $args;
×
71
        }
72

73
        /**
74
         * Gets the registered settings and their data.
75
         *
76
         * @return array Array of $option_name => $data pairs.
77
         */
UNCOV
78
        public function get_registered_settings() {
×
UNCOV
79
                return $this->registered_settings;
×
80
        }
81

82
        /**
83
         * Gets the whitelisted options for a given option group.
84
         *
85
         * @param string $option_group Option group.
86
         *
87
         * @return array List of option names, or empty array if unknown option group.
88
         */
UNCOV
89
        public function get_whitelist_options( $option_group ) {
×
UNCOV
90
                if ( ! isset( $this->whitelist_options[ $option_group ] ) ) {
×
UNCOV
91
                        return [];
×
92
                }
93

UNCOV
94
                return $this->whitelist_options[ $option_group ];
×
95
        }
96

97
        /**
98
         * Filters sanitization for a network option value.
99
         *
100
         * This method is added as a filter to `sanitize_option_{$option}` for network options that are
101
         * registered with a sanitize callback.
102
         *
103
         * @param string $value  The sanitized option value.
104
         * @param string $option The option name.
105
         *
106
         * @return string The filtered sanitized option value.
107
         */
UNCOV
108
        public function filter_sanitize_option( $value, $option ) {
×
109

UNCOV
110
                if ( empty( $this->registered_settings[ $option ] ) ) {
×
UNCOV
111
                        return $value;
×
112
                }
113

UNCOV
114
                return call_user_func( $this->registered_settings[ $option ]['sanitize_callback'], $value );
×
115
        }
116

117
        /**
118
         * Filters the default value for a network option.
119
         *
120
         * This function is added as a filter to `default_site_option_{$option}` for network options that
121
         * are registered with a default.
122
         *
123
         * @param mixed  $default_value Existing default value to return.
124
         * @param string $option        The option name.
125
         *
126
         * @return mixed The filtered default value.
127
         */
UNCOV
128
        public function filter_default_option( $default_value, $option ) {
×
129

130
                // If a default value was manually passed to the function, allow it to override.
UNCOV
131
                if ( $default_value !== false ) {
×
UNCOV
132
                        return $default_value;
×
133
                }
134

UNCOV
135
                if ( empty( $this->registered_settings[ $option ] ) ) {
×
UNCOV
136
                        return $default_value;
×
137
                }
138

UNCOV
139
                return $this->registered_settings[ $option ]['default'];
×
140
        }
141

142
        /**
143
         * Checks whether the requirements to use this class are met.
144
         *
145
         * @return bool True if requirements are met, false otherwise.
146
         */
UNCOV
147
        public function meets_requirements() {
×
UNCOV
148
                return is_multisite();
×
149
        }
150

151
        /**
152
         * Gets the singleton instance of this class.
153
         *
154
         * @return Yoast_Network_Settings_API The singleton instance.
155
         */
UNCOV
156
        public static function get() {
×
157

UNCOV
158
                if ( self::$instance === null ) {
×
159
                        self::$instance = new self();
×
160
                }
161

UNCOV
162
                return self::$instance;
×
163
        }
164
}
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