author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
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: |
19 | 31 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
* 1. When the option has not been saved in the database, the `$default_value` value |
18 | 33 |
* is returned if provided. If not, boolean `false` is returned. |
19 | 34 |
* 2. When one of the Options API filters is used: {@see 'pre_option_$option'}, |
35 |
* {@see 'default_option_$option'}, or {@see 'option_$option'}, the returned |
|
18 | 36 |
* value may not match the expected type. |
37 |
* 3. When the option has just been saved in the database, and get_option() |
|
38 |
* is used right after, non-string scalar and null values are not converted to |
|
39 |
* string equivalents and the original type is returned. |
|
40 |
* |
|
41 |
* Examples: |
|
42 |
* |
|
19 | 43 |
* When adding options like this: `add_option( 'my_option_name', 'value' )` |
44 |
* and then retrieving them with `get_option( 'my_option_name' )`, the returned |
|
18 | 45 |
* values will be: |
0 | 46 |
* |
19 | 47 |
* - `false` returns `string(0) ""` |
48 |
* - `true` returns `string(1) "1"` |
|
49 |
* - `0` returns `string(1) "0"` |
|
50 |
* - `1` returns `string(1) "1"` |
|
51 |
* - `'0'` returns `string(1) "0"` |
|
52 |
* - `'1'` returns `string(1) "1"` |
|
53 |
* - `null` returns `string(0) ""` |
|
18 | 54 |
* |
55 |
* When adding options with non-scalar values like |
|
19 | 56 |
* `add_option( 'my_array', array( false, 'str', null ) )`, the returned value |
18 | 57 |
* will be identical to the original as it is serialized before saving |
58 |
* it in the database: |
|
59 |
* |
|
19 | 60 |
* array(3) { |
61 |
* [0] => bool(false) |
|
62 |
* [1] => string(3) "str" |
|
63 |
* [2] => NULL |
|
64 |
* } |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
* |
0 | 66 |
* @since 1.5.0 |
67 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
70 |
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
71 |
* @param mixed $default_value Optional. Default value to return if the option does not exist. |
18 | 72 |
* @return mixed Value of the option. A value of any type may be returned, including |
73 |
* scalar (string, boolean, float, integer), null, array, object. |
|
74 |
* Scalar and null values will be returned as strings as long as they originate |
|
75 |
* from a database stored option value. If there is no option in the database, |
|
76 |
* boolean `false` is returned. |
|
0 | 77 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
78 |
function get_option( $option, $default_value = false ) { |
0 | 79 |
global $wpdb; |
80 |
||
19 | 81 |
if ( is_scalar( $option ) ) { |
82 |
$option = trim( $option ); |
|
83 |
} |
|
84 |
||
9 | 85 |
if ( empty( $option ) ) { |
0 | 86 |
return false; |
9 | 87 |
} |
0 | 88 |
|
16 | 89 |
/* |
90 |
* Until a proper _deprecated_option() function can be introduced, |
|
91 |
* redirect requests to deprecated keys to the new, correct ones. |
|
92 |
*/ |
|
93 |
$deprecated_keys = array( |
|
94 |
'blacklist_keys' => 'disallowed_keys', |
|
95 |
'comment_whitelist' => 'comment_previously_approved', |
|
96 |
); |
|
97 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
98 |
if ( isset( $deprecated_keys[ $option ] ) && ! wp_installing() ) { |
16 | 99 |
_deprecated_argument( |
100 |
__FUNCTION__, |
|
101 |
'5.5.0', |
|
102 |
sprintf( |
|
103 |
/* translators: 1: Deprecated option key, 2: New option key. */ |
|
104 |
__( 'The "%1$s" option key has been renamed to "%2$s".' ), |
|
105 |
$option, |
|
106 |
$deprecated_keys[ $option ] |
|
107 |
) |
|
108 |
); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
109 |
return get_option( $deprecated_keys[ $option ], $default_value ); |
16 | 110 |
} |
111 |
||
5 | 112 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
* Filters the value of an existing option before it is retrieved. |
5 | 114 |
* |
115 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
116 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
117 |
* Returning a value other than false from the filter will short-circuit retrieval |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
118 |
* and return that value instead. |
5 | 119 |
* |
120 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
121 |
* @since 4.4.0 The `$option` parameter was added. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
122 |
* @since 4.9.0 The `$default_value` parameter was added. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
124 |
* @param mixed $pre_option The value to return instead of the option value. This differs from |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
* `$default_value`, which is used as the fallback value in the event |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
* the option doesn't exist elsewhere in get_option(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
* Default false (to skip past the short-circuit). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
* @param string $option Option name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
129 |
* @param mixed $default_value The fallback value to return if the option does not exist. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
130 |
* Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
131 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
132 |
$pre = apply_filters( "pre_option_{$option}", false, $option, $default_value ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
133 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
134 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
135 |
* Filters the value of all existing options before it is retrieved. |
5 | 136 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
137 |
* Returning a truthy value from the filter will effectively short-circuit retrieval |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
138 |
* and return the passed value instead. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
* @param mixed $pre_option The value to return instead of the option value. This differs from |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
* `$default_value`, which is used as the fallback value in the event |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
144 |
* the option doesn't exist elsewhere in get_option(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
145 |
* Default false (to skip past the short-circuit). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
146 |
* @param string $option Name of the option. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
147 |
* @param mixed $default_value The fallback value to return if the option does not exist. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
148 |
* Default false. |
5 | 149 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
150 |
$pre = apply_filters( 'pre_option', $pre, $option, $default_value ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
|
9 | 152 |
if ( false !== $pre ) { |
0 | 153 |
return $pre; |
9 | 154 |
} |
0 | 155 |
|
9 | 156 |
if ( defined( 'WP_SETUP_CONFIG' ) ) { |
0 | 157 |
return false; |
9 | 158 |
} |
0 | 159 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
// 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
|
161 |
$passed_default = func_num_args() > 1; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
if ( ! wp_installing() ) { |
0 | 164 |
$alloptions = wp_load_alloptions(); |
165 |
||
9 | 166 |
if ( isset( $alloptions[ $option ] ) ) { |
167 |
$value = $alloptions[ $option ]; |
|
0 | 168 |
} else { |
169 |
$value = wp_cache_get( $option, 'options' ); |
|
170 |
||
171 |
if ( false === $value ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
172 |
// Prevent non-existent options from triggering multiple queries. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
$notoptions = wp_cache_get( 'notoptions', 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
174 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
175 |
// Prevent non-existent `notoptions` key from triggering multiple key lookups. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
176 |
if ( ! is_array( $notoptions ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
$notoptions = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
178 |
wp_cache_set( 'notoptions', $notoptions, 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
} elseif ( isset( $notoptions[ $option ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
180 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
181 |
* Filters the default value for an option. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
182 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
183 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
184 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
185 |
* @since 3.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
186 |
* @since 4.4.0 The `$option` parameter was added. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
187 |
* @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
188 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
189 |
* @param mixed $default_value The default value to return if the option does not exist |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
190 |
* in the database. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
191 |
* @param string $option Option name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
192 |
* @param bool $passed_default Was `get_option()` passed a default value? |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
193 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
194 |
return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
195 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
196 |
|
0 | 197 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
198 |
||
16 | 199 |
// Has to be get_row() instead of get_var() because of funkiness with 0, false, null values. |
0 | 200 |
if ( is_object( $row ) ) { |
201 |
$value = $row->option_value; |
|
202 |
wp_cache_add( $option, $value, 'options' ); |
|
16 | 203 |
} else { // Option does not exist, so we must cache its non-existence. |
9 | 204 |
$notoptions[ $option ] = true; |
0 | 205 |
wp_cache_set( 'notoptions', $notoptions, 'options' ); |
5 | 206 |
|
207 |
/** This filter is documented in wp-includes/option.php */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
208 |
return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default ); |
0 | 209 |
} |
210 |
} |
|
211 |
} |
|
212 |
} else { |
|
213 |
$suppress = $wpdb->suppress_errors(); |
|
9 | 214 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
0 | 215 |
$wpdb->suppress_errors( $suppress ); |
16 | 216 |
|
5 | 217 |
if ( is_object( $row ) ) { |
0 | 218 |
$value = $row->option_value; |
5 | 219 |
} else { |
220 |
/** This filter is documented in wp-includes/option.php */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
221 |
return apply_filters( "default_option_{$option}", $default_value, $option, $passed_default ); |
5 | 222 |
} |
0 | 223 |
} |
224 |
||
16 | 225 |
// If home is not set, use siteurl. |
226 |
if ( 'home' === $option && '' === $value ) { |
|
0 | 227 |
return get_option( 'siteurl' ); |
9 | 228 |
} |
0 | 229 |
|
16 | 230 |
if ( in_array( $option, array( 'siteurl', 'home', 'category_base', 'tag_base' ), true ) ) { |
0 | 231 |
$value = untrailingslashit( $value ); |
9 | 232 |
} |
0 | 233 |
|
5 | 234 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
* Filters the value of an existing option. |
5 | 236 |
* |
237 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
238 |
* |
|
239 |
* @since 1.5.0 As 'option_' . $setting |
|
240 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* @since 4.4.0 The `$option` parameter was added. |
5 | 242 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
* @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
|
244 |
* unserialized prior to being returned. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* @param string $option Option name. |
5 | 246 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
return apply_filters( "option_{$option}", maybe_unserialize( $value ), $option ); |
0 | 248 |
} |
249 |
||
250 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
251 |
* Primes specific options into the cache with a single database query. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
252 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
253 |
* Only options that do not already exist in cache will be loaded. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
254 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
255 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
256 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
257 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
258 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
259 |
* @param string[] $options An array of option names to be loaded. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
260 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
261 |
function wp_prime_option_caches( $options ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
262 |
global $wpdb; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
263 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
264 |
$alloptions = wp_load_alloptions(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
$cached_options = wp_cache_get_multiple( $options, 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
266 |
$notoptions = wp_cache_get( 'notoptions', 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
267 |
if ( ! is_array( $notoptions ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
268 |
$notoptions = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
269 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
270 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
271 |
// Filter options that are not in the cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
272 |
$options_to_prime = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
273 |
foreach ( $options as $option ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
274 |
if ( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
275 |
( ! isset( $cached_options[ $option ] ) || false === $cached_options[ $option ] ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
276 |
&& ! isset( $alloptions[ $option ] ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
277 |
&& ! isset( $notoptions[ $option ] ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
278 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
279 |
$options_to_prime[] = $option; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
280 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
281 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
282 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
283 |
// Bail early if there are no options to be loaded. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
284 |
if ( empty( $options_to_prime ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
285 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
286 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
287 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
288 |
$results = $wpdb->get_results( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
289 |
$wpdb->prepare( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
290 |
sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
291 |
"SELECT option_name, option_value FROM $wpdb->options WHERE option_name IN (%s)", |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
292 |
implode( ',', array_fill( 0, count( $options_to_prime ), '%s' ) ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
293 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
294 |
$options_to_prime |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
295 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
296 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
297 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
298 |
$options_found = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
299 |
foreach ( $results as $result ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
300 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
301 |
* The cache is primed with the raw value (i.e. not maybe_unserialized). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
302 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
303 |
* `get_option()` will handle unserializing the value as needed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
304 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
305 |
$options_found[ $result->option_name ] = $result->option_value; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
306 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
307 |
wp_cache_set_multiple( $options_found, 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
308 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
309 |
// If all options were found, no need to update `notoptions` cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
310 |
if ( count( $options_found ) === count( $options_to_prime ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
311 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
312 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
313 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
314 |
$options_not_found = array_diff( $options_to_prime, array_keys( $options_found ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
315 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
316 |
// Add the options that were not found to the cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
317 |
$update_notoptions = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
318 |
foreach ( $options_not_found as $option_name ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
319 |
if ( ! isset( $notoptions[ $option_name ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
320 |
$notoptions[ $option_name ] = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
321 |
$update_notoptions = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
322 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
323 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
324 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
325 |
// Only update the cache if it was modified. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
326 |
if ( $update_notoptions ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
327 |
wp_cache_set( 'notoptions', $notoptions, 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
328 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
329 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
330 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
331 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
332 |
* Primes the cache of all options registered with a specific option group. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
333 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
334 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
335 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
336 |
* @global array $new_allowed_options |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
337 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
338 |
* @param string $option_group The option group to load options for. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
339 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
340 |
function wp_prime_option_caches_by_group( $option_group ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
341 |
global $new_allowed_options; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
342 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
343 |
if ( isset( $new_allowed_options[ $option_group ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
344 |
wp_prime_option_caches( $new_allowed_options[ $option_group ] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
345 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
346 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
347 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
348 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
349 |
* Retrieves multiple options. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
350 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
351 |
* Options are loaded as necessary first in order to use a single database query at most. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
352 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
353 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
354 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
355 |
* @param string[] $options An array of option names to retrieve. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
356 |
* @return array An array of key-value pairs for the requested options. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
357 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
358 |
function get_options( $options ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
359 |
wp_prime_option_caches( $options ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
360 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
361 |
$result = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
362 |
foreach ( $options as $option ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
363 |
$result[ $option ] = get_option( $option ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
364 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
365 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
366 |
return $result; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
367 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
368 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
369 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
370 |
* Sets the autoload values for multiple options in the database. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
371 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
372 |
* Autoloading too many options can lead to performance problems, especially if the options are not frequently used. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
373 |
* This function allows modifying the autoload value for multiple options without changing the actual option value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
* This is for example recommended for plugin activation and deactivation hooks, to ensure any options exclusively used |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
375 |
* by the plugin which are generally autoloaded can be set to not autoload when the plugin is inactive. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
376 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
377 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
378 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
379 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
380 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
381 |
* @param array $options Associative array of option names and their autoload values to set. The option names are |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
382 |
* expected to not be SQL-escaped. The autoload values accept 'yes'|true to enable or 'no'|false |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
383 |
* to disable. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
384 |
* @return array Associative array of all provided $options as keys and boolean values for whether their autoload value |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
385 |
* was updated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
386 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
387 |
function wp_set_option_autoload_values( array $options ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
388 |
global $wpdb; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
389 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
390 |
if ( ! $options ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
391 |
return array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
392 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
393 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
394 |
$grouped_options = array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
395 |
'on' => array(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
396 |
'off' => array(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
397 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
398 |
$results = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
399 |
foreach ( $options as $option => $autoload ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
400 |
wp_protect_special_option( $option ); // Ensure only valid options can be passed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
401 |
if ( 'off' === $autoload || 'no' === $autoload || false === $autoload ) { // Sanitize autoload value and categorize accordingly. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
402 |
$grouped_options['off'][] = $option; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
403 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
404 |
$grouped_options['on'][] = $option; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
405 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
406 |
$results[ $option ] = false; // Initialize result value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
407 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
408 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
409 |
$where = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
410 |
$where_args = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
411 |
foreach ( $grouped_options as $autoload => $options ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
412 |
if ( ! $options ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
413 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
414 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
$placeholders = implode( ',', array_fill( 0, count( $options ), '%s' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
416 |
$where[] = "autoload != '%s' AND option_name IN ($placeholders)"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
417 |
$where_args[] = $autoload; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
418 |
foreach ( $options as $option ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
$where_args[] = $option; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
$where = 'WHERE ' . implode( ' OR ', $where ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
425 |
* Determine the relevant options that do not already use the given autoload value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
426 |
* If no options are returned, no need to update. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
427 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
428 |
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
429 |
$options_to_update = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options $where", $where_args ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
430 |
if ( ! $options_to_update ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
431 |
return $results; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
432 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
433 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
434 |
// Run UPDATE queries as needed (maximum 2) to update the relevant options' autoload values to 'yes' or 'no'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
435 |
foreach ( $grouped_options as $autoload => $options ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
436 |
if ( ! $options ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
437 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
438 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
439 |
$options = array_intersect( $options, $options_to_update ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
440 |
$grouped_options[ $autoload ] = $options; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
441 |
if ( ! $grouped_options[ $autoload ] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
442 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
443 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
444 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
445 |
// Run query to update autoload value for all the options where it is needed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
446 |
$success = $wpdb->query( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
447 |
$wpdb->prepare( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
448 |
"UPDATE $wpdb->options SET autoload = %s WHERE option_name IN (" . implode( ',', array_fill( 0, count( $grouped_options[ $autoload ] ), '%s' ) ) . ')', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
449 |
array_merge( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
450 |
array( $autoload ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
451 |
$grouped_options[ $autoload ] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
452 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
453 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
454 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
455 |
if ( ! $success ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
456 |
// Set option list to an empty array to indicate no options were updated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
457 |
$grouped_options[ $autoload ] = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
458 |
continue; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
459 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
460 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
461 |
// Assume that on success all options were updated, which should be the case given only new values are sent. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
462 |
foreach ( $grouped_options[ $autoload ] as $option ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
463 |
$results[ $option ] = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
464 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
465 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
466 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
467 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
468 |
* If any options were changed to 'on', delete their individual caches, and delete 'alloptions' cache so that it |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
469 |
* is refreshed as needed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
470 |
* If no options were changed to 'on' but any options were changed to 'no', delete them from the 'alloptions' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
471 |
* cache. This is not necessary when options were changed to 'on', since in that situation the entire cache is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
472 |
* deleted anyway. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
473 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
474 |
if ( $grouped_options['on'] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
475 |
wp_cache_delete_multiple( $grouped_options['on'], 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
476 |
wp_cache_delete( 'alloptions', 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
477 |
} elseif ( $grouped_options['off'] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
478 |
$alloptions = wp_load_alloptions( true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
479 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
480 |
foreach ( $grouped_options['off'] as $option ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
481 |
if ( isset( $alloptions[ $option ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
482 |
unset( $alloptions[ $option ] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
483 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
484 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
485 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
486 |
wp_cache_set( 'alloptions', $alloptions, 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
487 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
488 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
489 |
return $results; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
490 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
491 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
492 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
493 |
* Sets the autoload value for multiple options in the database. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
494 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
495 |
* This is a wrapper for {@see wp_set_option_autoload_values()}, which can be used to set different autoload values for |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
496 |
* each option at once. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
497 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
498 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
499 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
500 |
* @see wp_set_option_autoload_values() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
501 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
502 |
* @param string[] $options List of option names. Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
503 |
* @param string|bool $autoload Autoload value to control whether to load the options when WordPress starts up. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
504 |
* Accepts 'yes'|true to enable or 'no'|false to disable. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
505 |
* @return array Associative array of all provided $options as keys and boolean values for whether their autoload value |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
506 |
* was updated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
507 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
508 |
function wp_set_options_autoload( array $options, $autoload ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
509 |
return wp_set_option_autoload_values( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
510 |
array_fill_keys( $options, $autoload ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
511 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
512 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
513 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
514 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
515 |
* Sets the autoload value for an option in the database. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
516 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
517 |
* This is a wrapper for {@see wp_set_option_autoload_values()}, which can be used to set the autoload value for |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
518 |
* multiple options at once. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
519 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
520 |
* @since 6.4.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
521 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
522 |
* @see wp_set_option_autoload_values() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
523 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
524 |
* @param string $option Name of the option. Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
525 |
* @param string|bool $autoload Autoload value to control whether to load the option when WordPress starts up. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
526 |
* Accepts 'yes'|true to enable or 'no'|false to disable. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
527 |
* @return bool True if the autoload value was modified, false otherwise. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
528 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
529 |
function wp_set_option_autoload( $option, $autoload ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
530 |
$result = wp_set_option_autoload_values( array( $option => $autoload ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
531 |
if ( isset( $result[ $option ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
532 |
return $result[ $option ]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
533 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
534 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
535 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
536 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
537 |
/** |
16 | 538 |
* Protects WordPress special option from being modified. |
0 | 539 |
* |
540 |
* Will die if $option is in protected list. Protected options are 'alloptions' |
|
541 |
* and 'notoptions' options. |
|
542 |
* |
|
543 |
* @since 2.2.0 |
|
544 |
* |
|
545 |
* @param string $option Option name. |
|
546 |
*/ |
|
547 |
function wp_protect_special_option( $option ) { |
|
9 | 548 |
if ( 'alloptions' === $option || 'notoptions' === $option ) { |
16 | 549 |
wp_die( |
550 |
sprintf( |
|
551 |
/* translators: %s: Option name. */ |
|
552 |
__( '%s is a protected WP option and may not be modified' ), |
|
553 |
esc_html( $option ) |
|
554 |
) |
|
555 |
); |
|
9 | 556 |
} |
0 | 557 |
} |
558 |
||
559 |
/** |
|
16 | 560 |
* Prints option value after sanitizing for forms. |
0 | 561 |
* |
562 |
* @since 1.5.0 |
|
563 |
* |
|
564 |
* @param string $option Option name. |
|
565 |
*/ |
|
566 |
function form_option( $option ) { |
|
567 |
echo esc_attr( get_option( $option ) ); |
|
568 |
} |
|
569 |
||
570 |
/** |
|
571 |
* Loads and caches all autoloaded options, if available or all options. |
|
572 |
* |
|
573 |
* @since 2.2.0 |
|
16 | 574 |
* @since 5.3.1 The `$force_cache` parameter was added. |
0 | 575 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
576 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
577 |
* |
16 | 578 |
* @param bool $force_cache Optional. Whether to force an update of the local cache |
579 |
* from the persistent cache. Default false. |
|
0 | 580 |
* @return array List of all options. |
581 |
*/ |
|
16 | 582 |
function wp_load_alloptions( $force_cache = false ) { |
0 | 583 |
global $wpdb; |
584 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
585 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
586 |
* Filters the array of alloptions before it is populated. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
587 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
588 |
* Returning an array from the filter will effectively short circuit |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
589 |
* wp_load_alloptions(), returning that value instead. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
590 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
591 |
* @since 6.2.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
592 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
593 |
* @param array|null $alloptions An array of alloptions. Default null. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
594 |
* @param bool $force_cache Whether to force an update of the local cache from the persistent cache. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
595 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
596 |
$alloptions = apply_filters( 'pre_wp_load_alloptions', null, $force_cache ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
597 |
if ( is_array( $alloptions ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
598 |
return $alloptions; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
599 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
600 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
601 |
if ( ! wp_installing() || ! is_multisite() ) { |
16 | 602 |
$alloptions = wp_cache_get( 'alloptions', 'options', $force_cache ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
603 |
} else { |
0 | 604 |
$alloptions = false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
605 |
} |
0 | 606 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
607 |
if ( ! $alloptions ) { |
16 | 608 |
$suppress = $wpdb->suppress_errors(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
609 |
$alloptions_db = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE autoload IN ( '" . implode( "', '", esc_sql( wp_autoload_values_to_autoload() ) ) . "' )" ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
610 |
|
16 | 611 |
if ( ! $alloptions_db ) { |
0 | 612 |
$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
|
613 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
614 |
$wpdb->suppress_errors( $suppress ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
615 |
|
0 | 616 |
$alloptions = array(); |
617 |
foreach ( (array) $alloptions_db as $o ) { |
|
9 | 618 |
$alloptions[ $o->option_name ] = $o->option_value; |
0 | 619 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
if ( ! wp_installing() || ! is_multisite() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
* Filters all options before caching them. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
625 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
* @param array $alloptions Array with all options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
$alloptions = apply_filters( 'pre_cache_alloptions', $alloptions ); |
16 | 630 |
|
0 | 631 |
wp_cache_add( 'alloptions', $alloptions, 'options' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
} |
0 | 633 |
} |
634 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
* Filters all options after retrieving them. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
* @param array $alloptions Array with all options. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
return apply_filters( 'alloptions', $alloptions ); |
0 | 643 |
} |
644 |
||
645 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
646 |
* Primes specific network options for the current network into the cache with a single database query. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
647 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
648 |
* Only network options that do not already exist in cache will be loaded. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
649 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
650 |
* If site is not multisite, then call wp_prime_option_caches(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
651 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
652 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
653 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
654 |
* @see wp_prime_network_option_caches() |
0 | 655 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
656 |
* @param string[] $options An array of option names to be loaded. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
657 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
658 |
function wp_prime_site_option_caches( array $options ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
659 |
wp_prime_network_option_caches( null, $options ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
660 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
661 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
662 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
663 |
* Primes specific network options into the cache with a single database query. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
664 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
665 |
* Only network options that do not already exist in cache will be loaded. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
666 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
667 |
* If site is not multisite, then call wp_prime_option_caches(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
668 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
669 |
* @since 6.6.0 |
0 | 670 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
671 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
672 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
673 |
* @param int $network_id ID of the network. Can be null to default to the current network ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
674 |
* @param string[] $options An array of option names to be loaded. |
0 | 675 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
676 |
function wp_prime_network_option_caches( $network_id, array $options ) { |
0 | 677 |
global $wpdb; |
678 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
679 |
if ( wp_installing() ) { |
0 | 680 |
return; |
9 | 681 |
} |
0 | 682 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
683 |
if ( ! is_multisite() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
684 |
wp_prime_option_caches( $options ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
685 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
686 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
687 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
688 |
if ( $network_id && ! is_numeric( $network_id ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
689 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
690 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
691 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
692 |
$network_id = (int) $network_id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
693 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
694 |
// Fallback to the current network if a network ID is not specified. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
695 |
if ( ! $network_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
$network_id = get_current_network_id(); |
9 | 697 |
} |
0 | 698 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
699 |
$cache_keys = array(); |
0 | 700 |
foreach ( $options as $option ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
701 |
$cache_keys[ $option ] = "{$network_id}:{$option}"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
702 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
703 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
704 |
$cache_group = 'site-options'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
705 |
$cached_options = wp_cache_get_multiple( array_values( $cache_keys ), $cache_group ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
706 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
707 |
$notoptions_key = "$network_id:notoptions"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
708 |
$notoptions = wp_cache_get( $notoptions_key, $cache_group ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
709 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
710 |
if ( ! is_array( $notoptions ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
711 |
$notoptions = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
712 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
713 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
714 |
// Filter options that are not in the cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
715 |
$options_to_prime = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
716 |
foreach ( $cache_keys as $option => $cache_key ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
717 |
if ( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
718 |
( ! isset( $cached_options[ $cache_key ] ) || false === $cached_options[ $cache_key ] ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
719 |
&& ! isset( $notoptions[ $option ] ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
720 |
) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
721 |
$options_to_prime[] = $option; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
722 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
723 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
724 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
725 |
// Bail early if there are no options to be loaded. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
726 |
if ( empty( $options_to_prime ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
727 |
return; |
0 | 728 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
729 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
730 |
$query_args = $options_to_prime; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
731 |
$query_args[] = $network_id; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
732 |
$results = $wpdb->get_results( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
733 |
$wpdb->prepare( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
734 |
sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
735 |
"SELECT meta_key, meta_value FROM $wpdb->sitemeta WHERE meta_key IN (%s) AND site_id = %s", |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
736 |
implode( ',', array_fill( 0, count( $options_to_prime ), '%s' ) ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
737 |
'%d' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
738 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
739 |
$query_args |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
740 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
741 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
742 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
743 |
$data = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
744 |
$options_found = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
745 |
foreach ( $results as $result ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
746 |
$key = $result->meta_key; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
747 |
$cache_key = $cache_keys[ $key ]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
748 |
$data[ $cache_key ] = maybe_unserialize( $result->meta_value ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
749 |
$options_found[] = $key; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
750 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
751 |
wp_cache_set_multiple( $data, $cache_group ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
752 |
// If all options were found, no need to update `notoptions` cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
753 |
if ( count( $options_found ) === count( $options_to_prime ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
754 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
755 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
756 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
757 |
$options_not_found = array_diff( $options_to_prime, $options_found ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
758 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
759 |
// Add the options that were not found to the cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
760 |
$update_notoptions = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
761 |
foreach ( $options_not_found as $option_name ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
762 |
if ( ! isset( $notoptions[ $option_name ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
763 |
$notoptions[ $option_name ] = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
764 |
$update_notoptions = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
765 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
766 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
767 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
768 |
// Only update the cache if it was modified. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
769 |
if ( $update_notoptions ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
770 |
wp_cache_set( $notoptions_key, $notoptions, $cache_group ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
771 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
772 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
773 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
774 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
775 |
* Loads and primes caches of certain often requested network options if is_multisite(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
776 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
777 |
* @since 3.0.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
778 |
* @since 6.3.0 Also prime caches for network options when persistent object cache is enabled. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
779 |
* @since 6.6.0 Uses wp_prime_network_option_caches(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
780 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
781 |
* @param int $network_id Optional. Network ID of network for which to prime network options cache. Defaults to current network. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
782 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
783 |
function wp_load_core_site_options( $network_id = null ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
784 |
if ( ! is_multisite() || wp_installing() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
785 |
return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
786 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
787 |
$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', 'WPLANG' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
788 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
789 |
wp_prime_network_option_caches( $network_id, $core_options ); |
0 | 790 |
} |
791 |
||
792 |
/** |
|
16 | 793 |
* Updates the value of an option that was already added. |
0 | 794 |
* |
16 | 795 |
* You do not need to serialize values. If the value needs to be serialized, |
796 |
* then it will be serialized before it is inserted into the database. |
|
797 |
* Remember, resources cannot be serialized or added as an option. |
|
0 | 798 |
* |
16 | 799 |
* If the option does not exist, it will be created. |
800 |
||
801 |
* This function is designed to work with or without a logged-in user. In terms of security, |
|
802 |
* plugin developers should check the current user's capabilities before updating any options. |
|
0 | 803 |
* |
804 |
* @since 1.0.0 |
|
5 | 805 |
* @since 4.2.0 The `$autoload` parameter was added. |
0 | 806 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
807 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
808 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
809 |
* @param string $option Name of the option to update. Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
810 |
* @param mixed $value Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
811 |
* @param bool|null $autoload Optional. Whether to load the option when WordPress starts up. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
812 |
* Accepts a boolean, or `null` to stick with the initial value or, if no initial value is set, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
813 |
* to leave the decision up to default heuristics in WordPress. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
814 |
* For existing options, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
815 |
* `$autoload` can only be updated using `update_option()` if `$value` is also changed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
816 |
* For backward compatibility 'yes' and 'no' are also accepted. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
817 |
* Autoloading too many options can lead to performance problems, especially if the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
818 |
* options are not frequently used. For options which are accessed across several places |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
819 |
* in the frontend, it is recommended to autoload them, by using true. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
820 |
* For options which are accessed only on few specific URLs, it is recommended |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
821 |
* to not autoload them, by using false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
822 |
* For non-existent options, the default is null, which means WordPress will determine |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
823 |
* the autoload value. |
16 | 824 |
* @return bool True if the value was updated, false otherwise. |
0 | 825 |
*/ |
5 | 826 |
function update_option( $option, $value, $autoload = null ) { |
0 | 827 |
global $wpdb; |
828 |
||
19 | 829 |
if ( is_scalar( $option ) ) { |
830 |
$option = trim( $option ); |
|
831 |
} |
|
832 |
||
9 | 833 |
if ( empty( $option ) ) { |
0 | 834 |
return false; |
9 | 835 |
} |
0 | 836 |
|
16 | 837 |
/* |
838 |
* Until a proper _deprecated_option() function can be introduced, |
|
839 |
* redirect requests to deprecated keys to the new, correct ones. |
|
840 |
*/ |
|
841 |
$deprecated_keys = array( |
|
842 |
'blacklist_keys' => 'disallowed_keys', |
|
843 |
'comment_whitelist' => 'comment_previously_approved', |
|
844 |
); |
|
845 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
846 |
if ( isset( $deprecated_keys[ $option ] ) && ! wp_installing() ) { |
16 | 847 |
_deprecated_argument( |
848 |
__FUNCTION__, |
|
849 |
'5.5.0', |
|
850 |
sprintf( |
|
851 |
/* translators: 1: Deprecated option key, 2: New option key. */ |
|
852 |
__( 'The "%1$s" option key has been renamed to "%2$s".' ), |
|
853 |
$option, |
|
854 |
$deprecated_keys[ $option ] |
|
855 |
) |
|
856 |
); |
|
857 |
return update_option( $deprecated_keys[ $option ], $value, $autoload ); |
|
858 |
} |
|
859 |
||
0 | 860 |
wp_protect_special_option( $option ); |
861 |
||
9 | 862 |
if ( is_object( $value ) ) { |
0 | 863 |
$value = clone $value; |
9 | 864 |
} |
0 | 865 |
|
9 | 866 |
$value = sanitize_option( $option, $value ); |
0 | 867 |
$old_value = get_option( $option ); |
5 | 868 |
|
869 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
* Filters a specific option before its value is (maybe) serialized and updated. |
5 | 871 |
* |
872 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
873 |
* |
|
874 |
* @since 2.6.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
* @since 4.4.0 The `$option` parameter was added. |
5 | 876 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
* @param mixed $value The new, unserialized option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
* @param mixed $old_value The old option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
879 |
* @param string $option Option name. |
5 | 880 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
881 |
$value = apply_filters( "pre_update_option_{$option}", $value, $old_value, $option ); |
0 | 882 |
|
5 | 883 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
884 |
* Filters an option before its value is (maybe) serialized and updated. |
5 | 885 |
* |
886 |
* @since 3.9.0 |
|
887 |
* |
|
888 |
* @param mixed $value The new, unserialized option value. |
|
889 |
* @param string $option Name of the option. |
|
890 |
* @param mixed $old_value The old option value. |
|
891 |
*/ |
|
892 |
$value = apply_filters( 'pre_update_option', $value, $option, $old_value ); |
|
893 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
894 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
895 |
* 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
|
896 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
* 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
|
898 |
* 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
|
899 |
* unnecessary database calls for otherwise identical object instances. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
900 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
901 |
* See https://core.trac.wordpress.org/ticket/38903 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
902 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
903 |
if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
0 | 904 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
} |
0 | 906 |
|
5 | 907 |
/** 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
|
908 |
if ( apply_filters( "default_option_{$option}", false, $option, false ) === $old_value ) { |
5 | 909 |
return add_option( $option, $value, '', $autoload ); |
910 |
} |
|
0 | 911 |
|
912 |
$serialized_value = maybe_serialize( $value ); |
|
913 |
||
5 | 914 |
/** |
915 |
* Fires immediately before an option value is updated. |
|
916 |
* |
|
917 |
* @since 2.9.0 |
|
918 |
* |
|
919 |
* @param string $option Name of the option to update. |
|
920 |
* @param mixed $old_value The old option value. |
|
921 |
* @param mixed $value The new option value. |
|
922 |
*/ |
|
0 | 923 |
do_action( 'update_option', $option, $old_value, $value ); |
5 | 924 |
|
925 |
$update_args = array( |
|
926 |
'option_value' => $serialized_value, |
|
927 |
); |
|
928 |
||
929 |
if ( null !== $autoload ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
930 |
$update_args['autoload'] = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
931 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
932 |
// Retrieve the current autoload value to reevaluate it in case it was set automatically. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
933 |
$raw_autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
934 |
$allow_values = array( 'auto-on', 'auto-off', 'auto' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
935 |
if ( in_array( $raw_autoload, $allow_values, true ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
936 |
$autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
937 |
if ( $autoload !== $raw_autoload ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
938 |
$update_args['autoload'] = $autoload; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
939 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
940 |
} |
5 | 941 |
} |
942 |
||
943 |
$result = $wpdb->update( $wpdb->options, $update_args, array( 'option_name' => $option ) ); |
|
9 | 944 |
if ( ! $result ) { |
0 | 945 |
return false; |
9 | 946 |
} |
0 | 947 |
|
948 |
$notoptions = wp_cache_get( 'notoptions', 'options' ); |
|
16 | 949 |
|
9 | 950 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
951 |
unset( $notoptions[ $option ] ); |
|
0 | 952 |
wp_cache_set( 'notoptions', $notoptions, 'options' ); |
953 |
} |
|
954 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
if ( ! wp_installing() ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
956 |
if ( ! isset( $update_args['autoload'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
957 |
// Update the cached value based on where it is currently cached. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
958 |
$alloptions = wp_load_alloptions( true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
959 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
960 |
if ( isset( $alloptions[ $option ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
961 |
$alloptions[ $option ] = $serialized_value; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
962 |
wp_cache_set( 'alloptions', $alloptions, 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
963 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
964 |
wp_cache_set( $option, $serialized_value, 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
965 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
966 |
} elseif ( in_array( $update_args['autoload'], wp_autoload_values_to_autoload(), true ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
967 |
// Delete the individual cache, then set in alloptions cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
968 |
wp_cache_delete( $option, 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
969 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
970 |
$alloptions = wp_load_alloptions( true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
971 |
|
0 | 972 |
$alloptions[ $option ] = $serialized_value; |
973 |
wp_cache_set( 'alloptions', $alloptions, 'options' ); |
|
974 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
975 |
// Delete the alloptions cache, then set the individual cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
976 |
$alloptions = wp_load_alloptions( true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
977 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
978 |
if ( isset( $alloptions[ $option ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
979 |
unset( $alloptions[ $option ] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
980 |
wp_cache_set( 'alloptions', $alloptions, 'options' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
981 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
982 |
|
0 | 983 |
wp_cache_set( $option, $serialized_value, 'options' ); |
984 |
} |
|
985 |
} |
|
986 |
||
5 | 987 |
/** |
988 |
* Fires after the value of a specific option has been successfully updated. |
|
989 |
* |
|
990 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
991 |
* |
|
992 |
* @since 2.0.1 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
* @since 4.4.0 The `$option` parameter was added. |
5 | 994 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
* @param mixed $old_value The old option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
* @param mixed $value The new option value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
997 |
* @param string $option Option name. |
5 | 998 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
do_action( "update_option_{$option}", $old_value, $value, $option ); |
5 | 1000 |
|
1001 |
/** |
|
1002 |
* Fires after the value of an option has been successfully updated. |
|
1003 |
* |
|
1004 |
* @since 2.9.0 |
|
1005 |
* |
|
1006 |
* @param string $option Name of the updated option. |
|
1007 |
* @param mixed $old_value The old option value. |
|
1008 |
* @param mixed $value The new option value. |
|
1009 |
*/ |
|
0 | 1010 |
do_action( 'updated_option', $option, $old_value, $value ); |
16 | 1011 |
|
0 | 1012 |
return true; |
1013 |
} |
|
1014 |
||
1015 |
/** |
|
16 | 1016 |
* Adds a new option. |
0 | 1017 |
* |
16 | 1018 |
* You do not need to serialize values. If the value needs to be serialized, |
1019 |
* then it will be serialized before it is inserted into the database. |
|
1020 |
* Remember, resources cannot be serialized or added as an option. |
|
0 | 1021 |
* |
1022 |
* You can create options without values and then update the values later. |
|
1023 |
* Existing options will not be updated and checks are performed to ensure that you |
|
1024 |
* aren't adding a protected WordPress option. Care should be taken to not name |
|
1025 |
* options the same as the ones which are protected. |
|
1026 |
* |
|
1027 |
* @since 1.0.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1028 |
* @since 6.6.0 The $autoload parameter's default value was changed to null. |
0 | 1029 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1032 |
* @param string $option Name of the option to add. Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1033 |
* @param mixed $value Optional. Option value. Must be serializable if non-scalar. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1034 |
* Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1035 |
* @param string $deprecated Optional. Description. Not used anymore. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1036 |
* @param bool|null $autoload Optional. Whether to load the option when WordPress starts up. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1037 |
* Accepts a boolean, or `null` to leave the decision up to default heuristics in WordPress. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1038 |
* For backward compatibility 'yes' and 'no' are also accepted. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1039 |
* Autoloading too many options can lead to performance problems, especially if the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1040 |
* options are not frequently used. For options which are accessed across several places |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1041 |
* in the frontend, it is recommended to autoload them, by using 'yes'|true. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1042 |
* For options which are accessed only on few specific URLs, it is recommended |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1043 |
* to not autoload them, by using false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1044 |
* Default is null, which means WordPress will determine the autoload value. |
16 | 1045 |
* @return bool True if the option was added, false otherwise. |
0 | 1046 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1047 |
function add_option( $option, $value = '', $deprecated = '', $autoload = null ) { |
0 | 1048 |
global $wpdb; |
1049 |
||
9 | 1050 |
if ( ! empty( $deprecated ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
_deprecated_argument( __FUNCTION__, '2.3.0' ); |
9 | 1052 |
} |
0 | 1053 |
|
19 | 1054 |
if ( is_scalar( $option ) ) { |
1055 |
$option = trim( $option ); |
|
1056 |
} |
|
1057 |
||
9 | 1058 |
if ( empty( $option ) ) { |
0 | 1059 |
return false; |
9 | 1060 |
} |
0 | 1061 |
|
16 | 1062 |
/* |
1063 |
* Until a proper _deprecated_option() function can be introduced, |
|
1064 |
* redirect requests to deprecated keys to the new, correct ones. |
|
1065 |
*/ |
|
1066 |
$deprecated_keys = array( |
|
1067 |
'blacklist_keys' => 'disallowed_keys', |
|
1068 |
'comment_whitelist' => 'comment_previously_approved', |
|
1069 |
); |
|
1070 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1071 |
if ( isset( $deprecated_keys[ $option ] ) && ! wp_installing() ) { |
16 | 1072 |
_deprecated_argument( |
1073 |
__FUNCTION__, |
|
1074 |
'5.5.0', |
|
1075 |
sprintf( |
|
1076 |
/* translators: 1: Deprecated option key, 2: New option key. */ |
|
1077 |
__( 'The "%1$s" option key has been renamed to "%2$s".' ), |
|
1078 |
$option, |
|
1079 |
$deprecated_keys[ $option ] |
|
1080 |
) |
|
1081 |
); |
|
1082 |
return add_option( $deprecated_keys[ $option ], $value, $deprecated, $autoload ); |
|
1083 |
} |
|
1084 |
||
0 | 1085 |
wp_protect_special_option( $option ); |
1086 |
||
9 | 1087 |
if ( is_object( $value ) ) { |
0 | 1088 |
$value = clone $value; |
9 | 1089 |
} |
0 | 1090 |
|
1091 |
$value = sanitize_option( $option, $value ); |
|
1092 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1093 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1094 |
* Make sure the option doesn't already exist. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1095 |
* We can check the 'notoptions' cache before we ask for a DB query. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1096 |
*/ |
0 | 1097 |
$notoptions = wp_cache_get( 'notoptions', 'options' ); |
16 | 1098 |
|
9 | 1099 |
if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { |
5 | 1100 |
/** This filter is documented in wp-includes/option.php */ |
9 | 1101 |
if ( apply_filters( "default_option_{$option}", false, $option, false ) !== get_option( $option ) ) { |
0 | 1102 |
return false; |
9 | 1103 |
} |
1104 |
} |
|
0 | 1105 |
|
1106 |
$serialized_value = maybe_serialize( $value ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1107 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1108 |
$autoload = wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ); |
5 | 1109 |
|
1110 |
/** |
|
1111 |
* Fires before an option is added. |
|
1112 |
* |
|
1113 |
* @since 2.9.0 |
|
1114 |
* |
|
1115 |
* @param string $option Name of the option to add. |
|
1116 |
* @param mixed $value Value of the option. |
|
1117 |
*/ |
|
0 | 1118 |
do_action( 'add_option', $option, $value ); |
1119 |
||
1120 |
$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 | 1121 |
if ( ! $result ) { |
0 | 1122 |
return false; |
9 | 1123 |
} |
0 | 1124 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
if ( ! wp_installing() ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1126 |
if ( in_array( $autoload, wp_autoload_values_to_autoload(), true ) ) { |
16 | 1127 |
$alloptions = wp_load_alloptions( true ); |
0 | 1128 |
$alloptions[ $option ] = $serialized_value; |
1129 |
wp_cache_set( 'alloptions', $alloptions, 'options' ); |
|
1130 |
} else { |
|
1131 |
wp_cache_set( $option, $serialized_value, 'options' ); |
|
1132 |
} |
|
1133 |
} |
|
1134 |
||
16 | 1135 |
// This option exists now. |
1136 |
$notoptions = wp_cache_get( 'notoptions', 'options' ); // Yes, again... we need it to be fresh. |
|
1137 |
||
9 | 1138 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
1139 |
unset( $notoptions[ $option ] ); |
|
0 | 1140 |
wp_cache_set( 'notoptions', $notoptions, 'options' ); |
1141 |
} |
|
1142 |
||
5 | 1143 |
/** |
1144 |
* Fires after a specific option has been added. |
|
1145 |
* |
|
1146 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1147 |
* |
|
1148 |
* @since 2.5.0 As "add_option_{$name}" |
|
1149 |
* @since 3.0.0 |
|
1150 |
* |
|
1151 |
* @param string $option Name of the option to add. |
|
1152 |
* @param mixed $value Value of the option. |
|
1153 |
*/ |
|
0 | 1154 |
do_action( "add_option_{$option}", $option, $value ); |
5 | 1155 |
|
1156 |
/** |
|
1157 |
* Fires after an option has been added. |
|
1158 |
* |
|
1159 |
* @since 2.9.0 |
|
1160 |
* |
|
1161 |
* @param string $option Name of the added option. |
|
1162 |
* @param mixed $value Value of the option. |
|
1163 |
*/ |
|
0 | 1164 |
do_action( 'added_option', $option, $value ); |
16 | 1165 |
|
0 | 1166 |
return true; |
1167 |
} |
|
1168 |
||
1169 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1170 |
* Removes an option by name. Prevents removal of protected WordPress options. |
0 | 1171 |
* |
1172 |
* @since 1.2.0 |
|
1173 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1175 |
* |
16 | 1176 |
* @param string $option Name of the option to delete. Expected to not be SQL-escaped. |
1177 |
* @return bool True if the option was deleted, false otherwise. |
|
0 | 1178 |
*/ |
1179 |
function delete_option( $option ) { |
|
1180 |
global $wpdb; |
|
1181 |
||
19 | 1182 |
if ( is_scalar( $option ) ) { |
1183 |
$option = trim( $option ); |
|
1184 |
} |
|
1185 |
||
9 | 1186 |
if ( empty( $option ) ) { |
0 | 1187 |
return false; |
9 | 1188 |
} |
0 | 1189 |
|
1190 |
wp_protect_special_option( $option ); |
|
1191 |
||
16 | 1192 |
// Get the ID, if no ID then return. |
0 | 1193 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ); |
9 | 1194 |
if ( is_null( $row ) ) { |
0 | 1195 |
return false; |
9 | 1196 |
} |
5 | 1197 |
|
1198 |
/** |
|
1199 |
* Fires immediately before an option is deleted. |
|
1200 |
* |
|
1201 |
* @since 2.9.0 |
|
1202 |
* |
|
1203 |
* @param string $option Name of the option to delete. |
|
1204 |
*/ |
|
0 | 1205 |
do_action( 'delete_option', $option ); |
5 | 1206 |
|
0 | 1207 |
$result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) ); |
16 | 1208 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1209 |
if ( ! wp_installing() ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1210 |
if ( in_array( $row->autoload, wp_autoload_values_to_autoload(), true ) ) { |
16 | 1211 |
$alloptions = wp_load_alloptions( true ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1212 |
|
9 | 1213 |
if ( is_array( $alloptions ) && isset( $alloptions[ $option ] ) ) { |
1214 |
unset( $alloptions[ $option ] ); |
|
0 | 1215 |
wp_cache_set( 'alloptions', $alloptions, 'options' ); |
1216 |
} |
|
1217 |
} else { |
|
1218 |
wp_cache_delete( $option, 'options' ); |
|
1219 |
} |
|
1220 |
} |
|
16 | 1221 |
|
0 | 1222 |
if ( $result ) { |
5 | 1223 |
|
1224 |
/** |
|
1225 |
* Fires after a specific option has been deleted. |
|
1226 |
* |
|
1227 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1228 |
* |
|
1229 |
* @since 3.0.0 |
|
1230 |
* |
|
1231 |
* @param string $option Name of the deleted option. |
|
1232 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1233 |
do_action( "delete_option_{$option}", $option ); |
5 | 1234 |
|
1235 |
/** |
|
1236 |
* Fires after an option has been deleted. |
|
1237 |
* |
|
1238 |
* @since 2.9.0 |
|
1239 |
* |
|
1240 |
* @param string $option Name of the deleted option. |
|
1241 |
*/ |
|
0 | 1242 |
do_action( 'deleted_option', $option ); |
16 | 1243 |
|
0 | 1244 |
return true; |
1245 |
} |
|
16 | 1246 |
|
0 | 1247 |
return false; |
1248 |
} |
|
1249 |
||
1250 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1251 |
* Determines the appropriate autoload value for an option based on input. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1252 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1253 |
* This function checks the provided autoload value and returns a standardized value |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1254 |
* ('on', 'off', 'auto-on', 'auto-off', or 'auto') based on specific conditions. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1255 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1256 |
* If no explicit autoload value is provided, the function will check for certain heuristics around the given option. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1257 |
* It will return `auto-on` to indicate autoloading, `auto-off` to indicate not autoloading, or `auto` if no clear |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1258 |
* decision could be made. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1259 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1260 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1261 |
* @access private |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1262 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1263 |
* @param string $option The name of the option. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1264 |
* @param mixed $value The value of the option to check its autoload value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1265 |
* @param mixed $serialized_value The serialized value of the option to check its autoload value. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1266 |
* @param bool|null $autoload The autoload value to check. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1267 |
* Accepts 'on'|true to enable or 'off'|false to disable, or |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1268 |
* 'auto-on', 'auto-off', or 'auto' for internal purposes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1269 |
* Any other autoload value will be forced to either 'auto-on', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1270 |
* 'auto-off', or 'auto'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1271 |
* 'yes' and 'no' are supported for backward compatibility. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1272 |
* @return string Returns the original $autoload value if explicit, or 'auto-on', 'auto-off', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1273 |
* or 'auto' depending on default heuristics. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1274 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1275 |
function wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1276 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1277 |
// Check if autoload is a boolean. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1278 |
if ( is_bool( $autoload ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1279 |
return $autoload ? 'on' : 'off'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1280 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1281 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1282 |
switch ( $autoload ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1283 |
case 'on': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1284 |
case 'yes': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1285 |
return 'on'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1286 |
case 'off': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1287 |
case 'no': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1288 |
return 'off'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1289 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1290 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1291 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1292 |
* Allows to determine the default autoload value for an option where no explicit value is passed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1293 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1294 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1295 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1296 |
* @param bool|null $autoload The default autoload value to set. Returning true will be set as 'auto-on' in the |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1297 |
* database, false will be set as 'auto-off', and null will be set as 'auto'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1298 |
* @param string $option The passed option name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1299 |
* @param mixed $value The passed option value to be saved. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1300 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1301 |
$autoload = apply_filters( 'wp_default_autoload_value', null, $option, $value, $serialized_value ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1302 |
if ( is_bool( $autoload ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1303 |
return $autoload ? 'auto-on' : 'auto-off'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1304 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1305 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1306 |
return 'auto'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1307 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1308 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1309 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1310 |
* Filters the default autoload value to disable autoloading if the option value is too large. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1311 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1312 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1313 |
* @access private |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1314 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1315 |
* @param bool|null $autoload The default autoload value to set. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1316 |
* @param string $option The passed option name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1317 |
* @param mixed $value The passed option value to be saved. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1318 |
* @param mixed $serialized_value The passed option value to be saved, in serialized form. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1319 |
* @return bool|null Potentially modified $default. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1320 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1321 |
function wp_filter_default_autoload_value_via_option_size( $autoload, $option, $value, $serialized_value ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1322 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1323 |
* Filters the maximum size of option value in bytes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1324 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1325 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1326 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1327 |
* @param int $max_option_size The option-size threshold, in bytes. Default 150000. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1328 |
* @param string $option The name of the option. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1329 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1330 |
$max_option_size = (int) apply_filters( 'wp_max_autoloaded_option_size', 150000, $option ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1331 |
$size = ! empty( $serialized_value ) ? strlen( $serialized_value ) : 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1332 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1333 |
if ( $size > $max_option_size ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1334 |
return false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1335 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1336 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1337 |
return $autoload; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1338 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1339 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1340 |
/** |
16 | 1341 |
* Deletes a transient. |
0 | 1342 |
* |
1343 |
* @since 2.8.0 |
|
1344 |
* |
|
1345 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
|
16 | 1346 |
* @return bool True if the transient was deleted, false otherwise. |
0 | 1347 |
*/ |
1348 |
function delete_transient( $transient ) { |
|
5 | 1349 |
|
1350 |
/** |
|
1351 |
* Fires immediately before a specific transient is deleted. |
|
1352 |
* |
|
1353 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
1354 |
* |
|
1355 |
* @since 3.0.0 |
|
1356 |
* |
|
1357 |
* @param string $transient Transient name. |
|
1358 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1359 |
do_action( "delete_transient_{$transient}", $transient ); |
0 | 1360 |
|
19 | 1361 |
if ( wp_using_ext_object_cache() || wp_installing() ) { |
0 | 1362 |
$result = wp_cache_delete( $transient, 'transient' ); |
1363 |
} else { |
|
1364 |
$option_timeout = '_transient_timeout_' . $transient; |
|
9 | 1365 |
$option = '_transient_' . $transient; |
1366 |
$result = delete_option( $option ); |
|
16 | 1367 |
|
9 | 1368 |
if ( $result ) { |
0 | 1369 |
delete_option( $option_timeout ); |
9 | 1370 |
} |
0 | 1371 |
} |
1372 |
||
5 | 1373 |
if ( $result ) { |
1374 |
||
1375 |
/** |
|
1376 |
* Fires after a transient is deleted. |
|
1377 |
* |
|
1378 |
* @since 3.0.0 |
|
1379 |
* |
|
1380 |
* @param string $transient Deleted transient name. |
|
1381 |
*/ |
|
0 | 1382 |
do_action( 'deleted_transient', $transient ); |
5 | 1383 |
} |
1384 |
||
0 | 1385 |
return $result; |
1386 |
} |
|
1387 |
||
1388 |
/** |
|
16 | 1389 |
* Retrieves the value of a transient. |
0 | 1390 |
* |
5 | 1391 |
* If the transient does not exist, does not have a value, or has expired, |
1392 |
* then the return value will be false. |
|
0 | 1393 |
* |
1394 |
* @since 2.8.0 |
|
1395 |
* |
|
5 | 1396 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
1397 |
* @return mixed Value of transient. |
|
0 | 1398 |
*/ |
1399 |
function get_transient( $transient ) { |
|
5 | 1400 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1401 |
/** |
16 | 1402 |
* Filters the value of an existing transient before it is retrieved. |
5 | 1403 |
* |
1404 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
1405 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1406 |
* Returning a value other than false from the filter will short-circuit retrieval |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1407 |
* and return that value instead. |
5 | 1408 |
* |
1409 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1410 |
* @since 4.4.0 The `$transient` parameter was added |
5 | 1411 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1412 |
* @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
|
1413 |
* Any value other than false will short-circuit the retrieval |
16 | 1414 |
* of the transient, and return that value. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1415 |
* @param string $transient Transient name. |
5 | 1416 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1417 |
$pre = apply_filters( "pre_transient_{$transient}", false, $transient ); |
16 | 1418 |
|
9 | 1419 |
if ( false !== $pre ) { |
0 | 1420 |
return $pre; |
9 | 1421 |
} |
0 | 1422 |
|
19 | 1423 |
if ( wp_using_ext_object_cache() || wp_installing() ) { |
0 | 1424 |
$value = wp_cache_get( $transient, 'transient' ); |
1425 |
} else { |
|
1426 |
$transient_option = '_transient_' . $transient; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1427 |
if ( ! wp_installing() ) { |
16 | 1428 |
// If option is not in alloptions, it is not autoloaded and thus has a timeout. |
0 | 1429 |
$alloptions = wp_load_alloptions(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1430 |
|
9 | 1431 |
if ( ! isset( $alloptions[ $transient_option ] ) ) { |
0 | 1432 |
$transient_timeout = '_transient_timeout_' . $transient; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1433 |
wp_prime_option_caches( array( $transient_option, $transient_timeout ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1434 |
$timeout = get_option( $transient_timeout ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1435 |
if ( false !== $timeout && $timeout < time() ) { |
9 | 1436 |
delete_option( $transient_option ); |
0 | 1437 |
delete_option( $transient_timeout ); |
1438 |
$value = false; |
|
1439 |
} |
|
1440 |
} |
|
1441 |
} |
|
1442 |
||
9 | 1443 |
if ( ! isset( $value ) ) { |
0 | 1444 |
$value = get_option( $transient_option ); |
9 | 1445 |
} |
0 | 1446 |
} |
1447 |
||
5 | 1448 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1449 |
* Filters an existing transient's value. |
5 | 1450 |
* |
1451 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
1452 |
* |
|
1453 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1454 |
* @since 4.4.0 The `$transient` parameter was added |
5 | 1455 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1456 |
* @param mixed $value Value of transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1457 |
* @param string $transient Transient name. |
5 | 1458 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1459 |
return apply_filters( "transient_{$transient}", $value, $transient ); |
0 | 1460 |
} |
1461 |
||
1462 |
/** |
|
16 | 1463 |
* Sets/updates the value of a transient. |
0 | 1464 |
* |
16 | 1465 |
* You do not need to serialize values. If the value needs to be serialized, |
1466 |
* then it will be serialized before it is set. |
|
0 | 1467 |
* |
1468 |
* @since 2.8.0 |
|
1469 |
* |
|
16 | 1470 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
1471 |
* Must be 172 characters or fewer in length. |
|
5 | 1472 |
* @param mixed $value Transient value. Must be serializable if non-scalar. |
1473 |
* Expected to not be SQL-escaped. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1474 |
* @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration). |
16 | 1475 |
* @return bool True if the value was set, false otherwise. |
0 | 1476 |
*/ |
1477 |
function set_transient( $transient, $value, $expiration = 0 ) { |
|
5 | 1478 |
|
0 | 1479 |
$expiration = (int) $expiration; |
1480 |
||
5 | 1481 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1482 |
* Filters a specific transient before its value is set. |
5 | 1483 |
* |
1484 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
1485 |
* |
|
1486 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1487 |
* @since 4.2.0 The `$expiration` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1488 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 1489 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1490 |
* @param mixed $value New value of transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1491 |
* @param int $expiration Time until expiration in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1492 |
* @param string $transient Transient name. |
5 | 1493 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1494 |
$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
|
1495 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1496 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1497 |
* 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
|
1498 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1499 |
* 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
|
1500 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1501 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1502 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1503 |
* @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
|
1504 |
* @param mixed $value New value of transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1505 |
* @param string $transient Transient name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1506 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1507 |
$expiration = apply_filters( "expiration_of_transient_{$transient}", $expiration, $value, $transient ); |
5 | 1508 |
|
19 | 1509 |
if ( wp_using_ext_object_cache() || wp_installing() ) { |
0 | 1510 |
$result = wp_cache_set( $transient, $value, 'transient', $expiration ); |
1511 |
} else { |
|
1512 |
$transient_timeout = '_transient_timeout_' . $transient; |
|
9 | 1513 |
$transient_option = '_transient_' . $transient; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1514 |
wp_prime_option_caches( array( $transient_option, $transient_timeout ) ); |
16 | 1515 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1516 |
if ( false === get_option( $transient_option ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1517 |
$autoload = true; |
0 | 1518 |
if ( $expiration ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1519 |
$autoload = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1520 |
add_option( $transient_timeout, time() + $expiration, '', false ); |
0 | 1521 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1522 |
$result = add_option( $transient_option, $value, '', $autoload ); |
0 | 1523 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1524 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1525 |
* If expiration is requested, but the transient has no timeout option, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1526 |
* delete, then re-create transient rather than update. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1527 |
*/ |
5 | 1528 |
$update = true; |
16 | 1529 |
|
5 | 1530 |
if ( $expiration ) { |
1531 |
if ( false === get_option( $transient_timeout ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1532 |
delete_option( $transient_option ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1533 |
add_option( $transient_timeout, time() + $expiration, '', false ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1534 |
$result = add_option( $transient_option, $value, '', false ); |
5 | 1535 |
$update = false; |
1536 |
} else { |
|
1537 |
update_option( $transient_timeout, time() + $expiration ); |
|
1538 |
} |
|
1539 |
} |
|
16 | 1540 |
|
5 | 1541 |
if ( $update ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1542 |
$result = update_option( $transient_option, $value ); |
5 | 1543 |
} |
0 | 1544 |
} |
1545 |
} |
|
5 | 1546 |
|
0 | 1547 |
if ( $result ) { |
5 | 1548 |
|
1549 |
/** |
|
1550 |
* Fires after the value for a specific transient has been set. |
|
1551 |
* |
|
1552 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
1553 |
* |
|
1554 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1555 |
* @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
|
1556 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 1557 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1558 |
* @param mixed $value Transient value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1559 |
* @param int $expiration Time until expiration in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1560 |
* @param string $transient The name of the transient. |
5 | 1561 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1562 |
do_action( "set_transient_{$transient}", $value, $expiration, $transient ); |
5 | 1563 |
|
1564 |
/** |
|
1565 |
* Fires after the value for a transient has been set. |
|
1566 |
* |
|
1567 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1568 |
* @since 3.6.0 The `$value` and `$expiration` parameters were added. |
5 | 1569 |
* |
1570 |
* @param string $transient The name of the transient. |
|
1571 |
* @param mixed $value Transient value. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1572 |
* @param int $expiration Time until expiration in seconds. |
5 | 1573 |
*/ |
0 | 1574 |
do_action( 'setted_transient', $transient, $value, $expiration ); |
1575 |
} |
|
16 | 1576 |
|
0 | 1577 |
return $result; |
1578 |
} |
|
1579 |
||
1580 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1581 |
* Deletes all expired transients. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1582 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1583 |
* Note that this function won't do anything if an external object cache is in use. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1584 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1585 |
* 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
|
1586 |
* 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
|
1587 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1588 |
* @global wpdb $wpdb WordPress database abstraction object. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1589 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1590 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1591 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1592 |
* @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
|
1593 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1594 |
function delete_expired_transients( $force_db = false ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1595 |
global $wpdb; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1596 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1597 |
if ( ! $force_db && wp_using_ext_object_cache() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1598 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1599 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1600 |
|
9 | 1601 |
$wpdb->query( |
1602 |
$wpdb->prepare( |
|
1603 |
"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
|
1604 |
WHERE a.option_name LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1605 |
AND a.option_name NOT LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1606 |
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
|
1607 |
AND b.option_value < %d", |
9 | 1608 |
$wpdb->esc_like( '_transient_' ) . '%', |
1609 |
$wpdb->esc_like( '_transient_timeout_' ) . '%', |
|
1610 |
time() |
|
1611 |
) |
|
1612 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1613 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1614 |
if ( ! is_multisite() ) { |
16 | 1615 |
// Single site stores site transients in the options table. |
9 | 1616 |
$wpdb->query( |
1617 |
$wpdb->prepare( |
|
1618 |
"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
|
1619 |
WHERE a.option_name LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1620 |
AND a.option_name NOT LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1621 |
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
|
1622 |
AND b.option_value < %d", |
9 | 1623 |
$wpdb->esc_like( '_site_transient_' ) . '%', |
1624 |
$wpdb->esc_like( '_site_transient_timeout_' ) . '%', |
|
1625 |
time() |
|
1626 |
) |
|
1627 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1628 |
} elseif ( is_multisite() && is_main_site() && is_main_network() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1629 |
// Multisite stores site transients in the sitemeta table. |
9 | 1630 |
$wpdb->query( |
1631 |
$wpdb->prepare( |
|
1632 |
"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
|
1633 |
WHERE a.meta_key LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1634 |
AND a.meta_key NOT LIKE %s |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1635 |
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
|
1636 |
AND b.meta_value < %d", |
9 | 1637 |
$wpdb->esc_like( '_site_transient_' ) . '%', |
1638 |
$wpdb->esc_like( '_site_transient_timeout_' ) . '%', |
|
1639 |
time() |
|
1640 |
) |
|
1641 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1642 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1643 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1644 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1645 |
/** |
0 | 1646 |
* Saves and restores user interface settings stored in a cookie. |
1647 |
* |
|
1648 |
* Checks if the current user-settings cookie is updated and stores it. When no |
|
1649 |
* cookie exists (different browser used), adds the last saved cookie restoring |
|
1650 |
* the settings. |
|
1651 |
* |
|
1652 |
* @since 2.7.0 |
|
1653 |
*/ |
|
1654 |
function wp_user_settings() { |
|
1655 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1656 |
if ( ! is_admin() || wp_doing_ajax() ) { |
0 | 1657 |
return; |
5 | 1658 |
} |
0 | 1659 |
|
16 | 1660 |
$user_id = get_current_user_id(); |
1661 |
if ( ! $user_id ) { |
|
0 | 1662 |
return; |
5 | 1663 |
} |
0 | 1664 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1665 |
if ( ! is_user_member_of_blog() ) { |
0 | 1666 |
return; |
5 | 1667 |
} |
0 | 1668 |
|
1669 |
$settings = (string) get_user_option( 'user-settings', $user_id ); |
|
1670 |
||
9 | 1671 |
if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) { |
1672 |
$cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] ); |
|
0 | 1673 |
|
16 | 1674 |
// No change or both empty. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1675 |
if ( $cookie === $settings ) { |
0 | 1676 |
return; |
9 | 1677 |
} |
0 | 1678 |
|
1679 |
$last_saved = (int) get_user_option( 'user-settings-time', $user_id ); |
|
9 | 1680 |
$current = isset( $_COOKIE[ 'wp-settings-time-' . $user_id ] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE[ 'wp-settings-time-' . $user_id ] ) : 0; |
0 | 1681 |
|
16 | 1682 |
// The cookie is newer than the saved value. Update the user_option and leave the cookie as-is. |
0 | 1683 |
if ( $current > $last_saved ) { |
1684 |
update_user_option( $user_id, 'user-settings', $cookie, false ); |
|
1685 |
update_user_option( $user_id, 'user-settings-time', time() - 5, false ); |
|
1686 |
return; |
|
1687 |
} |
|
1688 |
} |
|
1689 |
||
1690 |
// 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
|
1691 |
$secure = ( 'https' === parse_url( admin_url(), PHP_URL_SCHEME ) ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1692 |
setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, '', $secure ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1693 |
setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, '', $secure ); |
9 | 1694 |
$_COOKIE[ 'wp-settings-' . $user_id ] = $settings; |
0 | 1695 |
} |
1696 |
||
1697 |
/** |
|
16 | 1698 |
* Retrieves user interface setting value based on setting name. |
0 | 1699 |
* |
1700 |
* @since 2.7.0 |
|
1701 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1702 |
* @param string $name The name of the setting. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1703 |
* @param string|false $default_value Optional. Default value to return when $name is not set. Default false. |
16 | 1704 |
* @return mixed The last saved user setting or the default value/false if it doesn't exist. |
0 | 1705 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1706 |
function get_user_setting( $name, $default_value = false ) { |
0 | 1707 |
$all_user_settings = get_all_user_settings(); |
1708 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1709 |
return isset( $all_user_settings[ $name ] ) ? $all_user_settings[ $name ] : $default_value; |
0 | 1710 |
} |
1711 |
||
1712 |
/** |
|
16 | 1713 |
* Adds or updates user interface setting. |
0 | 1714 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1715 |
* 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
|
1716 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1717 |
* This function has to be used before any output has started as it calls `setcookie()`. |
0 | 1718 |
* |
1719 |
* @since 2.8.0 |
|
1720 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1721 |
* @param string $name The name of the setting. |
0 | 1722 |
* @param string $value The value for the setting. |
16 | 1723 |
* @return bool|null True if set successfully, false otherwise. |
1724 |
* Null if the current user is not a member of the site. |
|
0 | 1725 |
*/ |
1726 |
function set_user_setting( $name, $value ) { |
|
5 | 1727 |
if ( headers_sent() ) { |
0 | 1728 |
return false; |
5 | 1729 |
} |
0 | 1730 |
|
9 | 1731 |
$all_user_settings = get_all_user_settings(); |
1732 |
$all_user_settings[ $name ] = $value; |
|
0 | 1733 |
|
1734 |
return wp_set_all_user_settings( $all_user_settings ); |
|
1735 |
} |
|
1736 |
||
1737 |
/** |
|
16 | 1738 |
* Deletes user interface settings. |
0 | 1739 |
* |
1740 |
* Deleting settings would reset them to the defaults. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1741 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1742 |
* This function has to be used before any output has started as it calls `setcookie()`. |
0 | 1743 |
* |
1744 |
* @since 2.7.0 |
|
1745 |
* |
|
5 | 1746 |
* @param string $names The name or array of names of the setting to be deleted. |
16 | 1747 |
* @return bool|null True if deleted successfully, false otherwise. |
1748 |
* Null if the current user is not a member of the site. |
|
0 | 1749 |
*/ |
1750 |
function delete_user_setting( $names ) { |
|
5 | 1751 |
if ( headers_sent() ) { |
0 | 1752 |
return false; |
5 | 1753 |
} |
0 | 1754 |
|
1755 |
$all_user_settings = get_all_user_settings(); |
|
9 | 1756 |
$names = (array) $names; |
1757 |
$deleted = false; |
|
0 | 1758 |
|
1759 |
foreach ( $names as $name ) { |
|
9 | 1760 |
if ( isset( $all_user_settings[ $name ] ) ) { |
1761 |
unset( $all_user_settings[ $name ] ); |
|
0 | 1762 |
$deleted = true; |
1763 |
} |
|
1764 |
} |
|
1765 |
||
5 | 1766 |
if ( $deleted ) { |
0 | 1767 |
return wp_set_all_user_settings( $all_user_settings ); |
5 | 1768 |
} |
0 | 1769 |
|
1770 |
return false; |
|
1771 |
} |
|
1772 |
||
1773 |
/** |
|
16 | 1774 |
* Retrieves all user interface settings. |
0 | 1775 |
* |
1776 |
* @since 2.7.0 |
|
1777 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1778 |
* @global array $_updated_user_settings |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1779 |
* |
16 | 1780 |
* @return array The last saved user settings or empty array. |
0 | 1781 |
*/ |
1782 |
function get_all_user_settings() { |
|
1783 |
global $_updated_user_settings; |
|
1784 |
||
16 | 1785 |
$user_id = get_current_user_id(); |
1786 |
if ( ! $user_id ) { |
|
0 | 1787 |
return array(); |
5 | 1788 |
} |
0 | 1789 |
|
5 | 1790 |
if ( isset( $_updated_user_settings ) && is_array( $_updated_user_settings ) ) { |
0 | 1791 |
return $_updated_user_settings; |
5 | 1792 |
} |
0 | 1793 |
|
1794 |
$user_settings = array(); |
|
5 | 1795 |
|
9 | 1796 |
if ( isset( $_COOKIE[ 'wp-settings-' . $user_id ] ) ) { |
1797 |
$cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE[ 'wp-settings-' . $user_id ] ); |
|
0 | 1798 |
|
16 | 1799 |
if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char. |
0 | 1800 |
parse_str( $cookie, $user_settings ); |
5 | 1801 |
} |
0 | 1802 |
} else { |
1803 |
$option = get_user_option( 'user-settings', $user_id ); |
|
5 | 1804 |
|
1805 |
if ( $option && is_string( $option ) ) { |
|
0 | 1806 |
parse_str( $option, $user_settings ); |
5 | 1807 |
} |
0 | 1808 |
} |
1809 |
||
1810 |
$_updated_user_settings = $user_settings; |
|
1811 |
return $user_settings; |
|
1812 |
} |
|
1813 |
||
1814 |
/** |
|
16 | 1815 |
* Private. Sets all user interface settings. |
0 | 1816 |
* |
1817 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1818 |
* @access private |
0 | 1819 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1820 |
* @global array $_updated_user_settings |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1821 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1822 |
* @param array $user_settings User settings. |
16 | 1823 |
* @return bool|null True if set successfully, false if the current user could not be found. |
1824 |
* Null if the current user is not a member of the site. |
|
0 | 1825 |
*/ |
1826 |
function wp_set_all_user_settings( $user_settings ) { |
|
1827 |
global $_updated_user_settings; |
|
1828 |
||
16 | 1829 |
$user_id = get_current_user_id(); |
1830 |
if ( ! $user_id ) { |
|
0 | 1831 |
return false; |
5 | 1832 |
} |
0 | 1833 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1834 |
if ( ! is_user_member_of_blog() ) { |
0 | 1835 |
return; |
5 | 1836 |
} |
0 | 1837 |
|
1838 |
$settings = ''; |
|
1839 |
foreach ( $user_settings as $name => $value ) { |
|
9 | 1840 |
$_name = preg_replace( '/[^A-Za-z0-9_-]+/', '', $name ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1841 |
$_value = preg_replace( '/[^A-Za-z0-9_-]+/', '', $value ); |
0 | 1842 |
|
5 | 1843 |
if ( ! empty( $_name ) ) { |
0 | 1844 |
$settings .= $_name . '=' . $_value . '&'; |
5 | 1845 |
} |
0 | 1846 |
} |
1847 |
||
5 | 1848 |
$settings = rtrim( $settings, '&' ); |
0 | 1849 |
parse_str( $settings, $_updated_user_settings ); |
1850 |
||
1851 |
update_user_option( $user_id, 'user-settings', $settings, false ); |
|
1852 |
update_user_option( $user_id, 'user-settings-time', time(), false ); |
|
1853 |
||
1854 |
return true; |
|
1855 |
} |
|
1856 |
||
1857 |
/** |
|
16 | 1858 |
* Deletes the user settings of the current user. |
0 | 1859 |
* |
1860 |
* @since 2.7.0 |
|
1861 |
*/ |
|
1862 |
function delete_all_user_settings() { |
|
16 | 1863 |
$user_id = get_current_user_id(); |
1864 |
if ( ! $user_id ) { |
|
0 | 1865 |
return; |
5 | 1866 |
} |
0 | 1867 |
|
1868 |
update_user_option( $user_id, 'user-settings', '', false ); |
|
5 | 1869 |
setcookie( 'wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH ); |
0 | 1870 |
} |
1871 |
||
1872 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1873 |
* 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
|
1874 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1875 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1876 |
* @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
|
1877 |
* @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
|
1878 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1879 |
* @see get_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1880 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1881 |
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1882 |
* @param mixed $default_value Optional. Value to return if the option doesn't exist. Default false. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1883 |
* @param bool $deprecated Whether to use cache. Multisite only. Always set to true. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1884 |
* @return mixed Value set for the option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1885 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1886 |
function get_site_option( $option, $default_value = false, $deprecated = true ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1887 |
return get_network_option( null, $option, $default_value ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1888 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1889 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1890 |
/** |
16 | 1891 |
* Adds a new option for the current network. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1892 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1893 |
* Existing options will not be updated. Note that prior to 3.3 this wasn't the case. |
0 | 1894 |
* |
1895 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1896 |
* @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
|
1897 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1898 |
* @see add_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1899 |
* |
16 | 1900 |
* @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
|
1901 |
* @param mixed $value Option value, can be anything. Expected to not be SQL-escaped. |
16 | 1902 |
* @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
|
1903 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1904 |
function add_site_option( $option, $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1905 |
return add_network_option( null, $option, $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1906 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1907 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1908 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1909 |
* Removes an option by name for the current network. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1910 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1911 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1912 |
* @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
|
1913 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1914 |
* @see delete_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1915 |
* |
16 | 1916 |
* @param string $option Name of the option to delete. Expected to not be SQL-escaped. |
1917 |
* @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
|
1918 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1919 |
function delete_site_option( $option ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1920 |
return delete_network_option( null, $option ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1921 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1922 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1923 |
/** |
16 | 1924 |
* 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
|
1925 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1926 |
* @since 2.8.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1927 |
* @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
|
1928 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1929 |
* @see update_network_option() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1930 |
* |
16 | 1931 |
* @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
|
1932 |
* @param mixed $value Option value. Expected to not be SQL-escaped. |
16 | 1933 |
* @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
|
1934 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1935 |
function update_site_option( $option, $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1936 |
return update_network_option( null, $option, $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1937 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1938 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1939 |
/** |
16 | 1940 |
* 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
|
1941 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1942 |
* @since 4.4.0 |
0 | 1943 |
* |
5 | 1944 |
* @see get_option() |
0 | 1945 |
* |
9 | 1946 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1947 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1948 |
* @param int $network_id ID of the network. Can be null to default to the current network ID. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1949 |
* @param string $option Name of the option to retrieve. Expected to not be SQL-escaped. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1950 |
* @param mixed $default_value Optional. Value to return if the option doesn't exist. Default false. |
0 | 1951 |
* @return mixed Value set for the option. |
1952 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1953 |
function get_network_option( $network_id, $option, $default_value = false ) { |
0 | 1954 |
global $wpdb; |
1955 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1956 |
if ( $network_id && ! is_numeric( $network_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1957 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1958 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1959 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1960 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1961 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1962 |
// 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
|
1963 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1964 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1965 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1966 |
|
5 | 1967 |
/** |
16 | 1968 |
* Filters the value of an existing network option before it is retrieved. |
5 | 1969 |
* |
1970 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
1971 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1972 |
* Returning a value other than false from the filter will short-circuit retrieval |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1973 |
* and return that value instead. |
5 | 1974 |
* |
1975 |
* @since 2.9.0 As 'pre_site_option_' . $key |
|
1976 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1977 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1978 |
* @since 4.7.0 The `$network_id` parameter was added. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1979 |
* @since 4.9.0 The `$default_value` parameter was added. |
5 | 1980 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1981 |
* @param mixed $pre_option The value to return instead of the option value. This differs from |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1982 |
* `$default_value`, which is used as the fallback value in the event |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1983 |
* the option doesn't exist elsewhere in get_network_option(). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1984 |
* Default false (to skip past the short-circuit). |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1985 |
* @param string $option Option name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1986 |
* @param int $network_id ID of the network. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1987 |
* @param mixed $default_value The fallback value to return if the option does not exist. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1988 |
* Default false. |
5 | 1989 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1990 |
$pre = apply_filters( "pre_site_option_{$option}", false, $option, $network_id, $default_value ); |
5 | 1991 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1992 |
if ( false !== $pre ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1993 |
return $pre; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1994 |
} |
0 | 1995 |
|
16 | 1996 |
// Prevent non-existent options from triggering multiple queries. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1997 |
$notoptions_key = "$network_id:notoptions"; |
9 | 1998 |
$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); |
5 | 1999 |
|
9 | 2000 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
5 | 2001 |
|
2002 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2003 |
* Filters the value of a specific default network option. |
5 | 2004 |
* |
2005 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
2006 |
* |
|
2007 |
* @since 3.4.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2008 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2009 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2010 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2011 |
* @param mixed $default_value The value to return if the site option does not exist |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2012 |
* in the database. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2013 |
* @param string $option Option name. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2014 |
* @param int $network_id ID of the network. |
5 | 2015 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2016 |
return apply_filters( "default_site_option_{$option}", $default_value, $option, $network_id ); |
5 | 2017 |
} |
0 | 2018 |
|
2019 |
if ( ! is_multisite() ) { |
|
5 | 2020 |
/** This filter is documented in wp-includes/option.php */ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2021 |
$default_value = apply_filters( 'default_site_option_' . $option, $default_value, $option, $network_id ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2022 |
$value = get_option( $option, $default_value ); |
0 | 2023 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2024 |
$cache_key = "$network_id:$option"; |
9 | 2025 |
$value = wp_cache_get( $cache_key, 'site-options' ); |
0 | 2026 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2027 |
if ( ! isset( $value ) || false === $value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2028 |
$row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_value FROM $wpdb->sitemeta WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); |
0 | 2029 |
|
16 | 2030 |
// Has to be get_row() instead of get_var() because of funkiness with 0, false, null values. |
0 | 2031 |
if ( is_object( $row ) ) { |
2032 |
$value = $row->meta_value; |
|
2033 |
$value = maybe_unserialize( $value ); |
|
2034 |
wp_cache_set( $cache_key, $value, 'site-options' ); |
|
2035 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2036 |
if ( ! is_array( $notoptions ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2037 |
$notoptions = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2038 |
} |
16 | 2039 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2040 |
$notoptions[ $option ] = true; |
5 | 2041 |
wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); |
2042 |
||
2043 |
/** This filter is documented in wp-includes/option.php */ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2044 |
$value = apply_filters( 'default_site_option_' . $option, $default_value, $option, $network_id ); |
0 | 2045 |
} |
2046 |
} |
|
2047 |
} |
|
2048 |
||
9 | 2049 |
if ( ! is_array( $notoptions ) ) { |
2050 |
$notoptions = array(); |
|
2051 |
wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); |
|
2052 |
} |
|
2053 |
||
5 | 2054 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2055 |
* Filters the value of an existing network option. |
5 | 2056 |
* |
2057 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
2058 |
* |
|
2059 |
* @since 2.9.0 As 'site_option_' . $key |
|
2060 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2061 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2062 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2063 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2064 |
* @param mixed $value Value of network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2065 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2066 |
* @param int $network_id ID of the network. |
5 | 2067 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2068 |
return apply_filters( "site_option_{$option}", $value, $option, $network_id ); |
0 | 2069 |
} |
2070 |
||
2071 |
/** |
|
16 | 2072 |
* Adds a new network option. |
0 | 2073 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2074 |
* Existing options will not be updated. |
0 | 2075 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2076 |
* @since 4.4.0 |
0 | 2077 |
* |
5 | 2078 |
* @see add_option() |
0 | 2079 |
* |
9 | 2080 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2081 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2082 |
* @param int $network_id ID of the network. Can be null to default to the current network ID. |
16 | 2083 |
* @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
|
2084 |
* @param mixed $value Option value, can be anything. Expected to not be SQL-escaped. |
16 | 2085 |
* @return bool True if the option was added, false otherwise. |
0 | 2086 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2087 |
function add_network_option( $network_id, $option, $value ) { |
0 | 2088 |
global $wpdb; |
2089 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2090 |
if ( $network_id && ! is_numeric( $network_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2091 |
return false; |
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 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2095 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2096 |
// 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
|
2097 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2098 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2099 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2100 |
|
0 | 2101 |
wp_protect_special_option( $option ); |
2102 |
||
5 | 2103 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2104 |
* Filters the value of a specific network option before it is added. |
5 | 2105 |
* |
2106 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
2107 |
* |
|
2108 |
* @since 2.9.0 As 'pre_add_site_option_' . $key |
|
2109 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2110 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2111 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2112 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2113 |
* @param mixed $value Value of network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2114 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2115 |
* @param int $network_id ID of the network. |
5 | 2116 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2117 |
$value = apply_filters( "pre_add_site_option_{$option}", $value, $option, $network_id ); |
0 | 2118 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2119 |
$notoptions_key = "$network_id:notoptions"; |
5 | 2120 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2121 |
if ( ! is_multisite() ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2122 |
$result = add_option( $option, $value, '', false ); |
0 | 2123 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2124 |
$cache_key = "$network_id:$option"; |
0 | 2125 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2126 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2127 |
* Make sure the option doesn't already exist. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2128 |
* We can check the 'notoptions' cache before we ask for a DB query. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2129 |
*/ |
5 | 2130 |
$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); |
16 | 2131 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2132 |
if ( ! is_array( $notoptions ) || ! isset( $notoptions[ $option ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2133 |
if ( false !== get_network_option( $network_id, $option, false ) ) { |
0 | 2134 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2135 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2136 |
} |
0 | 2137 |
|
2138 |
$value = sanitize_option( $option, $value ); |
|
2139 |
||
2140 |
$serialized_value = maybe_serialize( $value ); |
|
9 | 2141 |
$result = $wpdb->insert( |
2142 |
$wpdb->sitemeta, |
|
2143 |
array( |
|
2144 |
'site_id' => $network_id, |
|
2145 |
'meta_key' => $option, |
|
2146 |
'meta_value' => $serialized_value, |
|
2147 |
) |
|
2148 |
); |
|
0 | 2149 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2150 |
if ( ! $result ) { |
0 | 2151 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2152 |
} |
0 | 2153 |
|
2154 |
wp_cache_set( $cache_key, $value, 'site-options' ); |
|
2155 |
||
16 | 2156 |
// This option exists now. |
2157 |
$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); // Yes, again... we need it to be fresh. |
|
2158 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2159 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2160 |
unset( $notoptions[ $option ] ); |
5 | 2161 |
wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); |
0 | 2162 |
} |
2163 |
} |
|
2164 |
||
2165 |
if ( $result ) { |
|
5 | 2166 |
|
2167 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2168 |
* Fires after a specific network option has been successfully added. |
5 | 2169 |
* |
2170 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
2171 |
* |
|
2172 |
* @since 2.9.0 As "add_site_option_{$key}" |
|
2173 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2174 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2175 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2176 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2177 |
* @param mixed $value Value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2178 |
* @param int $network_id ID of the network. |
5 | 2179 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2180 |
do_action( "add_site_option_{$option}", $option, $value, $network_id ); |
5 | 2181 |
|
2182 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2183 |
* Fires after a network option has been successfully added. |
5 | 2184 |
* |
2185 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2186 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2187 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2188 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2189 |
* @param mixed $value Value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2190 |
* @param int $network_id ID of the network. |
5 | 2191 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2192 |
do_action( 'add_site_option', $option, $value, $network_id ); |
5 | 2193 |
|
0 | 2194 |
return true; |
2195 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2196 |
|
0 | 2197 |
return false; |
2198 |
} |
|
2199 |
||
2200 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2201 |
* Removes a network option by name. |
0 | 2202 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2203 |
* @since 4.4.0 |
0 | 2204 |
* |
5 | 2205 |
* @see delete_option() |
0 | 2206 |
* |
9 | 2207 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2208 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2209 |
* @param int $network_id ID of the network. Can be null to default to the current network ID. |
16 | 2210 |
* @param string $option Name of the option to delete. Expected to not be SQL-escaped. |
2211 |
* @return bool True if the option was deleted, false otherwise. |
|
0 | 2212 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2213 |
function delete_network_option( $network_id, $option ) { |
0 | 2214 |
global $wpdb; |
2215 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2216 |
if ( $network_id && ! is_numeric( $network_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2217 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2218 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2219 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2220 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2221 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2222 |
// 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
|
2223 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2224 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2225 |
} |
0 | 2226 |
|
5 | 2227 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2228 |
* Fires immediately before a specific network option is deleted. |
5 | 2229 |
* |
2230 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
2231 |
* |
|
2232 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2233 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2234 |
* @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
|
2235 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2236 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2237 |
* @param int $network_id ID of the network. |
5 | 2238 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2239 |
do_action( "pre_delete_site_option_{$option}", $option, $network_id ); |
0 | 2240 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2241 |
if ( ! is_multisite() ) { |
0 | 2242 |
$result = delete_option( $option ); |
2243 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2244 |
$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
|
2245 |
if ( is_null( $row ) || ! $row->meta_id ) { |
0 | 2246 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2247 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2248 |
$cache_key = "$network_id:$option"; |
0 | 2249 |
wp_cache_delete( $cache_key, 'site-options' ); |
2250 |
||
9 | 2251 |
$result = $wpdb->delete( |
2252 |
$wpdb->sitemeta, |
|
2253 |
array( |
|
2254 |
'meta_key' => $option, |
|
2255 |
'site_id' => $network_id, |
|
2256 |
) |
|
2257 |
); |
|
0 | 2258 |
} |
2259 |
||
2260 |
if ( $result ) { |
|
5 | 2261 |
|
2262 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2263 |
* Fires after a specific network option has been deleted. |
5 | 2264 |
* |
2265 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
2266 |
* |
|
2267 |
* @since 2.9.0 As "delete_site_option_{$key}" |
|
2268 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2269 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2270 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2271 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2272 |
* @param int $network_id ID of the network. |
5 | 2273 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2274 |
do_action( "delete_site_option_{$option}", $option, $network_id ); |
5 | 2275 |
|
2276 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2277 |
* Fires after a network option has been deleted. |
5 | 2278 |
* |
2279 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2280 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2281 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2282 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2283 |
* @param int $network_id ID of the network. |
5 | 2284 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2285 |
do_action( 'delete_site_option', $option, $network_id ); |
5 | 2286 |
|
0 | 2287 |
return true; |
2288 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2289 |
|
0 | 2290 |
return false; |
2291 |
} |
|
2292 |
||
2293 |
/** |
|
16 | 2294 |
* Updates the value of a network option that was already added. |
0 | 2295 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2296 |
* @since 4.4.0 |
5 | 2297 |
* |
0 | 2298 |
* @see update_option() |
2299 |
* |
|
9 | 2300 |
* @global wpdb $wpdb WordPress database abstraction object. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2301 |
* |
16 | 2302 |
* @param int $network_id ID of the network. Can be null to default to the current network ID. |
2303 |
* @param string $option Name of the option. Expected to not be SQL-escaped. |
|
2304 |
* @param mixed $value Option value. Expected to not be SQL-escaped. |
|
2305 |
* @return bool True if the value was updated, false otherwise. |
|
0 | 2306 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2307 |
function update_network_option( $network_id, $option, $value ) { |
0 | 2308 |
global $wpdb; |
2309 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2310 |
if ( $network_id && ! is_numeric( $network_id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2311 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2312 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2313 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2314 |
$network_id = (int) $network_id; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2315 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2316 |
// 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
|
2317 |
if ( ! $network_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2318 |
$network_id = get_current_network_id(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2319 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2320 |
|
0 | 2321 |
wp_protect_special_option( $option ); |
2322 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2323 |
$old_value = get_network_option( $network_id, $option ); |
5 | 2324 |
|
2325 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2326 |
* Filters a specific network option before its value is updated. |
5 | 2327 |
* |
2328 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
2329 |
* |
|
2330 |
* @since 2.9.0 As 'pre_update_site_option_' . $key |
|
2331 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2332 |
* @since 4.4.0 The `$option` parameter was added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2333 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2334 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2335 |
* @param mixed $value New value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2336 |
* @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
|
2337 |
* @param string $option Option name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2338 |
* @param int $network_id ID of the network. |
5 | 2339 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2340 |
$value = apply_filters( "pre_update_site_option_{$option}", $value, $old_value, $option, $network_id ); |
0 | 2341 |
|
9 | 2342 |
/* |
2343 |
* If the new and old values are the same, no need to update. |
|
2344 |
* |
|
2345 |
* Unserialized values will be adequate in most cases. If the unserialized |
|
2346 |
* data differs, the (maybe) serialized data is checked to avoid |
|
2347 |
* unnecessary database calls for otherwise identical object instances. |
|
2348 |
* |
|
2349 |
* See https://core.trac.wordpress.org/ticket/44956 |
|
2350 |
*/ |
|
2351 |
if ( $value === $old_value || maybe_serialize( $value ) === maybe_serialize( $old_value ) ) { |
|
0 | 2352 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2353 |
} |
0 | 2354 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2355 |
if ( false === $old_value ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2356 |
return add_network_option( $network_id, $option, $value ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2357 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2358 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2359 |
$notoptions_key = "$network_id:notoptions"; |
9 | 2360 |
$notoptions = wp_cache_get( $notoptions_key, 'site-options' ); |
16 | 2361 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2362 |
if ( is_array( $notoptions ) && isset( $notoptions[ $option ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2363 |
unset( $notoptions[ $option ] ); |
5 | 2364 |
wp_cache_set( $notoptions_key, $notoptions, 'site-options' ); |
0 | 2365 |
} |
2366 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2367 |
if ( ! is_multisite() ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2368 |
$result = update_option( $option, $value, false ); |
0 | 2369 |
} else { |
2370 |
$value = sanitize_option( $option, $value ); |
|
2371 |
||
2372 |
$serialized_value = maybe_serialize( $value ); |
|
9 | 2373 |
$result = $wpdb->update( |
2374 |
$wpdb->sitemeta, |
|
2375 |
array( 'meta_value' => $serialized_value ), |
|
2376 |
array( |
|
2377 |
'site_id' => $network_id, |
|
2378 |
'meta_key' => $option, |
|
2379 |
) |
|
2380 |
); |
|
0 | 2381 |
|
2382 |
if ( $result ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2383 |
$cache_key = "$network_id:$option"; |
0 | 2384 |
wp_cache_set( $cache_key, $value, 'site-options' ); |
2385 |
} |
|
2386 |
} |
|
2387 |
||
2388 |
if ( $result ) { |
|
5 | 2389 |
|
2390 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2391 |
* Fires after the value of a specific network option has been successfully updated. |
5 | 2392 |
* |
2393 |
* The dynamic portion of the hook name, `$option`, refers to the option name. |
|
2394 |
* |
|
2395 |
* @since 2.9.0 As "update_site_option_{$key}" |
|
2396 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2397 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2398 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2399 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2400 |
* @param mixed $value Current value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2401 |
* @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
|
2402 |
* @param int $network_id ID of the network. |
5 | 2403 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2404 |
do_action( "update_site_option_{$option}", $option, $value, $old_value, $network_id ); |
5 | 2405 |
|
2406 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2407 |
* Fires after the value of a network option has been successfully updated. |
5 | 2408 |
* |
2409 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2410 |
* @since 4.7.0 The `$network_id` parameter was added. |
5 | 2411 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2412 |
* @param string $option Name of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2413 |
* @param mixed $value Current value of the network option. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2414 |
* @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
|
2415 |
* @param int $network_id ID of the network. |
5 | 2416 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2417 |
do_action( 'update_site_option', $option, $value, $old_value, $network_id ); |
5 | 2418 |
|
0 | 2419 |
return true; |
2420 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2421 |
|
0 | 2422 |
return false; |
2423 |
} |
|
2424 |
||
2425 |
/** |
|
16 | 2426 |
* Deletes a site transient. |
0 | 2427 |
* |
2428 |
* @since 2.9.0 |
|
2429 |
* |
|
2430 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
|
16 | 2431 |
* @return bool True if the transient was deleted, false otherwise. |
0 | 2432 |
*/ |
2433 |
function delete_site_transient( $transient ) { |
|
5 | 2434 |
|
2435 |
/** |
|
2436 |
* Fires immediately before a specific site transient is deleted. |
|
2437 |
* |
|
2438 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
2439 |
* |
|
2440 |
* @since 3.0.0 |
|
2441 |
* |
|
2442 |
* @param string $transient Transient name. |
|
2443 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2444 |
do_action( "delete_site_transient_{$transient}", $transient ); |
5 | 2445 |
|
19 | 2446 |
if ( wp_using_ext_object_cache() || wp_installing() ) { |
0 | 2447 |
$result = wp_cache_delete( $transient, 'site-transient' ); |
2448 |
} else { |
|
2449 |
$option_timeout = '_site_transient_timeout_' . $transient; |
|
9 | 2450 |
$option = '_site_transient_' . $transient; |
2451 |
$result = delete_site_option( $option ); |
|
16 | 2452 |
|
9 | 2453 |
if ( $result ) { |
0 | 2454 |
delete_site_option( $option_timeout ); |
9 | 2455 |
} |
0 | 2456 |
} |
16 | 2457 |
|
5 | 2458 |
if ( $result ) { |
2459 |
||
2460 |
/** |
|
2461 |
* Fires after a transient is deleted. |
|
2462 |
* |
|
2463 |
* @since 3.0.0 |
|
2464 |
* |
|
2465 |
* @param string $transient Deleted transient name. |
|
2466 |
*/ |
|
0 | 2467 |
do_action( 'deleted_site_transient', $transient ); |
5 | 2468 |
} |
2469 |
||
0 | 2470 |
return $result; |
2471 |
} |
|
2472 |
||
2473 |
/** |
|
16 | 2474 |
* Retrieves the value of a site transient. |
0 | 2475 |
* |
5 | 2476 |
* If the transient does not exist, does not have a value, or has expired, |
2477 |
* then the return value will be false. |
|
2478 |
* |
|
2479 |
* @since 2.9.0 |
|
0 | 2480 |
* |
2481 |
* @see get_transient() |
|
2482 |
* |
|
2483 |
* @param string $transient Transient name. Expected to not be SQL-escaped. |
|
5 | 2484 |
* @return mixed Value of transient. |
0 | 2485 |
*/ |
2486 |
function get_site_transient( $transient ) { |
|
5 | 2487 |
|
2488 |
/** |
|
16 | 2489 |
* Filters the value of an existing site transient before it is retrieved. |
5 | 2490 |
* |
2491 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
2492 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2493 |
* Returning a value other than boolean false will short-circuit retrieval and |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2494 |
* return that value instead. |
5 | 2495 |
* |
2496 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2497 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 2498 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2499 |
* @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
|
2500 |
* Any value other than false will short-circuit the retrieval |
16 | 2501 |
* of the transient, and return that value. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2502 |
* @param string $transient Transient name. |
5 | 2503 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2504 |
$pre = apply_filters( "pre_site_transient_{$transient}", false, $transient ); |
5 | 2505 |
|
9 | 2506 |
if ( false !== $pre ) { |
0 | 2507 |
return $pre; |
9 | 2508 |
} |
0 | 2509 |
|
19 | 2510 |
if ( wp_using_ext_object_cache() || wp_installing() ) { |
0 | 2511 |
$value = wp_cache_get( $transient, 'site-transient' ); |
2512 |
} else { |
|
2513 |
// Core transients that do not have a timeout. Listed here so querying timeouts can be avoided. |
|
9 | 2514 |
$no_timeout = array( 'update_core', 'update_plugins', 'update_themes' ); |
0 | 2515 |
$transient_option = '_site_transient_' . $transient; |
16 | 2516 |
if ( ! in_array( $transient, $no_timeout, true ) ) { |
0 | 2517 |
$transient_timeout = '_site_transient_timeout_' . $transient; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2518 |
wp_prime_site_option_caches( array( $transient_option, $transient_timeout ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2519 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2520 |
$timeout = get_site_option( $transient_timeout ); |
0 | 2521 |
if ( false !== $timeout && $timeout < time() ) { |
9 | 2522 |
delete_site_option( $transient_option ); |
0 | 2523 |
delete_site_option( $transient_timeout ); |
2524 |
$value = false; |
|
2525 |
} |
|
2526 |
} |
|
2527 |
||
9 | 2528 |
if ( ! isset( $value ) ) { |
0 | 2529 |
$value = get_site_option( $transient_option ); |
9 | 2530 |
} |
0 | 2531 |
} |
2532 |
||
5 | 2533 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2534 |
* Filters the value of an existing site transient. |
5 | 2535 |
* |
2536 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
2537 |
* |
|
2538 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2539 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 2540 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2541 |
* @param mixed $value Value of site transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2542 |
* @param string $transient Transient name. |
5 | 2543 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2544 |
return apply_filters( "site_transient_{$transient}", $value, $transient ); |
0 | 2545 |
} |
2546 |
||
2547 |
/** |
|
16 | 2548 |
* Sets/updates the value of a site transient. |
0 | 2549 |
* |
16 | 2550 |
* You do not need to serialize values. If the value needs to be serialized, |
2551 |
* then it will be serialized before it is set. |
|
0 | 2552 |
* |
5 | 2553 |
* @since 2.9.0 |
2554 |
* |
|
0 | 2555 |
* @see set_transient() |
2556 |
* |
|
5 | 2557 |
* @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
|
2558 |
* 167 characters or fewer in length. |
5 | 2559 |
* @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
|
2560 |
* @param int $expiration Optional. Time until expiration in seconds. Default 0 (no expiration). |
16 | 2561 |
* @return bool True if the value was set, false otherwise. |
0 | 2562 |
*/ |
2563 |
function set_site_transient( $transient, $value, $expiration = 0 ) { |
|
5 | 2564 |
|
2565 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2566 |
* Filters the value of a specific site transient before it is set. |
5 | 2567 |
* |
2568 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
2569 |
* |
|
2570 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2571 |
* @since 4.4.0 The `$transient` parameter was added. |
5 | 2572 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2573 |
* @param mixed $value New value of site transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2574 |
* @param string $transient Transient name. |
5 | 2575 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2576 |
$value = apply_filters( "pre_set_site_transient_{$transient}", $value, $transient ); |
5 | 2577 |
|
0 | 2578 |
$expiration = (int) $expiration; |
2579 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2580 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2581 |
* 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
|
2582 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2583 |
* 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
|
2584 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2585 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2586 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2587 |
* @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
|
2588 |
* @param mixed $value New value of site transient. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2589 |
* @param string $transient Transient name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2590 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2591 |
$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
|
2592 |
|
19 | 2593 |
if ( wp_using_ext_object_cache() || wp_installing() ) { |
0 | 2594 |
$result = wp_cache_set( $transient, $value, 'site-transient', $expiration ); |
2595 |
} else { |
|
2596 |
$transient_timeout = '_site_transient_timeout_' . $transient; |
|
9 | 2597 |
$option = '_site_transient_' . $transient; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2598 |
wp_prime_site_option_caches( array( $option, $transient_timeout ) ); |
16 | 2599 |
|
0 | 2600 |
if ( false === get_site_option( $option ) ) { |
9 | 2601 |
if ( $expiration ) { |
0 | 2602 |
add_site_option( $transient_timeout, time() + $expiration ); |
9 | 2603 |
} |
0 | 2604 |
$result = add_site_option( $option, $value ); |
2605 |
} else { |
|
9 | 2606 |
if ( $expiration ) { |
0 | 2607 |
update_site_option( $transient_timeout, time() + $expiration ); |
9 | 2608 |
} |
0 | 2609 |
$result = update_site_option( $option, $value ); |
2610 |
} |
|
2611 |
} |
|
16 | 2612 |
|
0 | 2613 |
if ( $result ) { |
5 | 2614 |
|
2615 |
/** |
|
2616 |
* Fires after the value for a specific site transient has been set. |
|
2617 |
* |
|
2618 |
* The dynamic portion of the hook name, `$transient`, refers to the transient name. |
|
2619 |
* |
|
2620 |
* @since 3.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2621 |
* @since 4.4.0 The `$transient` parameter was added |
5 | 2622 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2623 |
* @param mixed $value Site transient value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2624 |
* @param int $expiration Time until expiration in seconds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2625 |
* @param string $transient Transient name. |
5 | 2626 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2627 |
do_action( "set_site_transient_{$transient}", $value, $expiration, $transient ); |
5 | 2628 |
|
2629 |
/** |
|
2630 |
* Fires after the value for a site transient has been set. |
|
2631 |
* |
|
2632 |
* @since 3.0.0 |
|
2633 |
* |
|
2634 |
* @param string $transient The name of the site transient. |
|
2635 |
* @param mixed $value Site transient value. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2636 |
* @param int $expiration Time until expiration in seconds. |
5 | 2637 |
*/ |
0 | 2638 |
do_action( 'setted_site_transient', $transient, $value, $expiration ); |
2639 |
} |
|
16 | 2640 |
|
0 | 2641 |
return $result; |
2642 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2643 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2644 |
/** |
16 | 2645 |
* Registers default settings available in WordPress. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2646 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2647 |
* 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
|
2648 |
* does not encompass all settings available in WordPress. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2649 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2650 |
* @since 4.7.0 |
19 | 2651 |
* @since 6.0.1 The `show_on_front`, `page_on_front`, and `page_for_posts` options were added. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2652 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2653 |
function register_initial_settings() { |
9 | 2654 |
register_setting( |
2655 |
'general', |
|
2656 |
'blogname', |
|
2657 |
array( |
|
2658 |
'show_in_rest' => array( |
|
2659 |
'name' => 'title', |
|
2660 |
), |
|
2661 |
'type' => 'string', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2662 |
'label' => __( 'Title' ), |
9 | 2663 |
'description' => __( 'Site title.' ), |
2664 |
) |
|
2665 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2666 |
|
9 | 2667 |
register_setting( |
2668 |
'general', |
|
2669 |
'blogdescription', |
|
2670 |
array( |
|
2671 |
'show_in_rest' => array( |
|
2672 |
'name' => 'description', |
|
2673 |
), |
|
2674 |
'type' => 'string', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2675 |
'label' => __( 'Tagline' ), |
9 | 2676 |
'description' => __( 'Site tagline.' ), |
2677 |
) |
|
2678 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2679 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2680 |
if ( ! is_multisite() ) { |
9 | 2681 |
register_setting( |
2682 |
'general', |
|
2683 |
'siteurl', |
|
2684 |
array( |
|
2685 |
'show_in_rest' => array( |
|
2686 |
'name' => 'url', |
|
2687 |
'schema' => array( |
|
2688 |
'format' => 'uri', |
|
2689 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2690 |
), |
9 | 2691 |
'type' => 'string', |
2692 |
'description' => __( 'Site URL.' ), |
|
2693 |
) |
|
2694 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2695 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2696 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2697 |
if ( ! is_multisite() ) { |
9 | 2698 |
register_setting( |
2699 |
'general', |
|
2700 |
'admin_email', |
|
2701 |
array( |
|
2702 |
'show_in_rest' => array( |
|
2703 |
'name' => 'email', |
|
2704 |
'schema' => array( |
|
2705 |
'format' => 'email', |
|
2706 |
), |
|
2707 |
), |
|
2708 |
'type' => 'string', |
|
2709 |
'description' => __( 'This address is used for admin purposes, like new user notification.' ), |
|
2710 |
) |
|
2711 |
); |
|
2712 |
} |
|
2713 |
||
2714 |
register_setting( |
|
2715 |
'general', |
|
2716 |
'timezone_string', |
|
2717 |
array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2718 |
'show_in_rest' => array( |
9 | 2719 |
'name' => 'timezone', |
2720 |
), |
|
2721 |
'type' => 'string', |
|
2722 |
'description' => __( 'A city in the same timezone as you.' ), |
|
2723 |
) |
|
2724 |
); |
|
2725 |
||
2726 |
register_setting( |
|
2727 |
'general', |
|
2728 |
'date_format', |
|
2729 |
array( |
|
2730 |
'show_in_rest' => true, |
|
2731 |
'type' => 'string', |
|
2732 |
'description' => __( 'A date format for all date strings.' ), |
|
2733 |
) |
|
2734 |
); |
|
2735 |
||
2736 |
register_setting( |
|
2737 |
'general', |
|
2738 |
'time_format', |
|
2739 |
array( |
|
2740 |
'show_in_rest' => true, |
|
2741 |
'type' => 'string', |
|
2742 |
'description' => __( 'A time format for all time strings.' ), |
|
2743 |
) |
|
2744 |
); |
|
2745 |
||
2746 |
register_setting( |
|
2747 |
'general', |
|
2748 |
'start_of_week', |
|
2749 |
array( |
|
2750 |
'show_in_rest' => true, |
|
2751 |
'type' => 'integer', |
|
2752 |
'description' => __( 'A day number of the week that the week should start on.' ), |
|
2753 |
) |
|
2754 |
); |
|
2755 |
||
2756 |
register_setting( |
|
2757 |
'general', |
|
2758 |
'WPLANG', |
|
2759 |
array( |
|
2760 |
'show_in_rest' => array( |
|
2761 |
'name' => 'language', |
|
2762 |
), |
|
2763 |
'type' => 'string', |
|
2764 |
'description' => __( 'WordPress locale code.' ), |
|
2765 |
'default' => 'en_US', |
|
2766 |
) |
|
2767 |
); |
|
2768 |
||
2769 |
register_setting( |
|
2770 |
'writing', |
|
2771 |
'use_smilies', |
|
2772 |
array( |
|
2773 |
'show_in_rest' => true, |
|
2774 |
'type' => 'boolean', |
|
2775 |
'description' => __( 'Convert emoticons like :-) and :-P to graphics on display.' ), |
|
2776 |
'default' => true, |
|
2777 |
) |
|
2778 |
); |
|
2779 |
||
2780 |
register_setting( |
|
2781 |
'writing', |
|
2782 |
'default_category', |
|
2783 |
array( |
|
2784 |
'show_in_rest' => true, |
|
2785 |
'type' => 'integer', |
|
2786 |
'description' => __( 'Default post category.' ), |
|
2787 |
) |
|
2788 |
); |
|
2789 |
||
2790 |
register_setting( |
|
2791 |
'writing', |
|
2792 |
'default_post_format', |
|
2793 |
array( |
|
2794 |
'show_in_rest' => true, |
|
2795 |
'type' => 'string', |
|
2796 |
'description' => __( 'Default post format.' ), |
|
2797 |
) |
|
2798 |
); |
|
2799 |
||
2800 |
register_setting( |
|
2801 |
'reading', |
|
2802 |
'posts_per_page', |
|
2803 |
array( |
|
2804 |
'show_in_rest' => true, |
|
2805 |
'type' => 'integer', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2806 |
'label' => __( 'Maximum posts per page' ), |
9 | 2807 |
'description' => __( 'Blog pages show at most.' ), |
2808 |
'default' => 10, |
|
2809 |
) |
|
2810 |
); |
|
2811 |
||
2812 |
register_setting( |
|
19 | 2813 |
'reading', |
2814 |
'show_on_front', |
|
2815 |
array( |
|
2816 |
'show_in_rest' => true, |
|
2817 |
'type' => 'string', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2818 |
'label' => __( 'Show on front' ), |
19 | 2819 |
'description' => __( 'What to show on the front page' ), |
2820 |
) |
|
2821 |
); |
|
2822 |
||
2823 |
register_setting( |
|
2824 |
'reading', |
|
2825 |
'page_on_front', |
|
2826 |
array( |
|
2827 |
'show_in_rest' => true, |
|
2828 |
'type' => 'integer', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2829 |
'label' => __( 'Page on front' ), |
19 | 2830 |
'description' => __( 'The ID of the page that should be displayed on the front page' ), |
2831 |
) |
|
2832 |
); |
|
2833 |
||
2834 |
register_setting( |
|
2835 |
'reading', |
|
2836 |
'page_for_posts', |
|
2837 |
array( |
|
2838 |
'show_in_rest' => true, |
|
2839 |
'type' => 'integer', |
|
2840 |
'description' => __( 'The ID of the page that should display the latest posts' ), |
|
2841 |
) |
|
2842 |
); |
|
2843 |
||
2844 |
register_setting( |
|
9 | 2845 |
'discussion', |
2846 |
'default_ping_status', |
|
2847 |
array( |
|
2848 |
'show_in_rest' => array( |
|
2849 |
'schema' => array( |
|
2850 |
'enum' => array( 'open', 'closed' ), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2851 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2852 |
), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2853 |
'type' => 'string', |
9 | 2854 |
'description' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles.' ), |
2855 |
) |
|
2856 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2857 |
|
9 | 2858 |
register_setting( |
2859 |
'discussion', |
|
2860 |
'default_comment_status', |
|
2861 |
array( |
|
2862 |
'show_in_rest' => array( |
|
2863 |
'schema' => array( |
|
2864 |
'enum' => array( 'open', 'closed' ), |
|
2865 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2866 |
), |
9 | 2867 |
'type' => 'string', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2868 |
'label' => __( 'Allow comments on new posts' ), |
16 | 2869 |
'description' => __( 'Allow people to submit comments on new posts.' ), |
9 | 2870 |
) |
2871 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2872 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2873 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2874 |
/** |
16 | 2875 |
* Registers a setting and its data. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2876 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2877 |
* @since 2.7.0 |
19 | 2878 |
* @since 3.0.0 The `misc` option group was deprecated. |
2879 |
* @since 3.5.0 The `privacy` option group was deprecated. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2880 |
* @since 4.7.0 `$args` can be passed to set flags on the setting, similar to `register_meta()`. |
16 | 2881 |
* @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`. |
2882 |
* Please consider writing more inclusive code. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2883 |
* @since 6.6.0 Added the `label` argument. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2884 |
* |
16 | 2885 |
* @global array $new_allowed_options |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2886 |
* @global array $wp_registered_settings |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2887 |
* |
16 | 2888 |
* @param string $option_group A settings group name. Should correspond to an allowed option key name. |
2889 |
* Default allowed option key names include 'general', 'discussion', 'media', |
|
19 | 2890 |
* 'reading', 'writing', and 'options'. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2891 |
* @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
|
2892 |
* @param array $args { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2893 |
* Data used to describe the setting when registered. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2894 |
* |
16 | 2895 |
* @type string $type The type of data associated with this setting. |
2896 |
* Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2897 |
* @type string $label A label of the data attached to this setting. |
16 | 2898 |
* @type string $description A description of the data attached to this setting. |
2899 |
* @type callable $sanitize_callback A callback function that sanitizes the option's value. |
|
2900 |
* @type bool|array $show_in_rest Whether data associated with this setting should be included in the REST API. |
|
2901 |
* When registering complex settings, this argument may optionally be an |
|
2902 |
* array with a 'schema' key. |
|
2903 |
* @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
|
2904 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2905 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2906 |
function register_setting( $option_group, $option_name, $args = array() ) { |
16 | 2907 |
global $new_allowed_options, $wp_registered_settings; |
2908 |
||
2909 |
/* |
|
2910 |
* In 5.5.0, the `$new_whitelist_options` global variable was renamed to `$new_allowed_options`. |
|
2911 |
* Please consider writing more inclusive code. |
|
2912 |
*/ |
|
2913 |
$GLOBALS['new_whitelist_options'] = &$new_allowed_options; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2914 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2915 |
$defaults = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2916 |
'type' => 'string', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2917 |
'group' => $option_group, |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
2918 |
'label' => '', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2919 |
'description' => '', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2920 |
'sanitize_callback' => null, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2921 |
'show_in_rest' => false, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2922 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2923 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2924 |
// Back-compat: old sanitize callback is added. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2925 |
if ( is_callable( $args ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2926 |
$args = array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2927 |
'sanitize_callback' => $args, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2928 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2929 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2930 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2931 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2932 |
* Filters the registration arguments when registering a setting. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2933 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2934 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2935 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2936 |
* @param array $args Array of setting registration arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2937 |
* @param array $defaults Array of default arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2938 |
* @param string $option_group Setting group. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2939 |
* @param string $option_name Setting name. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2940 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2941 |
$args = apply_filters( 'register_setting_args', $args, $defaults, $option_group, $option_name ); |
16 | 2942 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2943 |
$args = wp_parse_args( $args, $defaults ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2944 |
|
16 | 2945 |
// Require an item schema when registering settings with an array type. |
2946 |
if ( false !== $args['show_in_rest'] && 'array' === $args['type'] && ( ! is_array( $args['show_in_rest'] ) || ! isset( $args['show_in_rest']['schema']['items'] ) ) ) { |
|
2947 |
_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' ); |
|
2948 |
} |
|
2949 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2950 |
if ( ! is_array( $wp_registered_settings ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2951 |
$wp_registered_settings = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2952 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2953 |
|
16 | 2954 |
if ( 'misc' === $option_group ) { |
9 | 2955 |
_deprecated_argument( |
2956 |
__FUNCTION__, |
|
2957 |
'3.0.0', |
|
2958 |
sprintf( |
|
16 | 2959 |
/* translators: %s: misc */ |
9 | 2960 |
__( '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
|
2961 |
'misc' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2962 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2963 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2964 |
$option_group = 'general'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2965 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2966 |
|
16 | 2967 |
if ( 'privacy' === $option_group ) { |
9 | 2968 |
_deprecated_argument( |
2969 |
__FUNCTION__, |
|
2970 |
'3.5.0', |
|
2971 |
sprintf( |
|
16 | 2972 |
/* translators: %s: privacy */ |
9 | 2973 |
__( '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
|
2974 |
'privacy' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2975 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2976 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2977 |
$option_group = 'reading'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2978 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2979 |
|
16 | 2980 |
$new_allowed_options[ $option_group ][] = $option_name; |
2981 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2982 |
if ( ! empty( $args['sanitize_callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2983 |
add_filter( "sanitize_option_{$option_name}", $args['sanitize_callback'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2984 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2985 |
if ( array_key_exists( 'default', $args ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2986 |
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
|
2987 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2988 |
|
16 | 2989 |
/** |
2990 |
* Fires immediately before the setting is registered but after its filters are in place. |
|
2991 |
* |
|
2992 |
* @since 5.5.0 |
|
2993 |
* |
|
2994 |
* @param string $option_group Setting group. |
|
2995 |
* @param string $option_name Setting name. |
|
2996 |
* @param array $args Array of setting registration arguments. |
|
2997 |
*/ |
|
2998 |
do_action( 'register_setting', $option_group, $option_name, $args ); |
|
2999 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3000 |
$wp_registered_settings[ $option_name ] = $args; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3001 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3002 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3003 |
/** |
16 | 3004 |
* Unregisters a setting. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3005 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3006 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3007 |
* @since 4.7.0 `$sanitize_callback` was deprecated. The callback from `register_setting()` is now used instead. |
16 | 3008 |
* @since 5.5.0 `$new_whitelist_options` was renamed to `$new_allowed_options`. |
3009 |
* Please consider writing more inclusive code. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3010 |
* |
16 | 3011 |
* @global array $new_allowed_options |
9 | 3012 |
* @global array $wp_registered_settings |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3013 |
* |
19 | 3014 |
* @param string $option_group The settings group name used during registration. |
3015 |
* @param string $option_name The name of the option to unregister. |
|
3016 |
* @param callable $deprecated Optional. Deprecated. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3017 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3018 |
function unregister_setting( $option_group, $option_name, $deprecated = '' ) { |
16 | 3019 |
global $new_allowed_options, $wp_registered_settings; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3020 |
|
16 | 3021 |
/* |
3022 |
* In 5.5.0, the `$new_whitelist_options` global variable was renamed to `$new_allowed_options`. |
|
3023 |
* Please consider writing more inclusive code. |
|
3024 |
*/ |
|
3025 |
$GLOBALS['new_whitelist_options'] = &$new_allowed_options; |
|
3026 |
||
3027 |
if ( 'misc' === $option_group ) { |
|
9 | 3028 |
_deprecated_argument( |
3029 |
__FUNCTION__, |
|
3030 |
'3.0.0', |
|
3031 |
sprintf( |
|
16 | 3032 |
/* translators: %s: misc */ |
9 | 3033 |
__( '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
|
3034 |
'misc' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3035 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3036 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3037 |
$option_group = 'general'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3038 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3039 |
|
16 | 3040 |
if ( 'privacy' === $option_group ) { |
9 | 3041 |
_deprecated_argument( |
3042 |
__FUNCTION__, |
|
3043 |
'3.5.0', |
|
3044 |
sprintf( |
|
16 | 3045 |
/* translators: %s: privacy */ |
9 | 3046 |
__( '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
|
3047 |
'privacy' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3048 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3049 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3050 |
$option_group = 'reading'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3051 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3052 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3053 |
$pos = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3054 |
if ( isset( $new_allowed_options[ $option_group ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3055 |
$pos = array_search( $option_name, (array) $new_allowed_options[ $option_group ], true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3056 |
} |
16 | 3057 |
|
3058 |
if ( false !== $pos ) { |
|
3059 |
unset( $new_allowed_options[ $option_group ][ $pos ] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3060 |
} |
16 | 3061 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3062 |
if ( '' !== $deprecated ) { |
9 | 3063 |
_deprecated_argument( |
3064 |
__FUNCTION__, |
|
3065 |
'4.7.0', |
|
3066 |
sprintf( |
|
16 | 3067 |
/* translators: 1: $sanitize_callback, 2: register_setting() */ |
9 | 3068 |
__( '%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
|
3069 |
'<code>$sanitize_callback</code>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3070 |
'<code>register_setting()</code>' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3071 |
) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3072 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3073 |
remove_filter( "sanitize_option_{$option_name}", $deprecated ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3074 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3075 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3076 |
if ( isset( $wp_registered_settings[ $option_name ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3077 |
// 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
|
3078 |
if ( ! empty( $wp_registered_settings[ $option_name ]['sanitize_callback'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3079 |
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
|
3080 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3081 |
|
9 | 3082 |
// Remove the default filter if a default was provided during registration. |
3083 |
if ( array_key_exists( 'default', $wp_registered_settings[ $option_name ] ) ) { |
|
3084 |
remove_filter( "default_option_{$option_name}", 'filter_default_option', 10 ); |
|
3085 |
} |
|
3086 |
||
16 | 3087 |
/** |
3088 |
* Fires immediately before the setting is unregistered and after its filters have been removed. |
|
3089 |
* |
|
3090 |
* @since 5.5.0 |
|
3091 |
* |
|
3092 |
* @param string $option_group Setting group. |
|
3093 |
* @param string $option_name Setting name. |
|
3094 |
*/ |
|
3095 |
do_action( 'unregister_setting', $option_group, $option_name ); |
|
3096 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3097 |
unset( $wp_registered_settings[ $option_name ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3098 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3099 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3100 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3101 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3102 |
* Retrieves an array of registered settings. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3103 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3104 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3105 |
* |
9 | 3106 |
* @global array $wp_registered_settings |
3107 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3108 |
* @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
|
3109 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3110 |
function get_registered_settings() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3111 |
global $wp_registered_settings; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3112 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3113 |
if ( ! is_array( $wp_registered_settings ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3114 |
return array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3115 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3116 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3117 |
return $wp_registered_settings; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3118 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3119 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3120 |
/** |
16 | 3121 |
* Filters the default value for the option. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3122 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3123 |
* 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
|
3124 |
* 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
|
3125 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3126 |
* @since 4.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3127 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3128 |
* @param mixed $default_value Existing default value to return. |
16 | 3129 |
* @param string $option Option name. |
3130 |
* @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
|
3131 |
* @return mixed Filtered default value. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3132 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3133 |
function filter_default_option( $default_value, $option, $passed_default ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3134 |
if ( $passed_default ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3135 |
return $default_value; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3136 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3137 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3138 |
$registered = get_registered_settings(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3139 |
if ( empty( $registered[ $option ] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3140 |
return $default_value; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3141 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3142 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3143 |
return $registered[ $option ]['default']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3144 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3145 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3146 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3147 |
* Returns the values that trigger autoloading from the options table. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3148 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3149 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3150 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3151 |
* @return string[] The values that trigger autoloading. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3152 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3153 |
function wp_autoload_values_to_autoload() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3154 |
$autoload_values = array( 'yes', 'on', 'auto-on', 'auto' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3155 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3156 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3157 |
* Filters the autoload values that should be considered for autoloading from the options table. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3158 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3159 |
* The filter can only be used to remove autoload values from the default list. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3160 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3161 |
* @since 6.6.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3162 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3163 |
* @param string[] $autoload_values Autoload values used to autoload option. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3164 |
* Default list contains 'yes', 'on', 'auto-on', and 'auto'. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3165 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3166 |
$filtered_values = apply_filters( 'wp_autoload_values_to_autoload', $autoload_values ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3167 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3168 |
return array_intersect( $filtered_values, $autoload_values ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
3169 |
} |