/var/www/hkosl.com/aga/wp-content/plugins/wordpress-seo/inc/options/class-wpseo-option-wpseo.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?php
/**
 * WPSEO plugin file.
 *
 * @package WPSEO\Internals\Options
 */

/**
 * Option: wpseo.
 */
class WPSEO_Option_Wpseo extends WPSEO_Option {

    
/**
     * Option name.
     *
     * @var string
     */
    
public $option_name 'wpseo';

    
/**
     * Array of defaults for the option.
     *
     * {@internal Shouldn't be requested directly, use $this->get_defaults();}}
     *
     * @var array
     */
    
protected $defaults = array(
        
// Non-form fields, set via (ajax) function.
        
'ms_defaults_set'                 => false,
        
// Non-form field, should only be set via validation routine.
        
'version'                         => ''// Leave default as empty to ensure activation/upgrade works.

        // Form fields.
        
'disableadvanced_meta'            => true,
        
'onpage_indexability'             => true,
        
'baiduverify'                     => ''// Text field.
        
'googleverify'                    => ''// Text field.
        
'msverify'                        => ''// Text field.
        
'yandexverify'                    => '',
        
'site_type'                       => ''// List of options.
        
'has_multiple_authors'            => '',
        
'environment_type'                => '',
        
'content_analysis_active'         => true,
        
'keyword_analysis_active'         => true,
        
'enable_admin_bar_menu'           => true,
        
'enable_cornerstone_content'      => true,
        
'enable_xml_sitemap'              => true,
        
'enable_text_link_counter'        => true,
        
'show_onboarding_notice'          => false,
        
'first_activated_on'              => false,
        
'myyoast-oauth'                   => array(
            
'config'        => array(
                
'clientId' => null,
                
'secret'   => null,
            ),
            
'access_tokens' => array(),
        ),
    );

    
/**
     * Sub-options which should not be overloaded with multi-site defaults.
     *
     * @var array
     */
    
public $ms_exclude = array(
        
/* Privacy. */
        
'baiduverify',
        
'googleverify',
        
'msverify',
        
'yandexverify',
    );

    
/**
     * Possible values for the site_type option.
     *
     * @var array
     */
    
protected $site_types = array(
        
'',
        
'blog',
        
'shop',
        
'news',
        
'smallBusiness',
        
'corporateOther',
        
'personalOther',
    );

    
/**
     * Possible environment types.
     *
     * @var array
     */
    
protected $environment_types = array(
        
'',
        
'production',
        
'staging',
        
'development',
    );

    
/**
     * Possible has_multiple_authors options.
     *
     * @var array
     */
    
protected $has_multiple_authors_options = array(
        
'',
        
true,
        
false,
    );

    
/**
     * Name for an option higher in the hierarchy to override setting access.
     *
     * @var string
     */
    
protected $override_option_name 'wpseo_ms';

    
/**
     * Add the actions and filters for the option.
     *
     * @todo [JRF => testers] Check if the extra actions below would run into problems if an option
     * is updated early on and if so, change the call to schedule these for a later action on add/update
     * instead of running them straight away.
     *
     * @return \WPSEO_Option_Wpseo
     */
    
protected function __construct() {
        
parent::__construct();

        
/* Clear the cache on update/add. */
        
add_action'add_option_' $this->option_name, array( 'WPSEO_Utils''clear_cache' ) );
        
add_action'update_option_' $this->option_name, array( 'WPSEO_Utils''clear_cache' ) );

        
/**
         * Filter the `wpseo` option defaults.
         *
         * @param array $defaults Array the defaults for the `wpseo` option attributes.
         */
        
$this->defaults apply_filters'wpseo_option_wpseo_defaults'$this->defaults );
    }

    
/**
     * Get the singleton instance of this class.
     *
     * @return object
     */
    
public static function get_instance() {
        if ( ! ( 
self::$instance instanceof self ) ) {
            
self::$instance = new self();
        }

        return 
self::$instance;
    }

    
/**
     * Add filters to make sure that the option is merged with its defaults before being returned.
     *
     * @return void
     */
    
public function add_option_filters() {
        
parent::add_option_filters();

        list( 
$hookname$callback$priority ) = $this->get_verify_features_option_filter_hook();

        if ( 
has_filter$hookname$callback ) === false ) {
            
add_filter$hookname$callback$priority );
        }
    }

    
/**
     * Remove the option filters.
     * Called from the clean_up methods to make sure we retrieve the original old option.
     *
     * @return void
     */
    
public function remove_option_filters() {
        
parent::remove_option_filters();

        list( 
$hookname$callback$priority ) = $this->get_verify_features_option_filter_hook();

        
remove_filter$hookname$callback$priority );
    }

    
/**
     * Add filters to make sure that the option default is returned if the option is not set.
     *
     * @return void
     */
    
public function add_default_filters() {
        
parent::add_default_filters();

        list( 
$hookname$callback$priority ) = $this->get_verify_features_default_option_filter_hook();

        if ( 
has_filter$hookname$callback ) === false ) {
            
add_filter$hookname$callback$priority );
        }
    }

    
/**
     * Remove the default filters.
     * Called from the validate() method to prevent failure to add new options.
     *
     * @return void
     */
    
public function remove_default_filters() {
        
parent::remove_default_filters();

        list( 
$hookname$callback$priority ) = $this->get_verify_features_default_option_filter_hook();

        
remove_filter$hookname$callback$priority );
    }

    
/**
     * Validate the option.
     *
     * @param array $dirty New value for the option.
     * @param array $clean Clean value for the option, normally the defaults.
     * @param array $old   Old value of the option.
     *
     * @return array Validated clean value for the option to be saved to the database.
     */
    
protected function validate_option$dirty$clean$old ) {

        foreach ( 
$clean as $key => $value ) {
            switch ( 
$key ) {
                case 
'version':
                    
$clean$key ] = WPSEO_VERSION;
                    break;

                
/* Verification strings. */
                
case 'baiduverify':
                case 
'googleverify':
                case 
'msverify':
                case 
'yandexverify':
                    
$this->validate_verification_string$key$dirty$old$clean );
                    break;

                
/*
                 * Boolean dismiss warnings - not fields - may not be in form
                 * (and don't need to be either as long as the default is false).
                 */
                
case 'ms_defaults_set':
                    if ( isset( 
$dirty$key ] ) ) {
                        
$clean$key ] = WPSEO_Utils::validate_bool$dirty$key ] );
                    }
                    elseif ( isset( 
$old$key ] ) ) {
                        
$clean$key ] = WPSEO_Utils::validate_bool$old$key ] );
                    }
                    break;

                case 
'site_type':
                    
$clean$key ] = $old$key ];
                    if ( isset( 
$dirty$key ] ) && in_array$dirty$key ], $this->site_typestrue ) ) {
                        
$clean$key ] = $dirty$key ];
                    }
                    break;

                case 
'environment_type':
                    
$clean$key ] = $old$key ];
                    if ( isset( 
$dirty$key ] ) && in_array$dirty$key ], $this->environment_typestrue ) ) {
                        
$clean$key ] = $dirty$key ];
                    }
                    break;

                case 
'has_multiple_authors':
                    
$clean$key ] = $old$key ];
                    if ( isset( 
$dirty$key ] ) && in_array$dirty$key ], $this->has_multiple_authors_optionstrue ) ) {
                        
$clean$key ] = $dirty$key ];
                    }

                    break;

                case 
'first_activated_on':
                    
$clean$key ] = false;
                    if ( isset( 
$dirty$key ] ) ) {
                        if ( 
$dirty$key ] === false || WPSEO_Utils::validate_int$dirty$key ] ) ) {
                            
$clean$key ] = $dirty$key ];
                        }
                    }
                    break;

                case 
'myyoast_oauth':
                    
$clean$key ] = $old$key ];

                    if ( isset( 
$dirty$key ] ) ) {
                        
$myyoast_oauth $dirty$key ];
                        if ( ! 
is_array$myyoast_oauth ) ) {
                            
$myyoast_oauth json_decode$dirty$key ], true );
                        }

                        if ( 
is_array$myyoast_oauth ) ) {
                            
$clean$key ] = $dirty$key ];
                        }
                    }

                    break;

                
/*
                 * Boolean (checkbox) fields.
                 */

                /*
                 * Covers:
                 *  'disableadvanced_meta'
                 *  'yoast_tracking'
                 */
                
default:
                    
$clean$key ] = ( isset( $dirty$key ] ) ? WPSEO_Utils::validate_bool$dirty$key ] ) : false );
                    break;
            }
        }

        return 
$clean;
    }

    
/**
     * Verifies that the feature variables are turned off if the network is configured so.
     *
     * @param mixed $options Value of the option to be returned. Typically an array.
     *
     * @return mixed Filtered $options value.
     */
    
public function verify_features_against_network$options = array() ) {
        if ( ! 
is_array$options ) || empty( $options ) ) {
            return 
$options;
        }

        
// For the feature variables, set their values to off in case they are disabled.
        
$feature_vars = array(
            
'disableadvanced_meta'       => false,
            
'onpage_indexability'        => false,
            
'content_analysis_active'    => false,
            
'keyword_analysis_active'    => false,
            
'enable_admin_bar_menu'      => false,
            
'enable_cornerstone_content' => false,
            
'enable_xml_sitemap'         => false,
            
'enable_text_link_counter'   => false,
        );

        
// We can reuse this logic from the base class with the above defaults to parse with the correct feature values.
        
$options $this->prevent_disabled_options_update$options$feature_vars );

        return 
$options;
    }

    
/**
     * Gets the filter hook name and callback for adjusting the retrieved option value
     * against the network-allowed features.
     *
     * @return array Array where the first item is the hook name, the second is the hook callback,
     *               and the third is the hook priority.
     */
    
protected function get_verify_features_option_filter_hook() {
        return array(
            
"option_{$this->option_name}",
            array( 
$this'verify_features_against_network' ),
            
11,
        );
    }

    
/**
     * Gets the filter hook name and callback for adjusting the default option value against the network-allowed features.
     *
     * @return array Array where the first item is the hook name, the second is the hook callback,
     *               and the third is the hook priority.
     */
    
protected function get_verify_features_default_option_filter_hook() {
        return array(
            
"default_option_{$this->option_name}",
            array( 
$this'verify_features_against_network' ),
            
11,
        );
    }

    
/**
     * Clean a given option value.
     *
     * @param array  $option_value          Old (not merged with defaults or filtered) option value to
     *                                      clean according to the rules for this option.
     * @param string $current_version       Optional. Version from which to upgrade, if not set,
     *                                      version specific upgrades will be disregarded.
     * @param array  $all_old_option_values Optional. Only used when importing old options to have
     *                                      access to the real old values, in contrast to the saved ones.
     *
     * @return array Cleaned option.
     */
    
protected function clean_option$option_value$current_version null$all_old_option_values null ) {
        return 
$option_value;
    }
}