author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Option API |
|
4 |
* |
|
5 |
* @package WordPress |
|
5 | 6 |
* @subpackage Option |
0 | 7 |
*/ |
8 |
||
9 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
* Retrieves an option value based on an option name. |
0 | 11 |
* |
18 | 12 |
* If the option does not exist, and a default value is not provided, |
13 |
* boolean false is returned. This could be used to check whether you need |
|
14 |
* to initialize an option during installation of a plugin, however that |
|
15 |
* can be done better by using add_option() which will not overwrite |
|
16 |
* existing options. |
|
17 |
* |
|
18 |
* Not initializing an option and using boolean `false` as a return value |
|
19 |
* is a bad practice as it triggers an additional database query. |
|
20 |
* |
|
21 |
* The type of the returned value can be different from the type that was passed |
|
22 |
* when saving or updating the option. If the option value was serialized, |
|
23 |
* then it will be unserialized when it is returned. In this case the type will |
|
24 |
* be the same. For example, storing a non-scalar value like an array will |
|
25 |
* return the same array. |
|
26 |
* |
|
27 |
* In most cases non-string scalar and null values will be converted and returned |
|
28 |
* as string equivalents. |
|
0 | 29 |
* |
18 | 30 |
* Exceptions: |
31 |
* 1. When the option has not been saved in the database, the `$default` value |
|
32 |
* is returned if provided. If not, boolean `false` is returned. |
|
33 |
* 2. When one of the Options API filters is used: {@see 'pre_option_{$option}'}, |
|
34 |
* {@see 'default_option_{$option}'}, or {@see 'option_{$option}'}, the returned |
|
35 |
* value may not match the expected type. |
|
36 |
* 3. When the option has just been saved in the database, and get_option() |
|
37 |
* is used right after, non-string scalar and null values are not converted to |
|
38 |
* string equivalents and the original type is returned. |
|
39 |
* |
|
40 |
* Examples: |
|
41 |
* |
|
42 |
* When adding options like this: `add_option( 'my_option_name', 'value' );` |
|
43 |
* and then retrieving them with `get_option( 'my_option_name' );`, the returned |
|
44 |
* values will be: |
|
0 | 45 |
* |
18 | 46 |
* `false` returns `string(0) ""` |
47 |
* `true` returns `string(1) "1"` |
|
48 |
* `0` returns `string(1) "0"` |
|
49 |
* `1` returns `string(1) "1"` |
|
50 |
* `'0'` returns `string(1) "0"` |
|
51 |
* `'1'` returns `string(1) "1"` |
|
52 |
* `null` returns `string(0) ""` |
|
53 |
* |
|
54 |
* When adding options with non-scalar values like |
|
55 |
* `add_option( 'my_array', array( false, 'str', null ) );`, the returned value |
|
56 |
* will be identical to the original as it is serialized before saving |
|
57 |
* it in the database: |
|
58 |
* |
|
59 |
* array(3) { |
|
60 |
* [0] => bool(false) |
|
61 |
* [1] => string(3) "str" |
|
62 |
* [2] => NULL |
|
63 |
* } |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
* |
0 | 65 |
* @since 1.5.0 |
66 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
* |
16 | 69 |
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
* @param mixed $default Optional. Default value to return if the option does not exist. |
18 | 71 |
* @return mixed Value of the option. A value of any type may be returned, including |
72 |
* scalar (string, boolean, float, integer), null, array, object. |
|
73 |
* Scalar and null values will be returned as strings as long as they originate |
|
74 |
* from a database stored option value. If there is no option in the database, |
|
75 |
* boolean `false` is returned. |
|
0 | 76 |
*/ |
77 |
function get_option( $option, $default = false ) { |
|
78 |
global $wpdb; |
|
79 |
||
80 |
$option = trim( $option ); |
|
9 | 81 |
if ( empty( $option ) ) { |
0 | 82 |
return false; |
9 | 83 |
} |
0 | 84 |
|
16 | 85 |
/* |
86 |
* Until a proper _deprecated_option() function can be introduced, |
|
87 |
* redirect requests to deprecated keys to the new, correct ones. |
|
88 |
*/ |
|
89 |
$deprecated_keys = array( |
|
90 |
'blacklist_keys' => 'disallowed_keys', |
|
91 |
'comment_whitelist' => 'comment_previously_approved', |
|
92 |
); |
|
93 |
||
94 |
if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) { |
|
95 |
_deprecated_argument( |
|
96 |
__FUNCTION__, |
|
97 |
'5.5.0', |
|
98 |
sprintf( |
|
99 |
/* translators: 1: Deprecated option key, 2: New option key. */ |
|
100 |
__( 'The "%1$s" option key has been renamed to "%2$s".' ), |
|
101 |
$option, |
|
102 |
$deprecated_keys[ $option ] |
|
103 |
) |
|
104 |
); |
|
105 |
return get_option( $deprecated_keys[ $option ], $default ); |
|
106 |
} |
|
107 |
||
5 | 108 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
* Filters the value of an existing option before it is retrieved. |
5 | 110 |
* |
111 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
112 |
* |
|
16 | 113 |
* Returning a truthy value from the filter will effectively short-circuit retrieval |
114 |
* and return the passed value instead. |
|
5 | 115 |
* |
116 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
* @since 4.9.0 The `$default` parameter was added. |
5 | 119 |
* |
16 | 120 |
* @param mixed $pre_option The value to return instead of the option value. This differs |
121 |
* from `$default`, which is used as the fallback value in the event |
|
122 |
* the option doesn't exist elsewhere in get_option(). |
|
123 |
* Default false (to skip past the short-circuit). |
|
124 |
* @param string $option Option name. |
|
125 |
* @param mixed $default The fallback value to return if the option does not exist. |
|
126 |
* Default false. |
|
5 | 127 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
$pre = apply_filters( "pre_option_{$option}", false, $option, $default ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
|
9 | 130 |
if ( false !== $pre ) { |
0 | 131 |
return $pre; |
9 | 132 |
} |
0 | 133 |
|
9 | 134 |
if ( defined( 'WP_SETUP_CONFIG' ) ) { |
0 | 135 |
return false; |
9 | 136 |
} |
0 | 137 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
// Distinguish between `false` as a default, and not passing one. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
$passed_default = func_num_args() > 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
if ( ! wp_installing() ) { |
16 | 142 |
// Prevent non-existent options from triggering multiple queries. |
0 | 143 |
$notoptions = wp_cache_get( 'notoptions', 'options' ); |
16 | 144 |
|
5 | 145 |
if ( isset( $notoptions[ $option ] ) ) { |
146 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
* Filters the default value for an option. |
5 | 148 |
* |
149 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
150 |
* |
|
151 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
* @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. |
5 | 154 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
* @param mixed $default The default value to return if the option does not exist |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
* in the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
* @param bool $passed_default Was `get_option()` passed a default value? |
5 | 159 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
5 | 161 |
} |
0 | 162 |
|
163 |
$alloptions = wp_load_alloptions(); |
|
164 |
||
9 | 165 |
if ( isset( $alloptions[ $option ] ) ) { |
166 |
$value = $alloptions[ $option ]; |
|
0 | 167 |
} else { |
168 |
$value = wp_cache_get( $option, 'options' ); |
|
169 |
||
170 |
if ( false === $value ) { |
|
171 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
|
172 |
||
16 | 173 |
// Has to be get_row() instead of get_var() because of funkiness with 0, false, null values. |
0 | 174 |
if ( is_object( $row ) ) { |
175 |
$value = $row->option_value; |
|
176 |
wp_cache_add( $option, $value, 'options' ); |
|
16 | 177 |
} else { // Option does not exist, so we must cache its non-existence. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
if ( ! is_array( $notoptions ) ) { |
9 | 179 |
$notoptions = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
} |
16 | 181 |
|
9 | 182 |
$notoptions[ $option ] = true; |
0 | 183 |
wp_cache_set( 'notoptions', $notoptions, 'options' ); |
5 | 184 |
|
185 |
/** This filter is documented in wp-includes/option.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
0 | 187 |
} |
188 |
} |
|
189 |
} |
|
190 |
} else { |
|
191 |
$suppress = $wpdb->suppress_errors(); |
|
9 | 192 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
0 | 193 |
$wpdb->suppress_errors( $suppress ); |
16 | 194 |
|
5 | 195 |
if ( is_object( $row ) ) { |
0 | 196 |
$value = $row->option_value; |
5 | 197 |
} else { |
198 |
/** This filter is documented in wp-includes/option.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); |
5 | 200 |
} |
0 | 201 |
} |
202 |
||
16 | 203 |
// If home is not set, use siteurl. |
204 |
if ( 'home' === $option && '' === $value ) { |
|
0 | 205 |
return get_option( 'siteurl' ); |
9 | 206 |
} |
0 | 207 |
|
16 | 208 |
if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) { |
0 | 209 |
$value = untrailingslashit( $value ); |
9 | 210 |
} |
0 | 211 |
|
5 | 212 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
* Filters the value of an existing option. |
5 | 214 |
* |
215 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
216 |
* |
|
217 |
* @since 1.5.0 As 'option_' . $setting |
|
218 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
* @since 4.4.0 The `$option` parameter was added. |
5 | 220 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
* @param mixed $value Value of the option. If stored serialized, it will be |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
* unserialized prior to being returned. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
* @param string $option Option name. |
5 | 224 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
return apply_filters( "option_{$option}", maybe_unserialize( $value ), $option ); |
0 | 226 |
} |
227 |
||
228 |
/** |
|
16 | 229 |
* Protects WordPress special option from being modified. |
0 | 230 |
* |
231 |
* Will die if $option is in protected list. Protected options are 'alloptions' |
|
232 |
* and 'notoptions' options. |
|
233 |
* |
|
234 |
* @since 2.2.0 |
|
235 |
* |
|
236 |
* @param string $option Option name. |
|
237 |
*/ |
|
238 |
function wp_protect_special_option( $option ) { |
|
9 | 239 |
if ( 'alloptions' === $option || 'notoptions' === $option ) { |
16 | 240 |
wp_die( |
241 |
sprintf( |
|
242 |
/* translators: %s: Option name. */ |
|
243 |
__( '%s is a protected WP option and may not be modified' ), |
|
244 |
esc_html( $option ) |
|
245 |
) |
|
246 |
); |
|
9 | 247 |
} |
0 | 248 |
} |
249 |
||
250 |
/** |
|
16 | 251 |
* Prints option value after sanitizing for forms. |
0 | 252 |
* |
253 |
* @since 1.5.0 |
|
254 |
* |
|
255 |
* @param string $option Option name. |
|
256 |
*/ |
|
257 |
function form_option( $option ) { |
|
258 |
echo esc_attr( get_option( $option ) ); |
|
259 |
} |
|
260 |
||
261 |
/** |
|
262 |
* Loads and caches all autoloaded options, if available or all options. |
|
263 |
* |
|
264 |
* @since 2.2.0 |
|
16 | 265 |
* @since 5.3.1 The `$force_cache` parameter was added. |
0 | 266 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
* |
16 | 269 |
* @param bool $force_cache Optional. Whether to force an update of the local cache |
270 |
* from the persistent cache. Default false. |
|
0 | 271 |
* @return array List of all options. |
272 |
*/ |
|
16 | 273 |
function wp_load_alloptions( $force_cache = false ) { |
0 | 274 |
global $wpdb; |
275 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
if ( ! wp_installing() || ! is_multisite() ) { |
16 | 277 |
$alloptions = wp_cache_get( 'alloptions', 'options', $force_cache ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
} else { |
0 | 279 |
$alloptions = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
} |
0 | 281 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
if ( ! $alloptions ) { |
16 | 283 |
$suppress = $wpdb->suppress_errors(); |
284 |
$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload = 'yes'" ); |
|
285 |
if ( ! $alloptions_db ) { |
|
0 | 286 |
$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options" ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
$wpdb->suppress_errors( $suppress ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
|
0 | 290 |
$alloptions = array(); |
291 |
foreach ( (array) $alloptions_db as $o ) { |
|
9 | 292 |
$alloptions[ $o->option_name ] = $o->option_value; |
0 | 293 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
294 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
if ( ! wp_installing() || ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
* Filters all options before caching them. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
298 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
299 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
300 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
301 |
* @param array $alloptions Array with all options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
302 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
$alloptions = apply_filters( 'pre_cache_alloptions', $alloptions ); |
16 | 304 |
|
0 | 305 |
wp_cache_add( 'alloptions', $alloptions, 'options' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
} |
0 | 307 |
} |
308 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
* Filters all options after retrieving them. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
* @param array $alloptions Array with all options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
return apply_filters( 'alloptions', $alloptions ); |
0 | 317 |
} |
318 |
||
319 |
/** |
|
320 |
* Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used. |
|
321 |
* |
|
322 |
* @since 3.0.0 |
|
323 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
324 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
325 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
326 |
* @param int $network_id Optional site ID for which to query the options. Defaults to the current site. |
0 | 327 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
328 |
function wp_load_core_site_options( $network_id = null ) { |
0 | 329 |
global $wpdb; |
330 |
||
9 | 331 |
if ( ! is_multisite() || wp_using_ext_object_cache() || wp_installing() ) { |
0 | 332 |
return; |
9 | 333 |
} |
0 | 334 |
|
9 | 335 |
if ( empty( $network_id ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
336 |
$network_id = get_current_network_id(); |
9 | 337 |
} |
0 | 338 |
|
9 | 339 |
$core_options = array( 'site_name', 'siteurl', 'active_sitewide_plugins', '_site_transient_timeout_theme_roots', '_site_transient_theme_roots', 'site_admins', 'can_compress_scripts', 'global_terms_enabled', 'ms_files_rewriting' ); |
340 |
||
341 |
$core_options_in = "'" . implode( "', '", $core_options ) . "'"; |
|
342 |
$options = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN ($core_options_in) AND site_id = %d", $network_id ) ); |
|
0 | 343 |
|
344 |
foreach ( $options as $option ) { |
|
9 | 345 |
$key = $option->meta_key; |
346 |
$cache_key = "{$network_id}:$key"; |
|
0 | 347 |
$option->meta_value = maybe_unserialize( $option->meta_value ); |
348 |
||
349 |
wp_cache_set( $cache_key, $option->meta_value, 'site-options' ); |
|
350 |
} |
|
351 |
} |
|
352 |
||
353 |
/** |
|
16 | 354 |
* Updates the value of an option that was already added. |
0 | 355 |
* |
16 | 356 |
* You do not need to serialize values. If the value needs to be serialized, |
357 |
* then it will be serialized before it is inserted into the database. |
|
358 |
* Remember, resources cannot be serialized or added as an option. |
|
0 | 359 |
* |
16 | 360 |
* If the option does not exist, it will be created. |
361 |
||
362 |
* This function is designed to work with or without a logged-in user. In terms of security, |
|
363 |
* plugin developers should check the current user's capabilities before updating any options. |
|
0 | 364 |
* |
365 |
* @since 1.0.0 |
|
5 | 366 |
* @since 4.2.0 The `$autoload` parameter was added. |
0 | 367 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
* |
16 | 370 |
* @param string $option Name of the option to update. Expected to not be SQL-escaped. |
5 | 371 |
* @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
372 |
* @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options, |
|
373 |
* `$autoload` can only be updated using `update_option()` if `$value` is also changed. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
374 |
* Accepts 'yes'|true to enable or 'no'|false to disable. For non-existent options, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
375 |
* the default value is 'yes'. Default null. |
16 | 376 |
* @return bool True if the value was updated, false otherwise. |
0 | 377 |
*/ |
5 | 378 |
function update_option( $option, $value, $autoload = null ) { |
0 | 379 |
global $wpdb; |
380 |
||
9 | 381 |
$option = trim( $option ); |
382 |
if ( empty( $option ) ) { |
|
0 | 383 |
return false; |
9 | 384 |
} |
0 | 385 |
|
16 | 386 |
/* |
387 |
* Until a proper _deprecated_option() function can be introduced, |
|
388 |
* redirect requests to deprecated keys to the new, correct ones. |
|
389 |
*/ |
|
390 |
$deprecated_keys = array( |
|
391 |
'blacklist_keys' => 'disallowed_keys', |
|
392 |
'comment_whitelist' => 'comment_previously_approved', |
|
393 |
); |
|
394 |
||
395 |
if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) { |
|
396 |
_deprecated_argument( |
|
397 |
__FUNCTION__, |
|
398 |
'5.5.0', |
|
399 |
sprintf( |
|
400 |
/* translators: 1: Deprecated option key, 2: New option key. */ |
|
401 |
__( 'The "%1$s" option key has been renamed to "%2$s".' ), |
|
402 |
$option, |
|
403 |
$deprecated_keys[ $option ] |
|
404 |
) |
|
405 |
); |
|
406 |
return update_option( $deprecated_keys[ $option ], $value, $autoload ); |
|
407 |
} |
|
408 |
||
0 | 409 |
wp_protect_special_option( $option ); |
410 |
||
9 | 411 |
if ( is_object( $value ) ) { |
0 | 412 |
$value = clone $value; |
9 | 413 |
} |
0 | 414 |
|
9 | 415 |
$value = sanitize_option( $option, $value ); |
0 | 416 |
$old_value = get_option( $option ); |
5 | 417 |
|
418 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
* Filters a specific option before its value is (maybe) serialized and updated. |
5 | 420 |
* |
421 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
422 |
* |
|
423 |
* @since 2.6.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
424 |
* @since 4.4.0 The `$option` parameter was added. |
5 | 425 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
426 |
* @param mixed $value The new, unserialized option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
427 |
* @param mixed $old_value The old option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
428 |
* @param string $option Option name. |
5 | 429 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
$value = apply_filters( "pre_update_option_{$option}", $value, $old_value, $option ); |
0 | 431 |
|
5 | 432 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
* Filters an option before its value is (maybe) serialized and updated. |
5 | 434 |
* |
435 |
* @since 3.9.0 |
|
436 |
* |
|
437 |
* @param mixed $value The new, unserialized option value. |
|
438 |
* @param string $option Name of the option. |
|
439 |
* @param mixed $old_value The old option value. |
|
440 |
*/ |
|
441 |
$value = apply_filters( 'pre_update_option', $value, $option, $old_value ); |
|
442 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
443 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
444 |
* If the new and old values are the same, no need to update. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
* Unserialized values will be adequate in most cases. If the unserialized |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
447 |
* data differs, the (maybe) serialized data is checked to avoid |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
448 |
* unnecessary database calls for otherwise identical object instances. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
449 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
* See https://core.trac.wordpress.org/ticket/38903 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
451 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
0 | 453 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
} |
0 | 455 |
|
5 | 456 |
/** This filter is documented in wp-includes/option.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { |
5 | 458 |
// Default setting for new options is 'yes'. |
459 |
if ( null === $autoload ) { |
|
460 |
$autoload = 'yes'; |
|
461 |
} |
|
462 |
||
463 |
return add_option( $option, $value, '', $autoload ); |
|
464 |
} |
|
0 | 465 |
|
466 |
$serialized_value = maybe_serialize( $value ); |
|
467 |
||
5 | 468 |
/** |
469 |
* Fires immediately before an option value is updated. |
|
470 |
* |
|
471 |
* @since 2.9.0 |
|
472 |
* |
|
473 |
* @param string $option Name of the option to update. |
|
474 |
* @param mixed $old_value The old option value. |
|
475 |
* @param mixed $value The new option value. |
|
476 |
*/ |
|
0 | 477 |
do_action( 'update_option', $option, $old_value, $value ); |
5 | 478 |
|
479 |
$update_args = array( |
|
480 |
'option_value' => $serialized_value, |
|
481 |
); |
|
482 |
||
483 |
if ( null !== $autoload ) { |
|
484 |
$update_args['autoload'] = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; |
|
485 |
} |
|
486 |
||
487 |
$result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => $option ) ); |
|
9 | 488 |
if ( ! $result ) { |
0 | 489 |
return false; |
9 | 490 |
} |
0 | 491 |
|
492 |
$notoptions = wp_cache_get( 'notoptions', 'options' ); |
|
16 | 493 |
|
9 | 494 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
495 |
unset( $notoptions[ $option ] ); |
|
0 | 496 |
wp_cache_set( 'notoptions', $notoptions, 'options' ); |
497 |
} |
|
498 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
if ( ! wp_installing() ) { |
16 | 500 |
$alloptions = wp_load_alloptions( true ); |
9 | 501 |
if ( isset( $alloptions[ $option ] ) ) { |
0 | 502 |
$alloptions[ $option ] = $serialized_value; |
503 |
wp_cache_set( 'alloptions', $alloptions, 'options' ); |
|
504 |
} else { |
|
505 |
wp_cache_set( $option, $serialized_value, 'options' ); |
|
506 |
} |
|
507 |
} |
|
508 |
||
5 | 509 |
/** |
510 |
* Fires after the value of a specific option has been successfully updated. |
|
511 |
* |
|
512 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
513 |
* |
|
514 |
* @since 2.0.1 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
* @since 4.4.0 The `$option` parameter was added. |
5 | 516 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
517 |
* @param mixed $old_value The old option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
518 |
* @param mixed $value The new option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
519 |
* @param string $option Option name. |
5 | 520 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
521 |
do_action( "update_option_{$option}", $old_value, $value, $option ); |
5 | 522 |
|
523 |
/** |
|
524 |
* Fires after the value of an option has been successfully updated. |
|
525 |
* |
|
526 |
* @since 2.9.0 |
|
527 |
* |
|
528 |
* @param string $option Name of the updated option. |
|
529 |
* @param mixed $old_value The old option value. |
|
530 |
* @param mixed $value The new option value. |
|
531 |
*/ |
|
0 | 532 |
do_action( 'updated_option', $option, $old_value, $value ); |
16 | 533 |
|
0 | 534 |
return true; |
535 |
} |
|
536 |
||
537 |
/** |
|
16 | 538 |
* Adds a new option. |
0 | 539 |
* |
16 | 540 |
* You do not need to serialize values. If the value needs to be serialized, |
541 |
* then it will be serialized before it is inserted into the database. |
|
542 |
* Remember, resources cannot be serialized or added as an option. |
|
0 | 543 |
* |
544 |
* You can create options without values and then update the values later. |
|
545 |
* Existing options will not be updated and checks are performed to ensure that you |
|
546 |
* aren't adding a protected WordPress option. Care should be taken to not name |
|
547 |
* options the same as the ones which are protected. |
|
548 |
* |
|
549 |
* @since 1.0.0 |
|
550 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
551 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
552 |
* |
16 | 553 |
* @param string $option Name of the option to add. Expected to not be SQL-escaped. |
554 |
* @param mixed $value Optional. Option value. Must be serializable if non-scalar. |
|
555 |
* Expected to not be SQL-escaped. |
|
556 |
* @param string $deprecated Optional. Description. Not used anymore. |
|
557 |
* @param string|bool $autoload Optional. Whether to load the option when WordPress starts up. |
|
558 |
* Default is enabled. Accepts 'no' to disable for legacy reasons. |
|
559 |
* @return bool True if the option was added, false otherwise. |
|
0 | 560 |
*/ |
561 |
function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) { |
|
562 |
global $wpdb; |
|
563 |
||
9 | 564 |
if ( ! empty( $deprecated ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
565 |
_deprecated_argument( __FUNCTION__, '2.3.0' ); |
9 | 566 |
} |
0 | 567 |
|
9 | 568 |
$option = trim( $option ); |
569 |
if ( empty( $option ) ) { |
|
0 | 570 |
return false; |
9 | 571 |
} |
0 | 572 |
|
16 | 573 |
/* |
574 |
* Until a proper _deprecated_option() function can be introduced, |
|
575 |
* redirect requests to deprecated keys to the new, correct ones. |
|
576 |
*/ |
|
577 |
$deprecated_keys = array( |
|
578 |
'blacklist_keys' => 'disallowed_keys', |
|
579 |
'comment_whitelist' => 'comment_previously_approved', |
|
580 |
); |
|
581 |
||
582 |
if ( ! wp_installing() && isset( $deprecated_keys[ $option ] ) ) { |
|
583 |
_deprecated_argument( |
|
584 |
__FUNCTION__, |
|
585 |
'5.5.0', |
|
586 |
sprintf( |
|
587 |
/* translators: 1: Deprecated option key, 2: New option key. */ |
|
588 |
__( 'The "%1$s" option key has been renamed to "%2$s".' ), |
|
589 |
$option, |
|
590 |
$deprecated_keys[ $option ] |
|
591 |
) |
|
592 |
); |
|
593 |
return add_option( $deprecated_keys[ $option ], $value, $deprecated, $autoload ); |
|
594 |
} |
|
595 |
||
0 | 596 |
wp_protect_special_option( $option ); |
597 |
||
9 | 598 |
if ( is_object( $value ) ) { |
0 | 599 |
$value = clone $value; |
9 | 600 |
} |
0 | 601 |
|
602 |
$value = sanitize_option( $option, $value ); |
|
603 |
||
16 | 604 |
// Make sure the option doesn't already exist. |
605 |
// We can check the 'notoptions' cache before we ask for a DB query. |
|
0 | 606 |
$notoptions = wp_cache_get( 'notoptions', 'options' ); |
16 | 607 |
|
9 | 608 |
if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { |
5 | 609 |
/** This filter is documented in wp-includes/option.php */ |
9 | 610 |
if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) { |
0 | 611 |
return false; |
9 | 612 |
} |
613 |
} |
|
0 | 614 |
|
615 |
$serialized_value = maybe_serialize( $value ); |
|
9 | 616 |
$autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes'; |
5 | 617 |
|
618 |
/** |
|
619 |
* Fires before an option is added. |
|
620 |
* |
|
621 |
* @since 2.9.0 |
|
622 |
* |
|
623 |
* @param string $option Name of the option to add. |
|
624 |
* @param mixed $value Value of the option. |
|
625 |
*/ |
|
0 | 626 |
do_action( 'add_option', $option, $value ); |
627 |
||
628 |
$result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) ); |
|
9 | 629 |
if ( ! $result ) { |
0 | 630 |
return false; |
9 | 631 |
} |
0 | 632 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
if ( ! wp_installing() ) { |
16 | 634 |
if ( 'yes' === $autoload ) { |
635 |
$alloptions = wp_load_alloptions( true ); |
|
0 | 636 |
$alloptions[ $option ] = $serialized_value; |
637 |
wp_cache_set( 'alloptions', $alloptions, 'options' ); |
|
638 |
} else { |
|
639 |
wp_cache_set( $option, $serialized_value, 'options' ); |
|
640 |
} |
|
641 |
} |
|
642 |
||
16 | 643 |
// This option exists now. |
644 |
$notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh. |
|
645 |
||
9 | 646 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
647 |
unset( $notoptions[ $option ] ); |
|
0 | 648 |
wp_cache_set( 'notoptions', $notoptions, 'options' ); |
649 |
} |
|
650 |
||
5 | 651 |
/** |
652 |
* Fires after a specific option has been added. |
|
653 |
* |
|
654 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
655 |
* |
|
656 |
* @since 2.5.0 As "add_option_{$name}" |
|
657 |
* @since 3.0.0 |
|
658 |
* |
|
659 |
* @param string $option Name of the option to add. |
|
660 |
* @param mixed $value Value of the option. |
|
661 |
*/ |
|
0 | 662 |
do_action( "add_option_{$option}", $option, $value ); |
5 | 663 |
|
664 |
/** |
|
665 |
* Fires after an option has been added. |
|
666 |
* |
|
667 |
* @since 2.9.0 |
|
668 |
* |
|
669 |
* @param string $option Name of the added option. |
|
670 |
* @param mixed $value Value of the option. |
|
671 |
*/ |
|
0 | 672 |
do_action( 'added_option', $option, $value ); |
16 | 673 |
|
0 | 674 |
return true; |
675 |
} |
|
676 |
||
677 |
/** |
|
678 |
* Removes option by name. Prevents removal of protected WordPress options. |
|
679 |
* |
|
680 |
* @since 1.2.0 |
|
681 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
683 |
* |
16 | 684 |
* @param string $option Name of the option to delete. Expected to not be SQL-escaped. |
685 |
* @return bool True if the option was deleted, false otherwise. |
|
0 | 686 |
*/ |
687 |
function delete_option( $option ) { |
|
688 |
global $wpdb; |
|
689 |
||
690 |
$option = trim( $option ); |
|
9 | 691 |
if ( empty( $option ) ) { |
0 | 692 |
return false; |
9 | 693 |
} |
0 | 694 |
|
695 |
wp_protect_special_option( $option ); |
|
696 |
||
16 | 697 |
// Get the ID, if no ID then return. |
0 | 698 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ); |
9 | 699 |
if ( is_null( $row ) ) { |
0 | 700 |
return false; |
9 | 701 |
} |
5 | 702 |
|
703 |
/** |
|
704 |
* Fires immediately before an option is deleted. |
|
705 |
* |
|
706 |
* @since 2.9.0 |
|
707 |
* |
|
708 |
* @param string $option Name of the option to delete. |
|
709 |
*/ |
|
0 | 710 |
do_action( 'delete_option', $option ); |
5 | 711 |
|
0 | 712 |
$result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) ); |
16 | 713 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
if ( ! wp_installing() ) { |
16 | 715 |
if ( 'yes' === $row->autoload ) { |
716 |
$alloptions = wp_load_alloptions( true ); |
|
9 | 717 |
if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) { |
718 |
unset( $alloptions[ $option ] ); |
|
0 | 719 |
wp_cache_set( 'alloptions', $alloptions, 'options' ); |
720 |
} |
|
721 |
} else { |
|
722 |
wp_cache_delete( $option, 'options' ); |
|
723 |
} |
|
724 |
} |
|
16 | 725 |
|
0 | 726 |
if ( $result ) { |
5 | 727 |
|
728 |
/** |
|
729 |
* Fires after a specific option has been deleted. |
|
730 |
* |
|
731 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
732 |
* |
|
733 |
* @since 3.0.0 |
|
734 |
* |
|
735 |
* @param string $option Name of the deleted option. |
|
736 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
737 |
do_action( "delete_option_{$option}", $option ); |
5 | 738 |
|
739 |
/** |
|
740 |
* Fires after an option has been deleted. |
|
741 |
* |
|
742 |
* @since 2.9.0 |
|
743 |
* |
|
744 |
* @param string $option Name of the deleted option. |
|
745 |
*/ |
|
0 | 746 |
do_action( 'deleted_option', $option ); |
16 | 747 |
|
0 | 748 |
return true; |
749 |
} |
|
16 | 750 |
|
0 | 751 |
return false; |
752 |
} |
|
753 |
||
754 |
/** |
|
16 | 755 |
* Deletes a transient. |
0 | 756 |
* |
757 |
* @since 2.8.0 |
|
758 |
* |
|
759 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
|
16 | 760 |
* @return bool True if the transient was deleted, false otherwise. |
0 | 761 |
*/ |
762 |
function delete_transient( $transient ) { |
|
5 | 763 |
|
764 |
/** |
|
765 |
* Fires immediately before a specific transient is deleted. |
|
766 |
* |
|
767 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
768 |
* |
|
769 |
* @since 3.0.0 |
|
770 |
* |
|
771 |
* @param string $transient Transient name. |
|
772 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
773 |
do_action( "delete_transient_{$transient}", $transient ); |
0 | 774 |
|
775 |
if ( wp_using_ext_object_cache() ) { |
|
776 |
$result = wp_cache_delete( $transient, 'transient' ); |
|
777 |
} else { |
|
778 |
$option_timeout = '_transient_timeout_' . $transient; |
|
9 | 779 |
$option = '_transient_' . $transient; |
780 |
$result = delete_option( $option ); |
|
16 | 781 |
|
9 | 782 |
if ( $result ) { |
0 | 783 |
delete_option( $option_timeout ); |
9 | 784 |
} |
0 | 785 |
} |
786 |
||
5 | 787 |
if ( $result ) { |
788 |
||
789 |
/** |
|
790 |
* Fires after a transient is deleted. |
|
791 |
* |
|
792 |
* @since 3.0.0 |
|
793 |
* |
|
794 |
* @param string $transient Deleted transient name. |
|
795 |
*/ |
|
0 | 796 |
do_action( 'deleted_transient', $transient ); |
5 | 797 |
} |
798 |
||
0 | 799 |
return $result; |
800 |
} |
|
801 |
||
802 |
/** |
|
16 | 803 |
* Retrieves the value of a transient. |
0 | 804 |
* |
5 | 805 |
* If the transient does not exist, does not have a value, or has expired, |
806 |
* then the return value will be false. |
|
0 | 807 |
* |
808 |
* @since 2.8.0 |
|
809 |
* |
|
5 | 810 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
811 |
* @return mixed Value of transient. |
|
0 | 812 |
*/ |
813 |
function get_transient( $transient ) { |
|
5 | 814 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
/** |
16 | 816 |
* Filters the value of an existing transient before it is retrieved. |
5 | 817 |
* |
818 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
819 |
* |
|
16 | 820 |
* Returning a truthy value from the filter will effectively short-circuit retrieval |
821 |
* and return the passed value instead. |
|
5 | 822 |
* |
823 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
824 |
* @since 4.4.0 The `$transient` parameter was added |
5 | 825 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
826 |
* @param mixed $pre_transient The default value to return if the transient does not exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
827 |
* Any value other than false will short-circuit the retrieval |
16 | 828 |
* of the transient, and return that value. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
829 |
* @param string $transient Transient name. |
5 | 830 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
$pre = apply_filters( "pre_transient_{$transient}", false, $transient ); |
16 | 832 |
|
9 | 833 |
if ( false !== $pre ) { |
0 | 834 |
return $pre; |
9 | 835 |
} |
0 | 836 |
|
837 |
if ( wp_using_ext_object_cache() ) { |
|
838 |
$value = wp_cache_get( $transient, 'transient' ); |
|
839 |
} else { |
|
840 |
$transient_option = '_transient_' . $transient; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
841 |
if ( ! wp_installing() ) { |
16 | 842 |
// If option is not in alloptions, it is not autoloaded and thus has a timeout. |
0 | 843 |
$alloptions = wp_load_alloptions(); |
9 | 844 |
if ( ! isset( $alloptions[ $transient_option ] ) ) { |
0 | 845 |
$transient_timeout = '_transient_timeout_' . $transient; |
9 | 846 |
$timeout = get_option( $transient_timeout ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
847 |
if ( false !== $timeout && $timeout < time() ) { |
9 | 848 |
delete_option( $transient_option ); |
0 | 849 |
delete_option( $transient_timeout ); |
850 |
$value = false; |
|
851 |
} |
|
852 |
} |
|
853 |
} |
|
854 |
||
9 | 855 |
if ( ! isset( $value ) ) { |
0 | 856 |
$value = get_option( $transient_option ); |
9 | 857 |
} |
0 | 858 |
} |
859 |
||
5 | 860 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
* Filters an existing transient's value. |
5 | 862 |
* |
863 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
864 |
* |
|
865 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
* @since 4.4.0 The `$transient` parameter was added |
5 | 867 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
868 |
* @param mixed $value Value of transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
* @param string $transient Transient name. |
5 | 870 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
return apply_filters( "transient_{$transient}", $value, $transient ); |
0 | 872 |
} |
873 |
||
874 |
/** |
|
16 | 875 |
* Sets/updates the value of a transient. |
0 | 876 |
* |
16 | 877 |
* You do not need to serialize values. If the value needs to be serialized, |
878 |
* then it will be serialized before it is set. |
|
0 | 879 |
* |
880 |
* @since 2.8.0 |
|
881 |
* |
|
16 | 882 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
883 |
* Must be 172 characters or fewer in length. |
|
5 | 884 |
* @param mixed $value Transient value. Must be serializable if non-scalar. |
885 |
* Expected to not be SQL-escaped. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
* @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration). |
16 | 887 |
* @return bool True if the value was set, false otherwise. |
0 | 888 |
*/ |
889 |
function set_transient( $transient, $value, $expiration = 0 ) { |
|
5 | 890 |
|
0 | 891 |
$expiration = (int) $expiration; |
892 |
||
5 | 893 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
* Filters a specific transient before its value is set. |
5 | 895 |
* |
896 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
897 |
* |
|
898 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
899 |
* @since 4.2.0 The `$expiration` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 901 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
* @param mixed $value New value of transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
* @param int $expiration Time until expiration in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
904 |
* @param string $transient Transient name. |
5 | 905 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
$value = apply_filters( "pre_set_transient_{$transient}", $value, $expiration, $transient ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
* Filters the expiration for a transient before its value is set. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
913 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
* @param int $expiration Time until expiration in seconds. Use 0 for no expiration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
* @param mixed $value New value of transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
917 |
* @param string $transient Transient name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
918 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
919 |
$expiration = apply_filters( "expiration_of_transient_{$transient}", $expiration, $value, $transient ); |
5 | 920 |
|
0 | 921 |
if ( wp_using_ext_object_cache() ) { |
922 |
$result = wp_cache_set( $transient, $value, 'transient', $expiration ); |
|
923 |
} else { |
|
924 |
$transient_timeout = '_transient_timeout_' . $transient; |
|
9 | 925 |
$transient_option = '_transient_' . $transient; |
16 | 926 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
if ( false === get_option( $transient_option ) ) { |
0 | 928 |
$autoload = 'yes'; |
929 |
if ( $expiration ) { |
|
930 |
$autoload = 'no'; |
|
931 |
add_option( $transient_timeout, time() + $expiration, '', 'no' ); |
|
932 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
933 |
$result = add_option( $transient_option, $value, '', $autoload ); |
0 | 934 |
} else { |
5 | 935 |
// If expiration is requested, but the transient has no timeout option, |
936 |
// delete, then re-create transient rather than update. |
|
937 |
$update = true; |
|
16 | 938 |
|
5 | 939 |
if ( $expiration ) { |
940 |
if ( false === get_option( $transient_timeout ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
delete_option( $transient_option ); |
5 | 942 |
add_option( $transient_timeout, time() + $expiration, '', 'no' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
943 |
$result = add_option( $transient_option, $value, '', 'no' ); |
5 | 944 |
$update = false; |
945 |
} else { |
|
946 |
update_option( $transient_timeout, time() + $expiration ); |
|
947 |
} |
|
948 |
} |
|
16 | 949 |
|
5 | 950 |
if ( $update ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
$result = update_option( $transient_option, $value ); |
5 | 952 |
} |
0 | 953 |
} |
954 |
} |
|
5 | 955 |
|
0 | 956 |
if ( $result ) { |
5 | 957 |
|
958 |
/** |
|
959 |
* Fires after the value for a specific transient has been set. |
|
960 |
* |
|
961 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
962 |
* |
|
963 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
* @since 3.6.0 The `$value` and `$expiration` parameters were added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 966 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
* @param mixed $value Transient value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
* @param int $expiration Time until expiration in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
* @param string $transient The name of the transient. |
5 | 970 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
do_action( "set_transient_{$transient}", $value, $expiration, $transient ); |
5 | 972 |
|
973 |
/** |
|
974 |
* Fires after the value for a transient has been set. |
|
975 |
* |
|
976 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
* @since 3.6.0 The `$value` and `$expiration` parameters were added. |
5 | 978 |
* |
979 |
* @param string $transient The name of the transient. |
|
980 |
* @param mixed $value Transient value. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
* @param int $expiration Time until expiration in seconds. |
5 | 982 |
*/ |
0 | 983 |
do_action( 'setted_transient', $transient, $value, $expiration ); |
984 |
} |
|
16 | 985 |
|
0 | 986 |
return $result; |
987 |
} |
|
988 |
||
989 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
* Deletes all expired transients. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
* The multi-table delete syntax is used to delete the transient record |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
* from table a, and the corresponding transient_timeout record from table b. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
994 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
* @param bool $force_db Optional. Force cleanup to run against the database even when an external object cache is used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
function delete_expired_transients( $force_db = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
if ( ! $force_db && wp_using_ext_object_cache() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
|
9 | 1006 |
$wpdb->query( |
1007 |
$wpdb->prepare( |
|
1008 |
"DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
WHERE a.option_name LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1010 |
AND a.option_name NOT LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1012 |
AND b.option_value < %d", |
9 | 1013 |
$wpdb->esc_like( '_transient_' ) . '%', |
1014 |
$wpdb->esc_like( '_transient_timeout_' ) . '%', |
|
1015 |
time() |
|
1016 |
) |
|
1017 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1018 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
if ( ! is_multisite() ) { |
16 | 1020 |
// Single site stores site transients in the options table. |
9 | 1021 |
$wpdb->query( |
1022 |
$wpdb->prepare( |
|
1023 |
"DELETE a, b FROM {$wpdb->options} a, {$wpdb->options} b |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
WHERE a.option_name LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1025 |
AND a.option_name NOT LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
AND b.option_value < %d", |
9 | 1028 |
$wpdb->esc_like( '_site_transient_' ) . '%', |
1029 |
$wpdb->esc_like( '_site_transient_timeout_' ) . '%', |
|
1030 |
time() |
|
1031 |
) |
|
1032 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1033 |
} elseif ( is_multisite() && is_main_site() && is_main_network() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1034 |
// Multisite stores site transients in the sitemeta table. |
9 | 1035 |
$wpdb->query( |
1036 |
$wpdb->prepare( |
|
1037 |
"DELETE a, b FROM {$wpdb->sitemeta} a, {$wpdb->sitemeta} b |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
WHERE a.meta_key LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
AND a.meta_key NOT LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
AND b.meta_value < %d", |
9 | 1042 |
$wpdb->esc_like( '_site_transient_' ) . '%', |
1043 |
$wpdb->esc_like( '_site_transient_timeout_' ) . '%', |
|
1044 |
time() |
|
1045 |
) |
|
1046 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
/** |
0 | 1051 |
* Saves and restores user interface settings stored in a cookie. |
1052 |
* |
|
1053 |
* Checks if the current user-settings cookie is updated and stores it. When no |
|
1054 |
* cookie exists (different browser used), adds the last saved cookie restoring |
|
1055 |
* the settings. |
|
1056 |
* |
|
1057 |
* @since 2.7.0 |
|
1058 |
*/ |
|
1059 |
function wp_user_settings() { |
|
1060 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
if ( ! is_admin() || wp_doing_ajax() ) { |
0 | 1062 |
return; |
5 | 1063 |
} |
0 | 1064 |
|
16 | 1065 |
$user_id = get_current_user_id(); |
1066 |
if ( ! $user_id ) { |
|
0 | 1067 |
return; |
5 | 1068 |
} |
0 | 1069 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
if ( ! is_user_member_of_blog() ) { |
0 | 1071 |
return; |
5 | 1072 |
} |
0 | 1073 |
|
1074 |
$settings = (string) get_user_option( 'user-settings', $user_id ); |
|
1075 |
||
9 | 1076 |
if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) { |
1077 |
$cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] ); |
|
0 | 1078 |
|
16 | 1079 |
// No change or both empty. |
9 | 1080 |
if ( $cookie == $settings ) { |
0 | 1081 |
return; |
9 | 1082 |
} |
0 | 1083 |
|
1084 |
$last_saved = (int) get_user_option( 'user-settings-time', $user_id ); |
|
9 | 1085 |
$current = isset( $_COOKIE[ 'wp-settings-time-' . $user_id ] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE[ 'wp-settings-time-' . $user_id ] ) : 0; |
0 | 1086 |
|
16 | 1087 |
// The cookie is newer than the saved value. Update the user_option and leave the cookie as-is. |
0 | 1088 |
if ( $current > $last_saved ) { |
1089 |
update_user_option( $user_id, 'user-settings', $cookie, false ); |
|
1090 |
update_user_option( $user_id, 'user-settings-time', time() - 5, false ); |
|
1091 |
return; |
|
1092 |
} |
|
1093 |
} |
|
1094 |
||
1095 |
// The cookie is not set in the current browser or the saved value is newer. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1096 |
$secure = ( 'https' === parse_url( admin_url(), PHP_URL_SCHEME ) ); |
5 | 1097 |
setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure ); |
1098 |
setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure ); |
|
9 | 1099 |
$_COOKIE[ 'wp-settings-' . $user_id ] = $settings; |
0 | 1100 |
} |
1101 |
||
1102 |
/** |
|
16 | 1103 |
* Retrieves user interface setting value based on setting name. |
0 | 1104 |
* |
1105 |
* @since 2.7.0 |
|
1106 |
* |
|
18 | 1107 |
* @param string $name The name of the setting. |
1108 |
* @param string|false $default Optional. Default value to return when $name is not set. Default false. |
|
16 | 1109 |
* @return mixed The last saved user setting or the default value/false if it doesn't exist. |
0 | 1110 |
*/ |
1111 |
function get_user_setting( $name, $default = false ) { |
|
1112 |
$all_user_settings = get_all_user_settings(); |
|
1113 |
||
9 | 1114 |
return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default; |
0 | 1115 |
} |
1116 |
||
1117 |
/** |
|
16 | 1118 |
* Adds or updates user interface setting. |
0 | 1119 |
* |
16 | 1120 |
* Both $name and $value can contain only ASCII letters, numbers, hyphens, and underscores. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
* |
0 | 1122 |
* This function has to be used before any output has started as it calls setcookie(). |
1123 |
* |
|
1124 |
* @since 2.8.0 |
|
1125 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1126 |
* @param string $name The name of the setting. |
0 | 1127 |
* @param string $value The value for the setting. |
16 | 1128 |
* @return bool|null True if set successfully, false otherwise. |
1129 |
* Null if the current user is not a member of the site. |
|
0 | 1130 |
*/ |
1131 |
function set_user_setting( $name, $value ) { |
|
5 | 1132 |
if ( headers_sent() ) { |
0 | 1133 |
return false; |
5 | 1134 |
} |
0 | 1135 |
|
9 | 1136 |
$all_user_settings = get_all_user_settings(); |
1137 |
$all_user_settings[ $name ] = $value; |
|
0 | 1138 |
|
1139 |
return wp_set_all_user_settings( $all_user_settings ); |
|
1140 |
} |
|
1141 |
||
1142 |
/** |
|
16 | 1143 |
* Deletes user interface settings. |
0 | 1144 |
* |
1145 |
* Deleting settings would reset them to the defaults. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
* |
0 | 1147 |
* This function has to be used before any output has started as it calls setcookie(). |
1148 |
* |
|
1149 |
* @since 2.7.0 |
|
1150 |
* |
|
5 | 1151 |
* @param string $names The name or array of names of the setting to be deleted. |
16 | 1152 |
* @return bool|null True if deleted successfully, false otherwise. |
1153 |
* Null if the current user is not a member of the site. |
|
0 | 1154 |
*/ |
1155 |
function delete_user_setting( $names ) { |
|
5 | 1156 |
if ( headers_sent() ) { |
0 | 1157 |
return false; |
5 | 1158 |
} |
0 | 1159 |
|
1160 |
$all_user_settings = get_all_user_settings(); |
|
9 | 1161 |
$names = (array) $names; |
1162 |
$deleted = false; |
|
0 | 1163 |
|
1164 |
foreach ( $names as $name ) { |
|
9 | 1165 |
if ( isset( $all_user_settings[ $name ] ) ) { |
1166 |
unset( $all_user_settings[ $name ] ); |
|
0 | 1167 |
$deleted = true; |
1168 |
} |
|
1169 |
} |
|
1170 |
||
5 | 1171 |
if ( $deleted ) { |
0 | 1172 |
return wp_set_all_user_settings( $all_user_settings ); |
5 | 1173 |
} |
0 | 1174 |
|
1175 |
return false; |
|
1176 |
} |
|
1177 |
||
1178 |
/** |
|
16 | 1179 |
* Retrieves all user interface settings. |
0 | 1180 |
* |
1181 |
* @since 2.7.0 |
|
1182 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1183 |
* @global array $_updated_user_settings |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1184 |
* |
16 | 1185 |
* @return array The last saved user settings or empty array. |
0 | 1186 |
*/ |
1187 |
function get_all_user_settings() { |
|
1188 |
global $_updated_user_settings; |
|
1189 |
||
16 | 1190 |
$user_id = get_current_user_id(); |
1191 |
if ( ! $user_id ) { |
|
0 | 1192 |
return array(); |
5 | 1193 |
} |
0 | 1194 |
|
5 | 1195 |
if ( isset( $_updated_user_settings ) && is_array( $_updated_user_settings ) ) { |
0 | 1196 |
return $_updated_user_settings; |
5 | 1197 |
} |
0 | 1198 |
|
1199 |
$user_settings = array(); |
|
5 | 1200 |
|
9 | 1201 |
if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) { |
1202 |
$cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] ); |
|
0 | 1203 |
|
16 | 1204 |
if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char. |
0 | 1205 |
parse_str( $cookie, $user_settings ); |
5 | 1206 |
} |
0 | 1207 |
} else { |
1208 |
$option = get_user_option( 'user-settings', $user_id ); |
|
5 | 1209 |
|
1210 |
if ( $option && is_string( $option ) ) { |
|
0 | 1211 |
parse_str( $option, $user_settings ); |
5 | 1212 |
} |
0 | 1213 |
} |
1214 |
||
1215 |
$_updated_user_settings = $user_settings; |
|
1216 |
return $user_settings; |
|
1217 |
} |
|
1218 |
||
1219 |
/** |
|
16 | 1220 |
* Private. Sets all user interface settings. |
0 | 1221 |
* |
1222 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1223 |
* @access private |
0 | 1224 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1225 |
* @global array $_updated_user_settings |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1226 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1227 |
* @param array $user_settings User settings. |
16 | 1228 |
* @return bool|null True if set successfully, false if the current user could not be found. |
1229 |
* Null if the current user is not a member of the site. |
|
0 | 1230 |
*/ |
1231 |
function wp_set_all_user_settings( $user_settings ) { |
|
1232 |
global $_updated_user_settings; |
|
1233 |
||
16 | 1234 |
$user_id = get_current_user_id(); |
1235 |
if ( ! $user_id ) { |
|
0 | 1236 |
return false; |
5 | 1237 |
} |
0 | 1238 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1239 |
if ( ! is_user_member_of_blog() ) { |
0 | 1240 |
return; |
5 | 1241 |
} |
0 | 1242 |
|
1243 |
$settings = ''; |
|
1244 |
foreach ( $user_settings as $name => $value ) { |
|
9 | 1245 |
$_name = preg_replace( '/[^A-Za-z0-9_-]+/', '', $name ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1246 |
$_value = preg_replace( '/[^A-Za-z0-9_-]+/', '', $value ); |
0 | 1247 |
|
5 | 1248 |
if ( ! empty( $_name ) ) { |
0 | 1249 |
$settings .= $_name . '=' . $_value . '&'; |
5 | 1250 |
} |
0 | 1251 |
} |
1252 |
||
5 | 1253 |
$settings = rtrim( $settings, '&' ); |
0 | 1254 |
parse_str( $settings, $_updated_user_settings ); |
1255 |
||
1256 |
update_user_option( $user_id, 'user-settings', $settings, false ); |
|
1257 |
update_user_option( $user_id, 'user-settings-time', time(), false ); |
|
1258 |
||
1259 |
return true; |
|
1260 |
} |
|
1261 |
||
1262 |
/** |
|
16 | 1263 |
* Deletes the user settings of the current user. |
0 | 1264 |
* |
1265 |
* @since 2.7.0 |
|
1266 |
*/ |
|
1267 |
function delete_all_user_settings() { |
|
16 | 1268 |
$user_id = get_current_user_id(); |
1269 |
if ( ! $user_id ) { |
|
0 | 1270 |
return; |
5 | 1271 |
} |
0 | 1272 |
|
1273 |
update_user_option( $user_id, 'user-settings', '', false ); |
|
5 | 1274 |
setcookie( 'wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH ); |
0 | 1275 |
} |
1276 |
||
1277 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1278 |
* Retrieve an option value for the current network based on name of option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1279 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1280 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1281 |
* @since 4.4.0 The `$use_cache` parameter was deprecated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1282 |
* @since 4.4.0 Modified into wrapper for get_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1283 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1284 |
* @see get_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1285 |
* |
16 | 1286 |
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped. |
1287 |
* @param mixed $default Optional. Value to return if the option doesn't exist. Default false. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1288 |
* @param bool $deprecated Whether to use cache. Multisite only. Always set to true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1289 |
* @return mixed Value set for the option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1290 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1291 |
function get_site_option( $option, $default = false, $deprecated = true ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1292 |
return get_network_option( null, $option, $default ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1293 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1294 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1295 |
/** |
16 | 1296 |
* Adds a new option for the current network. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1297 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1298 |
* Existing options will not be updated. Note that prior to 3.3 this wasn't the case. |
0 | 1299 |
* |
1300 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1301 |
* @since 4.4.0 Modified into wrapper for add_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1302 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1303 |
* @see add_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1304 |
* |
16 | 1305 |
* @param string $option Name of the option to add. Expected to not be SQL-escaped. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1306 |
* @param mixed $value Option value, can be anything. Expected to not be SQL-escaped. |
16 | 1307 |
* @return bool True if the option was added, false otherwise. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1308 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1309 |
function add_site_option( $option, $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1310 |
return add_network_option( null, $option, $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1311 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1312 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1313 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1314 |
* Removes a option by name for the current network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1315 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1316 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1317 |
* @since 4.4.0 Modified into wrapper for delete_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1318 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1319 |
* @see delete_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1320 |
* |
16 | 1321 |
* @param string $option Name of the option to delete. Expected to not be SQL-escaped. |
1322 |
* @return bool True if the option was deleted, false otherwise. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1323 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1324 |
function delete_site_option( $option ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1325 |
return delete_network_option( null, $option ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1326 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1327 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1328 |
/** |
16 | 1329 |
* Updates the value of an option that was already added for the current network. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1330 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1331 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1332 |
* @since 4.4.0 Modified into wrapper for update_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1333 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1334 |
* @see update_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1335 |
* |
16 | 1336 |
* @param string $option Name of the option. Expected to not be SQL-escaped. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1337 |
* @param mixed $value Option value. Expected to not be SQL-escaped. |
16 | 1338 |
* @return bool True if the value was updated, false otherwise. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1339 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1340 |
function update_site_option( $option, $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1341 |
return update_network_option( null, $option, $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1342 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1343 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1344 |
/** |
16 | 1345 |
* Retrieves a network's option value based on the option name. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1346 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1347 |
* @since 4.4.0 |
0 | 1348 |
* |
5 | 1349 |
* @see get_option() |
0 | 1350 |
* |
9 | 1351 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1352 |
* |
16 | 1353 |
* @param int $network_id ID of the network. Can be null to default to the current network ID. |
1354 |
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped. |
|
1355 |
* @param mixed $default Optional. Value to return if the option doesn't exist. Default false. |
|
0 | 1356 |
* @return mixed Value set for the option. |
1357 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1358 |
function get_network_option( $network_id, $option, $default = false ) { |
0 | 1359 |
global $wpdb; |
1360 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1361 |
if ( $network_id && ! is_numeric( $network_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1362 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1363 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1364 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1365 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1366 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1367 |
// Fallback to the current network if a network ID is not specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1368 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1369 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1370 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1371 |
|
5 | 1372 |
/** |
16 | 1373 |
* Filters the value of an existing network option before it is retrieved. |
5 | 1374 |
* |
1375 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1376 |
* |
|
16 | 1377 |
* Returning a truthy value from the filter will effectively short-circuit retrieval |
1378 |
* and return the passed value instead. |
|
5 | 1379 |
* |
1380 |
* @since 2.9.0 As 'pre_site_option_' . $key |
|
1381 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1382 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1383 |
* @since 4.7.0 The `$network_id` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1384 |
* @since 4.9.0 The `$default` parameter was added. |
5 | 1385 |
* |
16 | 1386 |
* @param mixed $pre_option The value to return instead of the option value. This differs |
1387 |
* from `$default`, which is used as the fallback value in the event |
|
1388 |
* the option doesn't exist elsewhere in get_network_option(). |
|
1389 |
* Default false (to skip past the short-circuit). |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1390 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1391 |
* @param int $network_id ID of the network. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1392 |
* @param mixed $default The fallback value to return if the option does not exist. |
16 | 1393 |
* Default false. |
5 | 1394 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1395 |
$pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default ); |
5 | 1396 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1397 |
if ( false !== $pre ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1398 |
return $pre; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1399 |
} |
0 | 1400 |
|
16 | 1401 |
// Prevent non-existent options from triggering multiple queries. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1402 |
$notoptions_key = "$network_id:notoptions"; |
9 | 1403 |
$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); |
5 | 1404 |
|
9 | 1405 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
5 | 1406 |
|
1407 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1408 |
* Filters a specific default network option. |
5 | 1409 |
* |
1410 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1411 |
* |
|
1412 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1413 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1414 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1415 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1416 |
* @param mixed $default The value to return if the site option does not exist |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
* in the database. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1418 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1419 |
* @param int $network_id ID of the network. |
5 | 1420 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1421 |
return apply_filters( "default_site_option_{$option}", $default, $option, $network_id ); |
5 | 1422 |
} |
0 | 1423 |
|
1424 |
if ( ! is_multisite() ) { |
|
5 | 1425 |
/** This filter is documented in wp-includes/option.php */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1426 |
$default = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); |
9 | 1427 |
$value = get_option( $option, $default ); |
0 | 1428 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1429 |
$cache_key = "$network_id:$option"; |
9 | 1430 |
$value = wp_cache_get( $cache_key, 'site-options' ); |
0 | 1431 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1432 |
if ( ! isset( $value ) || false === $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1433 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); |
0 | 1434 |
|
16 | 1435 |
// Has to be get_row() instead of get_var() because of funkiness with 0, false, null values. |
0 | 1436 |
if ( is_object( $row ) ) { |
1437 |
$value = $row->meta_value; |
|
1438 |
$value = maybe_unserialize( $value ); |
|
1439 |
wp_cache_set( $cache_key, $value, 'site-options' ); |
|
1440 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1441 |
if ( ! is_array( $notoptions ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1442 |
$notoptions = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1443 |
} |
16 | 1444 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1445 |
$notoptions[ $option ] = true; |
5 | 1446 |
wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); |
1447 |
||
1448 |
/** This filter is documented in wp-includes/option.php */ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
$value = apply_filters( 'default_site_option_' . $option, $default, $option, $network_id ); |
0 | 1450 |
} |
1451 |
} |
|
1452 |
} |
|
1453 |
||
9 | 1454 |
if ( ! is_array( $notoptions ) ) { |
1455 |
$notoptions = array(); |
|
1456 |
wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); |
|
1457 |
} |
|
1458 |
||
5 | 1459 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1460 |
* Filters the value of an existing network option. |
5 | 1461 |
* |
1462 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1463 |
* |
|
1464 |
* @since 2.9.0 As 'site_option_' . $key |
|
1465 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1466 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1467 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1468 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1469 |
* @param mixed $value Value of network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1470 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1471 |
* @param int $network_id ID of the network. |
5 | 1472 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1473 |
return apply_filters( "site_option_{$option}", $value, $option, $network_id ); |
0 | 1474 |
} |
1475 |
||
1476 |
/** |
|
16 | 1477 |
* Adds a new network option. |
0 | 1478 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1479 |
* Existing options will not be updated. |
0 | 1480 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1481 |
* @since 4.4.0 |
0 | 1482 |
* |
5 | 1483 |
* @see add_option() |
0 | 1484 |
* |
9 | 1485 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1486 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
* @param int $network_id ID of the network. Can be null to default to the current network ID. |
16 | 1488 |
* @param string $option Name of the option to add. Expected to not be SQL-escaped. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1489 |
* @param mixed $value Option value, can be anything. Expected to not be SQL-escaped. |
16 | 1490 |
* @return bool True if the option was added, false otherwise. |
0 | 1491 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
function add_network_option( $network_id, $option, $value ) { |
0 | 1493 |
global $wpdb; |
1494 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1495 |
if ( $network_id && ! is_numeric( $network_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1496 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1497 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1498 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1500 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
// Fallback to the current network if a network ID is not specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1502 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1503 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1504 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1505 |
|
0 | 1506 |
wp_protect_special_option( $option ); |
1507 |
||
5 | 1508 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1509 |
* Filters the value of a specific network option before it is added. |
5 | 1510 |
* |
1511 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1512 |
* |
|
1513 |
* @since 2.9.0 As 'pre_add_site_option_' . $key |
|
1514 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1515 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1517 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1518 |
* @param mixed $value Value of network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1519 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1520 |
* @param int $network_id ID of the network. |
5 | 1521 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
$value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id ); |
0 | 1523 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1524 |
$notoptions_key = "$network_id:notoptions"; |
5 | 1525 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1526 |
if ( ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1527 |
$result = add_option( $option, $value, '', 'no' ); |
0 | 1528 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1529 |
$cache_key = "$network_id:$option"; |
0 | 1530 |
|
16 | 1531 |
// Make sure the option doesn't already exist. |
1532 |
// We can check the 'notoptions' cache before we ask for a DB query. |
|
5 | 1533 |
$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); |
16 | 1534 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1535 |
if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1536 |
if ( false !== get_network_option( $network_id, $option, false ) ) { |
0 | 1537 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1538 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1539 |
} |
0 | 1540 |
|
1541 |
$value = sanitize_option( $option, $value ); |
|
1542 |
||
1543 |
$serialized_value = maybe_serialize( $value ); |
|
9 | 1544 |
$result = $wpdb->insert( |
1545 |
$wpdb->sitemeta, |
|
1546 |
array( |
|
1547 |
'site_id' => $network_id, |
|
1548 |
'meta_key' => $option, |
|
1549 |
'meta_value' => $serialized_value, |
|
1550 |
) |
|
1551 |
); |
|
0 | 1552 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1553 |
if ( ! $result ) { |
0 | 1554 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1555 |
} |
0 | 1556 |
|
1557 |
wp_cache_set( $cache_key, $value, 'site-options' ); |
|
1558 |
||
16 | 1559 |
// This option exists now. |
1560 |
$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // Yes, again... we need it to be fresh. |
|
1561 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1562 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1563 |
unset( $notoptions[ $option ] ); |
5 | 1564 |
wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); |
0 | 1565 |
} |
1566 |
} |
|
1567 |
||
1568 |
if ( $result ) { |
|
5 | 1569 |
|
1570 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1571 |
* Fires after a specific network option has been successfully added. |
5 | 1572 |
* |
1573 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1574 |
* |
|
1575 |
* @since 2.9.0 As "add_site_option_{$key}" |
|
1576 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1577 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1578 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1579 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1580 |
* @param mixed $value Value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
* @param int $network_id ID of the network. |
5 | 1582 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1583 |
do_action( "add_site_option_{$option}", $option, $value, $network_id ); |
5 | 1584 |
|
1585 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1586 |
* Fires after a network option has been successfully added. |
5 | 1587 |
* |
1588 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1589 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1590 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1592 |
* @param mixed $value Value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1593 |
* @param int $network_id ID of the network. |
5 | 1594 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
do_action( 'add_site_option', $option, $value, $network_id ); |
5 | 1596 |
|
0 | 1597 |
return true; |
1598 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1599 |
|
0 | 1600 |
return false; |
1601 |
} |
|
1602 |
||
1603 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1604 |
* Removes a network option by name. |
0 | 1605 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1606 |
* @since 4.4.0 |
0 | 1607 |
* |
5 | 1608 |
* @see delete_option() |
0 | 1609 |
* |
9 | 1610 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1611 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1612 |
* @param int $network_id ID of the network. Can be null to default to the current network ID. |
16 | 1613 |
* @param string $option Name of the option to delete. Expected to not be SQL-escaped. |
1614 |
* @return bool True if the option was deleted, false otherwise. |
|
0 | 1615 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1616 |
function delete_network_option( $network_id, $option ) { |
0 | 1617 |
global $wpdb; |
1618 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1619 |
if ( $network_id && ! is_numeric( $network_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1620 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1621 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1622 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1623 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1624 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1625 |
// Fallback to the current network if a network ID is not specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1626 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1627 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1628 |
} |
0 | 1629 |
|
5 | 1630 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1631 |
* Fires immediately before a specific network option is deleted. |
5 | 1632 |
* |
1633 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1634 |
* |
|
1635 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1636 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1637 |
* @since 4.7.0 The `$network_id` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1638 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1639 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1640 |
* @param int $network_id ID of the network. |
5 | 1641 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1642 |
do_action( "pre_delete_site_option_{$option}", $option, $network_id ); |
0 | 1643 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1644 |
if ( ! is_multisite() ) { |
0 | 1645 |
$result = delete_option( $option ); |
1646 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1647 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1648 |
if ( is_null( $row ) || ! $row->meta_id ) { |
0 | 1649 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1650 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1651 |
$cache_key = "$network_id:$option"; |
0 | 1652 |
wp_cache_delete( $cache_key, 'site-options' ); |
1653 |
||
9 | 1654 |
$result = $wpdb->delete( |
1655 |
$wpdb->sitemeta, |
|
1656 |
array( |
|
1657 |
'meta_key' => $option, |
|
1658 |
'site_id' => $network_id, |
|
1659 |
) |
|
1660 |
); |
|
0 | 1661 |
} |
1662 |
||
1663 |
if ( $result ) { |
|
5 | 1664 |
|
1665 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1666 |
* Fires after a specific network option has been deleted. |
5 | 1667 |
* |
1668 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1669 |
* |
|
1670 |
* @since 2.9.0 As "delete_site_option_{$key}" |
|
1671 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1672 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1673 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1674 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1675 |
* @param int $network_id ID of the network. |
5 | 1676 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1677 |
do_action( "delete_site_option_{$option}", $option, $network_id ); |
5 | 1678 |
|
1679 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1680 |
* Fires after a network option has been deleted. |
5 | 1681 |
* |
1682 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1683 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1684 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1685 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1686 |
* @param int $network_id ID of the network. |
5 | 1687 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1688 |
do_action( 'delete_site_option', $option, $network_id ); |
5 | 1689 |
|
0 | 1690 |
return true; |
1691 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1692 |
|
0 | 1693 |
return false; |
1694 |
} |
|
1695 |
||
1696 |
/** |
|
16 | 1697 |
* Updates the value of a network option that was already added. |
0 | 1698 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1699 |
* @since 4.4.0 |
5 | 1700 |
* |
0 | 1701 |
* @see update_option() |
1702 |
* |
|
9 | 1703 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1704 |
* |
16 | 1705 |
* @param int $network_id ID of the network. Can be null to default to the current network ID. |
1706 |
* @param string $option Name of the option. Expected to not be SQL-escaped. |
|
1707 |
* @param mixed $value Option value. Expected to not be SQL-escaped. |
|
1708 |
* @return bool True if the value was updated, false otherwise. |
|
0 | 1709 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1710 |
function update_network_option( $network_id, $option, $value ) { |
0 | 1711 |
global $wpdb; |
1712 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1713 |
if ( $network_id && ! is_numeric( $network_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1714 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1715 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1716 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1717 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1718 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1719 |
// Fallback to the current network if a network ID is not specified. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1720 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1721 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1722 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1723 |
|
0 | 1724 |
wp_protect_special_option( $option ); |
1725 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1726 |
$old_value = get_network_option( $network_id, $option, false ); |
5 | 1727 |
|
1728 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1729 |
* Filters a specific network option before its value is updated. |
5 | 1730 |
* |
1731 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1732 |
* |
|
1733 |
* @since 2.9.0 As 'pre_update_site_option_' . $key |
|
1734 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1735 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1736 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1737 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1738 |
* @param mixed $value New value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1739 |
* @param mixed $old_value Old value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1740 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1741 |
* @param int $network_id ID of the network. |
5 | 1742 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1743 |
$value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value, $option, $network_id ); |
0 | 1744 |
|
9 | 1745 |
/* |
1746 |
* If the new and old values are the same, no need to update. |
|
1747 |
* |
|
1748 |
* Unserialized values will be adequate in most cases. If the unserialized |
|
1749 |
* data differs, the (maybe) serialized data is checked to avoid |
|
1750 |
* unnecessary database calls for otherwise identical object instances. |
|
1751 |
* |
|
1752 |
* See https://core.trac.wordpress.org/ticket/44956 |
|
1753 |
*/ |
|
1754 |
if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
|
0 | 1755 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1756 |
} |
0 | 1757 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1758 |
if ( false === $old_value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1759 |
return add_network_option( $network_id, $option, $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1760 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1761 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1762 |
$notoptions_key = "$network_id:notoptions"; |
9 | 1763 |
$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); |
16 | 1764 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1765 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1766 |
unset( $notoptions[ $option ] ); |
5 | 1767 |
wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); |
0 | 1768 |
} |
1769 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1770 |
if ( ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1771 |
$result = update_option( $option, $value, 'no' ); |
0 | 1772 |
} else { |
1773 |
$value = sanitize_option( $option, $value ); |
|
1774 |
||
1775 |
$serialized_value = maybe_serialize( $value ); |
|
9 | 1776 |
$result = $wpdb->update( |
1777 |
$wpdb->sitemeta, |
|
1778 |
array( 'meta_value' => $serialized_value ), |
|
1779 |
array( |
|
1780 |
'site_id' => $network_id, |
|
1781 |
'meta_key' => $option, |
|
1782 |
) |
|
1783 |
); |
|
0 | 1784 |
|
1785 |
if ( $result ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1786 |
$cache_key = "$network_id:$option"; |
0 | 1787 |
wp_cache_set( $cache_key, $value, 'site-options' ); |
1788 |
} |
|
1789 |
} |
|
1790 |
||
1791 |
if ( $result ) { |
|
5 | 1792 |
|
1793 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1794 |
* Fires after the value of a specific network option has been successfully updated. |
5 | 1795 |
* |
1796 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1797 |
* |
|
1798 |
* @since 2.9.0 As "update_site_option_{$key}" |
|
1799 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1800 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1801 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1802 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1803 |
* @param mixed $value Current value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1804 |
* @param mixed $old_value Old value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1805 |
* @param int $network_id ID of the network. |
5 | 1806 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1807 |
do_action( "update_site_option_{$option}", $option, $value, $old_value, $network_id ); |
5 | 1808 |
|
1809 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1810 |
* Fires after the value of a network option has been successfully updated. |
5 | 1811 |
* |
1812 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1813 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 1814 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1815 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1816 |
* @param mixed $value Current value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1817 |
* @param mixed $old_value Old value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1818 |
* @param int $network_id ID of the network. |
5 | 1819 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1820 |
do_action( 'update_site_option', $option, $value, $old_value, $network_id ); |
5 | 1821 |
|
0 | 1822 |
return true; |
1823 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1824 |
|
0 | 1825 |
return false; |
1826 |
} |
|
1827 |
||
1828 |
/** |
|
16 | 1829 |
* Deletes a site transient. |
0 | 1830 |
* |
1831 |
* @since 2.9.0 |
|
1832 |
* |
|
1833 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
|
16 | 1834 |
* @return bool True if the transient was deleted, false otherwise. |
0 | 1835 |
*/ |
1836 |
function delete_site_transient( $transient ) { |
|
5 | 1837 |
|
1838 |
/** |
|
1839 |
* Fires immediately before a specific site transient is deleted. |
|
1840 |
* |
|
1841 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
1842 |
* |
|
1843 |
* @since 3.0.0 |
|
1844 |
* |
|
1845 |
* @param string $transient Transient name. |
|
1846 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1847 |
do_action( "delete_site_transient_{$transient}", $transient ); |
5 | 1848 |
|
0 | 1849 |
if ( wp_using_ext_object_cache() ) { |
1850 |
$result = wp_cache_delete( $transient, 'site-transient' ); |
|
1851 |
} else { |
|
1852 |
$option_timeout = '_site_transient_timeout_' . $transient; |
|
9 | 1853 |
$option = '_site_transient_' . $transient; |
1854 |
$result = delete_site_option( $option ); |
|
16 | 1855 |
|
9 | 1856 |
if ( $result ) { |
0 | 1857 |
delete_site_option( $option_timeout ); |
9 | 1858 |
} |
0 | 1859 |
} |
16 | 1860 |
|
5 | 1861 |
if ( $result ) { |
1862 |
||
1863 |
/** |
|
1864 |
* Fires after a transient is deleted. |
|
1865 |
* |
|
1866 |
* @since 3.0.0 |
|
1867 |
* |
|
1868 |
* @param string $transient Deleted transient name. |
|
1869 |
*/ |
|
0 | 1870 |
do_action( 'deleted_site_transient', $transient ); |
5 | 1871 |
} |
1872 |
||
0 | 1873 |
return $result; |
1874 |
} |
|
1875 |
||
1876 |
/** |
|
16 | 1877 |
* Retrieves the value of a site transient. |
0 | 1878 |
* |
5 | 1879 |
* If the transient does not exist, does not have a value, or has expired, |
1880 |
* then the return value will be false. |
|
1881 |
* |
|
1882 |
* @since 2.9.0 |
|
0 | 1883 |
* |
1884 |
* @see get_transient() |
|
1885 |
* |
|
1886 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
|
5 | 1887 |
* @return mixed Value of transient. |
0 | 1888 |
*/ |
1889 |
function get_site_transient( $transient ) { |
|
5 | 1890 |
|
1891 |
/** |
|
16 | 1892 |
* Filters the value of an existing site transient before it is retrieved. |
5 | 1893 |
* |
1894 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
1895 |
* |
|
16 | 1896 |
* Returning a truthy value from the filter will effectively short-circuit retrieval |
1897 |
* and return the passed value instead. |
|
5 | 1898 |
* |
1899 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1900 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 1901 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1902 |
* @param mixed $pre_site_transient The default value to return if the site transient does not exist. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1903 |
* Any value other than false will short-circuit the retrieval |
16 | 1904 |
* of the transient, and return that value. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1905 |
* @param string $transient Transient name. |
5 | 1906 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1907 |
$pre = apply_filters( "pre_site_transient_{$transient}", false, $transient ); |
5 | 1908 |
|
9 | 1909 |
if ( false !== $pre ) { |
0 | 1910 |
return $pre; |
9 | 1911 |
} |
0 | 1912 |
|
1913 |
if ( wp_using_ext_object_cache() ) { |
|
1914 |
$value = wp_cache_get( $transient, 'site-transient' ); |
|
1915 |
} else { |
|
1916 |
// Core transients that do not have a timeout. Listed here so querying timeouts can be avoided. |
|
9 | 1917 |
$no_timeout = array( 'update_core', 'update_plugins', 'update_themes' ); |
0 | 1918 |
$transient_option = '_site_transient_' . $transient; |
16 | 1919 |
if ( ! in_array( $transient, $no_timeout, true ) ) { |
0 | 1920 |
$transient_timeout = '_site_transient_timeout_' . $transient; |
9 | 1921 |
$timeout = get_site_option( $transient_timeout ); |
0 | 1922 |
if ( false !== $timeout && $timeout < time() ) { |
9 | 1923 |
delete_site_option( $transient_option ); |
0 | 1924 |
delete_site_option( $transient_timeout ); |
1925 |
$value = false; |
|
1926 |
} |
|
1927 |
} |
|
1928 |
||
9 | 1929 |
if ( ! isset( $value ) ) { |
0 | 1930 |
$value = get_site_option( $transient_option ); |
9 | 1931 |
} |
0 | 1932 |
} |
1933 |
||
5 | 1934 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
* Filters the value of an existing site transient. |
5 | 1936 |
* |
1937 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
1938 |
* |
|
1939 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1940 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 1941 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1942 |
* @param mixed $value Value of site transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1943 |
* @param string $transient Transient name. |
5 | 1944 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1945 |
return apply_filters( "site_transient_{$transient}", $value, $transient ); |
0 | 1946 |
} |
1947 |
||
1948 |
/** |
|
16 | 1949 |
* Sets/updates the value of a site transient. |
0 | 1950 |
* |
16 | 1951 |
* You do not need to serialize values. If the value needs to be serialized, |
1952 |
* then it will be serialized before it is set. |
|
0 | 1953 |
* |
5 | 1954 |
* @since 2.9.0 |
1955 |
* |
|
0 | 1956 |
* @see set_transient() |
1957 |
* |
|
5 | 1958 |
* @param string $transient Transient name. Expected to not be SQL-escaped. Must be |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1959 |
* 167 characters or fewer in length. |
5 | 1960 |
* @param mixed $value Transient value. Expected to not be SQL-escaped. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1961 |
* @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration). |
16 | 1962 |
* @return bool True if the value was set, false otherwise. |
0 | 1963 |
*/ |
1964 |
function set_site_transient( $transient, $value, $expiration = 0 ) { |
|
5 | 1965 |
|
1966 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1967 |
* Filters the value of a specific site transient before it is set. |
5 | 1968 |
* |
1969 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
1970 |
* |
|
1971 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1972 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 1973 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1974 |
* @param mixed $value New value of site transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1975 |
* @param string $transient Transient name. |
5 | 1976 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1977 |
$value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient ); |
5 | 1978 |
|
0 | 1979 |
$expiration = (int) $expiration; |
1980 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1981 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1982 |
* Filters the expiration for a site transient before its value is set. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1983 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1984 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1985 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1986 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1987 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1988 |
* @param int $expiration Time until expiration in seconds. Use 0 for no expiration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1989 |
* @param mixed $value New value of site transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1990 |
* @param string $transient Transient name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1991 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
$expiration = apply_filters( "expiration_of_site_transient_{$transient}", $expiration, $value, $transient ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
|
0 | 1994 |
if ( wp_using_ext_object_cache() ) { |
1995 |
$result = wp_cache_set( $transient, $value, 'site-transient', $expiration ); |
|
1996 |
} else { |
|
1997 |
$transient_timeout = '_site_transient_timeout_' . $transient; |
|
9 | 1998 |
$option = '_site_transient_' . $transient; |
16 | 1999 |
|
0 | 2000 |
if ( false === get_site_option( $option ) ) { |
9 | 2001 |
if ( $expiration ) { |
0 | 2002 |
add_site_option( $transient_timeout, time() + $expiration ); |
9 | 2003 |
} |
0 | 2004 |
$result = add_site_option( $option, $value ); |
2005 |
} else { |
|
9 | 2006 |
if ( $expiration ) { |
0 | 2007 |
update_site_option( $transient_timeout, time() + $expiration ); |
9 | 2008 |
} |
0 | 2009 |
$result = update_site_option( $option, $value ); |
2010 |
} |
|
2011 |
} |
|
16 | 2012 |
|
0 | 2013 |
if ( $result ) { |
5 | 2014 |
|
2015 |
/** |
|
2016 |
* Fires after the value for a specific site transient has been set. |
|
2017 |
* |
|
2018 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
2019 |
* |
|
2020 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2021 |
* @since 4.4.0 The `$transient` parameter was added |
5 | 2022 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2023 |
* @param mixed $value Site transient value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2024 |
* @param int $expiration Time until expiration in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2025 |
* @param string $transient Transient name. |
5 | 2026 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
do_action( "set_site_transient_{$transient}", $value, $expiration, $transient ); |
5 | 2028 |
|
2029 |
/** |
|
2030 |
* Fires after the value for a site transient has been set. |
|
2031 |
* |
|
2032 |
* @since 3.0.0 |
|
2033 |
* |
|
2034 |
* @param string $transient The name of the site transient. |
|
2035 |
* @param mixed $value Site transient value. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2036 |
* @param int $expiration Time until expiration in seconds. |
5 | 2037 |
*/ |
0 | 2038 |
do_action( 'setted_site_transient', $transient, $value, $expiration ); |
2039 |
} |
|
16 | 2040 |
|
0 | 2041 |
return $result; |
2042 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2043 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2044 |
/** |
16 | 2045 |
* Registers default settings available in WordPress. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2046 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2047 |
* The settings registered here are primarily useful for the REST API, so this |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2048 |
* does not encompass all settings available in WordPress. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2049 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2050 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2051 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2052 |
function register_initial_settings() { |
9 | 2053 |
register_setting( |
2054 |
'general', |
|
2055 |
'blogname', |
|
2056 |
array( |
|
2057 |
'show_in_rest' => array( |
|
2058 |
'name' => 'title', |
|
2059 |
), |
|
2060 |
'type' => 'string', |
|
2061 |
'description' => __( 'Site title.' ), |
|
2062 |
) |
|
2063 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2064 |
|
9 | 2065 |
register_setting( |
2066 |
'general', |
|
2067 |
'blogdescription', |
|
2068 |
array( |
|
2069 |
'show_in_rest' => array( |
|
2070 |
'name' => 'description', |
|
2071 |
), |
|
2072 |
'type' => 'string', |
|
2073 |
'description' => __( 'Site tagline.' ), |
|
2074 |
) |
|
2075 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2077 |
if ( ! is_multisite() ) { |
9 | 2078 |
register_setting( |
2079 |
'general', |
|
2080 |
'siteurl', |
|
2081 |
array( |
|
2082 |
'show_in_rest' => array( |
|
2083 |
'name' => 'url', |
|
2084 |
'schema' => array( |
|
2085 |
'format' => 'uri', |
|
2086 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
), |
9 | 2088 |
'type' => 'string', |
2089 |
'description' => __( 'Site URL.' ), |
|
2090 |
) |
|
2091 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2092 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2093 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2094 |
if ( ! is_multisite() ) { |
9 | 2095 |
register_setting( |
2096 |
'general', |
|
2097 |
'admin_email', |
|
2098 |
array( |
|
2099 |
'show_in_rest' => array( |
|
2100 |
'name' => 'email', |
|
2101 |
'schema' => array( |
|
2102 |
'format' => 'email', |
|
2103 |
), |
|
2104 |
), |
|
2105 |
'type' => 'string', |
|
2106 |
'description' => __( 'This address is used for admin purposes, like new user notification.' ), |
|
2107 |
) |
|
2108 |
); |
|
2109 |
} |
|
2110 |
||
2111 |
register_setting( |
|
2112 |
'general', |
|
2113 |
'timezone_string', |
|
2114 |
array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2115 |
'show_in_rest' => array( |
9 | 2116 |
'name' => 'timezone', |
2117 |
), |
|
2118 |
'type' => 'string', |
|
2119 |
'description' => __( 'A city in the same timezone as you.' ), |
|
2120 |
) |
|
2121 |
); |
|
2122 |
||
2123 |
register_setting( |
|
2124 |
'general', |
|
2125 |
'date_format', |
|
2126 |
array( |
|
2127 |
'show_in_rest' => true, |
|
2128 |
'type' => 'string', |
|
2129 |
'description' => __( 'A date format for all date strings.' ), |
|
2130 |
) |
|
2131 |
); |
|
2132 |
||
2133 |
register_setting( |
|
2134 |
'general', |
|
2135 |
'time_format', |
|
2136 |
array( |
|
2137 |
'show_in_rest' => true, |
|
2138 |
'type' => 'string', |
|
2139 |
'description' => __( 'A time format for all time strings.' ), |
|
2140 |
) |
|
2141 |
); |
|
2142 |
||
2143 |
register_setting( |
|
2144 |
'general', |
|
2145 |
'start_of_week', |
|
2146 |
array( |
|
2147 |
'show_in_rest' => true, |
|
2148 |
'type' => 'integer', |
|
2149 |
'description' => __( 'A day number of the week that the week should start on.' ), |
|
2150 |
) |
|
2151 |
); |
|
2152 |
||
2153 |
register_setting( |
|
2154 |
'general', |
|
2155 |
'WPLANG', |
|
2156 |
array( |
|
2157 |
'show_in_rest' => array( |
|
2158 |
'name' => 'language', |
|
2159 |
), |
|
2160 |
'type' => 'string', |
|
2161 |
'description' => __( 'WordPress locale code.' ), |
|
2162 |
'default' => 'en_US', |
|
2163 |
) |
|
2164 |
); |
|
2165 |
||
2166 |
register_setting( |
|
2167 |
'writing', |
|
2168 |
'use_smilies', |
|
2169 |
array( |
|
2170 |
'show_in_rest' => true, |
|
2171 |
'type' => 'boolean', |
|
2172 |
'description' => __( 'Convert emoticons like :-) and :-P to graphics on display.' ), |
|
2173 |
'default' => true, |
|
2174 |
) |
|
2175 |
); |
|
2176 |
||
2177 |
register_setting( |
|
2178 |
'writing', |
|
2179 |
'default_category', |
|
2180 |
array( |
|
2181 |
'show_in_rest' => true, |
|
2182 |
'type' => 'integer', |
|
2183 |
'description' => __( 'Default post category.' ), |
|
2184 |
) |
|
2185 |
); |
|
2186 |
||
2187 |
register_setting( |
|
2188 |
'writing', |
|
2189 |
'default_post_format', |
|
2190 |
array( |
|
2191 |
'show_in_rest' => true, |
|
2192 |
'type' => 'string', |
|
2193 |
'description' => __( 'Default post format.' ), |
|
2194 |
) |
|
2195 |
); |
|
2196 |
||
2197 |
register_setting( |
|
2198 |
'reading', |
|
2199 |
'posts_per_page', |
|
2200 |
array( |
|
2201 |
'show_in_rest' => true, |
|
2202 |
'type' => 'integer', |
|
2203 |
'description' => __( 'Blog pages show at most.' ), |
|
2204 |
'default' => 10, |
|
2205 |
) |
|
2206 |
); |
|
2207 |
||
2208 |
register_setting( |
|
2209 |
'discussion', |
|
2210 |
'default_ping_status', |
|
2211 |
array( |
|
2212 |
'show_in_rest' => array( |
|
2213 |
'schema' => array( |
|
2214 |
'enum' => array( 'open', 'closed' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2215 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2216 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2217 |
'type' => 'string', |
9 | 2218 |
'description' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ), |
2219 |
) |
|
2220 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2221 |
|
9 | 2222 |
register_setting( |
2223 |
'discussion', |
|
2224 |
'default_comment_status', |
|
2225 |
array( |
|
2226 |
'show_in_rest' => array( |
|
2227 |
'schema' => array( |
|
2228 |
'enum' => array( 'open', 'closed' ), |
|
2229 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2230 |
), |
9 | 2231 |
'type' => 'string', |
16 | 2232 |
'description' => __( 'Allow people to submit comments on new posts.' ), |
9 | 2233 |
) |
2234 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2235 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2237 |
/** |
16 | 2238 |
* Registers a setting and its data. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2240 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
* @since 4.7.0 `$args` can be passed to set flags on the setting, similar to `register_meta()`. |
16 | 2242 |
* @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`. |
2243 |
* Please consider writing more inclusive code. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
* |
16 | 2245 |
* @global array $new_allowed_options |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2246 |
* @global array $wp_registered_settings |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2247 |
* |
16 | 2248 |
* @param string $option_group A settings group name. Should correspond to an allowed option key name. |
2249 |
* Default allowed option key names include 'general', 'discussion', 'media', |
|
2250 |
* 'reading', 'writing', 'misc', 'options', and 'privacy'. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2251 |
* @param string $option_name The name of an option to sanitize and save. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2252 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2253 |
* Data used to describe the setting when registered. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2254 |
* |
16 | 2255 |
* @type string $type The type of data associated with this setting. |
2256 |
* Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'. |
|
2257 |
* @type string $description A description of the data attached to this setting. |
|
2258 |
* @type callable $sanitize_callback A callback function that sanitizes the option's value. |
|
2259 |
* @type bool|array $show_in_rest Whether data associated with this setting should be included in the REST API. |
|
2260 |
* When registering complex settings, this argument may optionally be an |
|
2261 |
* array with a 'schema' key. |
|
2262 |
* @type mixed $default Default value when calling `get_option()`. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2263 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2264 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2265 |
function register_setting( $option_group, $option_name, $args = array() ) { |
16 | 2266 |
global $new_allowed_options, $wp_registered_settings; |
2267 |
||
2268 |
/* |
|
2269 |
* In 5.5.0, the `$new_whitelist_options` global variable was renamed to `$new_allowed_options`. |
|
2270 |
* Please consider writing more inclusive code. |
|
2271 |
*/ |
|
2272 |
$GLOBALS['new_whitelist_options'] = &$new_allowed_options; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2273 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2274 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2275 |
'type' => 'string', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2276 |
'group' => $option_group, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2277 |
'description' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2278 |
'sanitize_callback' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2279 |
'show_in_rest' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2280 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2281 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2282 |
// Back-compat: old sanitize callback is added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2283 |
if ( is_callable( $args ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2284 |
$args = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2285 |
'sanitize_callback' => $args, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2286 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2287 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2288 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2289 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2290 |
* Filters the registration arguments when registering a setting. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2291 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2292 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2293 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2294 |
* @param array $args Array of setting registration arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2295 |
* @param array $defaults Array of default arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2296 |
* @param string $option_group Setting group. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2297 |
* @param string $option_name Setting name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2298 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2299 |
$args = apply_filters( 'register_setting_args', $args, $defaults, $option_group, $option_name ); |
16 | 2300 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2301 |
$args = wp_parse_args( $args, $defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2302 |
|
16 | 2303 |
// Require an item schema when registering settings with an array type. |
2304 |
if ( false !== $args['show_in_rest'] && 'array' === $args['type'] && ( ! is_array( $args['show_in_rest'] ) || ! isset( $args['show_in_rest']['schema']['items'] ) ) ) { |
|
2305 |
_doing_it_wrong( __FUNCTION__, __( 'When registering an "array" setting to show in the REST API, you must specify the schema for each array item in "show_in_rest.schema.items".' ), '5.4.0' ); |
|
2306 |
} |
|
2307 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2308 |
if ( ! is_array( $wp_registered_settings ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2309 |
$wp_registered_settings = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2310 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2311 |
|
16 | 2312 |
if ( 'misc' === $option_group ) { |
9 | 2313 |
_deprecated_argument( |
2314 |
__FUNCTION__, |
|
2315 |
'3.0.0', |
|
2316 |
sprintf( |
|
16 | 2317 |
/* translators: %s: misc */ |
9 | 2318 |
__( 'The "%s" options group has been removed. Use another settings group.' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2319 |
'misc' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2320 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2321 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2322 |
$option_group = 'general'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2323 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2324 |
|
16 | 2325 |
if ( 'privacy' === $option_group ) { |
9 | 2326 |
_deprecated_argument( |
2327 |
__FUNCTION__, |
|
2328 |
'3.5.0', |
|
2329 |
sprintf( |
|
16 | 2330 |
/* translators: %s: privacy */ |
9 | 2331 |
__( 'The "%s" options group has been removed. Use another settings group.' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2332 |
'privacy' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2333 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2334 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2335 |
$option_group = 'reading'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2336 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2337 |
|
16 | 2338 |
$new_allowed_options[ $option_group ][] = $option_name; |
2339 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2340 |
if ( ! empty( $args['sanitize_callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2341 |
add_filter( "sanitize_option_{$option_name}", $args['sanitize_callback'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2342 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2343 |
if ( array_key_exists( 'default', $args ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2344 |
add_filter( "default_option_{$option_name}", 'filter_default_option', 10, 3 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2345 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2346 |
|
16 | 2347 |
/** |
2348 |
* Fires immediately before the setting is registered but after its filters are in place. |
|
2349 |
* |
|
2350 |
* @since 5.5.0 |
|
2351 |
* |
|
2352 |
* @param string $option_group Setting group. |
|
2353 |
* @param string $option_name Setting name. |
|
2354 |
* @param array $args Array of setting registration arguments. |
|
2355 |
*/ |
|
2356 |
do_action( 'register_setting', $option_group, $option_name, $args ); |
|
2357 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2358 |
$wp_registered_settings[ $option_name ] = $args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2359 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2360 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2361 |
/** |
16 | 2362 |
* Unregisters a setting. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2363 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2364 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2365 |
* @since 4.7.0 `$sanitize_callback` was deprecated. The callback from `register_setting()` is now used instead. |
16 | 2366 |
* @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`. |
2367 |
* Please consider writing more inclusive code. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2368 |
* |
16 | 2369 |
* @global array $new_allowed_options |
9 | 2370 |
* @global array $wp_registered_settings |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2371 |
* |
18 | 2372 |
* @param string $option_group The settings group name used during registration. |
2373 |
* @param string $option_name The name of the option to unregister. |
|
2374 |
* @param callable|string $deprecated Deprecated. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2375 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2376 |
function unregister_setting( $option_group, $option_name, $deprecated = '' ) { |
16 | 2377 |
global $new_allowed_options, $wp_registered_settings; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2378 |
|
16 | 2379 |
/* |
2380 |
* In 5.5.0, the `$new_whitelist_options` global variable was renamed to `$new_allowed_options`. |
|
2381 |
* Please consider writing more inclusive code. |
|
2382 |
*/ |
|
2383 |
$GLOBALS['new_whitelist_options'] = &$new_allowed_options; |
|
2384 |
||
2385 |
if ( 'misc' === $option_group ) { |
|
9 | 2386 |
_deprecated_argument( |
2387 |
__FUNCTION__, |
|
2388 |
'3.0.0', |
|
2389 |
sprintf( |
|
16 | 2390 |
/* translators: %s: misc */ |
9 | 2391 |
__( 'The "%s" options group has been removed. Use another settings group.' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2392 |
'misc' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2393 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2394 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2395 |
$option_group = 'general'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2396 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2397 |
|
16 | 2398 |
if ( 'privacy' === $option_group ) { |
9 | 2399 |
_deprecated_argument( |
2400 |
__FUNCTION__, |
|
2401 |
'3.5.0', |
|
2402 |
sprintf( |
|
16 | 2403 |
/* translators: %s: privacy */ |
9 | 2404 |
__( 'The "%s" options group has been removed. Use another settings group.' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2405 |
'privacy' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2406 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2407 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2408 |
$option_group = 'reading'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2409 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2410 |
|
16 | 2411 |
$pos = array_search( $option_name, (array) $new_allowed_options[ $option_group ], true ); |
2412 |
||
2413 |
if ( false !== $pos ) { |
|
2414 |
unset( $new_allowed_options[ $option_group ][ $pos ] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2415 |
} |
16 | 2416 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2417 |
if ( '' !== $deprecated ) { |
9 | 2418 |
_deprecated_argument( |
2419 |
__FUNCTION__, |
|
2420 |
'4.7.0', |
|
2421 |
sprintf( |
|
16 | 2422 |
/* translators: 1: $sanitize_callback, 2: register_setting() */ |
9 | 2423 |
__( '%1$s is deprecated. The callback from %2$s is used instead.' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2424 |
'<code>$sanitize_callback</code>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2425 |
'<code>register_setting()</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2426 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2427 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2428 |
remove_filter( "sanitize_option_{$option_name}", $deprecated ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2429 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2430 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2431 |
if ( isset( $wp_registered_settings[ $option_name ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2432 |
// Remove the sanitize callback if one was set during registration. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2433 |
if ( ! empty( $wp_registered_settings[ $option_name ]['sanitize_callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2434 |
remove_filter( "sanitize_option_{$option_name}", $wp_registered_settings[ $option_name ]['sanitize_callback'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2435 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2436 |
|
9 | 2437 |
// Remove the default filter if a default was provided during registration. |
2438 |
if ( array_key_exists( 'default', $wp_registered_settings[ $option_name ] ) ) { |
|
2439 |
remove_filter( "default_option_{$option_name}", 'filter_default_option', 10 ); |
|
2440 |
} |
|
2441 |
||
16 | 2442 |
/** |
2443 |
* Fires immediately before the setting is unregistered and after its filters have been removed. |
|
2444 |
* |
|
2445 |
* @since 5.5.0 |
|
2446 |
* |
|
2447 |
* @param string $option_group Setting group. |
|
2448 |
* @param string $option_name Setting name. |
|
2449 |
*/ |
|
2450 |
do_action( 'unregister_setting', $option_group, $option_name ); |
|
2451 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2452 |
unset( $wp_registered_settings[ $option_name ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2453 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2454 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2455 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2456 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2457 |
* Retrieves an array of registered settings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2458 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2459 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2460 |
* |
9 | 2461 |
* @global array $wp_registered_settings |
2462 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2463 |
* @return array List of registered settings, keyed by option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2464 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2465 |
function get_registered_settings() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2466 |
global $wp_registered_settings; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2467 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2468 |
if ( ! is_array( $wp_registered_settings ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2469 |
return array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2470 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2471 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2472 |
return $wp_registered_settings; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2473 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2474 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2475 |
/** |
16 | 2476 |
* Filters the default value for the option. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2477 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2478 |
* For settings which register a default setting in `register_setting()`, this |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2479 |
* function is added as a filter to `default_option_{$option}`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2480 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2481 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2482 |
* |
16 | 2483 |
* @param mixed $default Existing default value to return. |
2484 |
* @param string $option Option name. |
|
2485 |
* @param bool $passed_default Was `get_option()` passed a default value? |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2486 |
* @return mixed Filtered default value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2487 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2488 |
function filter_default_option( $default, $option, $passed_default ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2489 |
if ( $passed_default ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2490 |
return $default; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2491 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2492 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2493 |
$registered = get_registered_settings(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2494 |
if ( empty( $registered[ $option ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2495 |
return $default; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2496 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2497 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2498 |
return $registered[ $option ]['default']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2499 |
} |