class-wpseo-option-permalinks.php
3.84 KB
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
<?php
/**
* @package WPSEO\Internals\Options
*/
/**
* @internal Clean routine for 1.5 not needed as values used to be saved as string 'on' and those will convert
* automatically
*/
class WPSEO_Option_Permalinks extends WPSEO_Option {
/**
* @var string option name
*/
public $option_name = 'wpseo_permalinks';
/**
* @var array Array of defaults for the option
* Shouldn't be requested directly, use $this->get_defaults();
*/
protected $defaults = array(
'cleanpermalinks' => false,
'cleanpermalink-extravars' => '', // Text field.
'cleanpermalink-googlecampaign' => false,
'cleanpermalink-googlesitesearch' => false,
'cleanreplytocom' => false,
'cleanslugs' => true,
'hide-feedlinks' => false,
'hide-rsdlink' => false,
'hide-shortlink' => false,
'hide-wlwmanifest' => false,
'redirectattachment' => false,
'stripcategorybase' => false,
'trailingslash' => false,
);
/**
* 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_Permalinks
*/
protected function __construct() {
parent::__construct();
add_action( 'update_option_' . $this->option_name, array( 'WPSEO_Utils', 'clear_rewrites' ) );
}
/**
* 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;
}
/**
* 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 (not used here as all fields will always be in the form).
*
* @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 ) {
/* text fields */
case 'cleanpermalink-extravars':
if ( isset( $dirty[ $key ] ) && $dirty[ $key ] !== '' ) {
$clean[ $key ] = sanitize_text_field( $dirty[ $key ] );
}
break;
/*
Boolean (checkbox) fields
*/
/*
Covers:
* 'cleanpermalinks'
* 'cleanpermalink-googlesitesearch'
* 'cleanpermalink-googlecampaign'
* 'cleanreplytocom'
* 'cleanslugs'
* 'hide-rsdlink'
* 'hide-wlwmanifest'
* 'hide-shortlink'
* 'hide-feedlinks'
* 'redirectattachment'
* 'stripcategorybase'
* 'trailingslash'
*/
default:
$clean[ $key ] = ( isset( $dirty[ $key ] ) ? WPSEO_Utils::validate_bool( $dirty[ $key ] ) : false );
break;
}
}
return $clean;
}
/**
* 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;
}
*/
}