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.2.1 4.2.2 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.8 4.3.9 4.4.0 4.4.1 4.4.10 4.4.11 4.4.12 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 5.10 5.10.1 5.10.2 5.11 5.11.1 5.11.2 5.11.3 5.11.4 5.12 5.12.1 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.6.10 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6 5.6.7 5.6.8 5.6.9 5.7.0 5.7.1 5.7.10 5.7.12 5.7.13 5.7.2 5.7.3 5.7.4 5.7.5 5.7.6 5.7.7 5.7.8 5.7.9 5.8.0 5.8.1 5.8.10 5.8.11 5.8.12 5.8.13 5.8.14 5.8.2 5.8.3 5.8.4
advanced-custom-fields / includes / class-acf-data.php
advanced-custom-fields / includes Last commit date
admin 1 month ago ajax 3 months ago api 2 weeks ago fields 4 weeks ago forms 4 weeks ago legacy 5 months ago locations 1 month ago post-types 5 months ago rest-api 4 weeks ago walkers 5 months ago acf-bidirectional-functions.php 5 months ago acf-field-functions.php 5 months ago acf-field-group-functions.php 5 months ago acf-form-functions.php 5 months ago acf-helper-functions.php 5 months ago acf-hook-functions.php 5 months ago acf-input-functions.php 5 months ago acf-internal-post-type-functions.php 5 months ago acf-meta-functions.php 2 months ago acf-post-functions.php 5 months ago acf-post-type-functions.php 5 months ago acf-taxonomy-functions.php 5 months ago acf-user-functions.php 5 months ago acf-utility-functions.php 5 months ago acf-value-functions.php 5 months ago acf-wp-functions.php 5 months ago assets.php 5 months ago class-acf-data.php 5 months ago class-acf-internal-post-type.php 5 months ago compatibility.php 5 months ago deprecated.php 5 months ago fields.php 5 months ago index.php 2 years ago l10n.php 5 months ago local-fields.php 5 months ago local-json.php 3 months ago local-meta.php 5 months ago locations.php 5 months ago loop.php 5 months ago media.php 5 months ago rest-api.php 5 months ago revisions.php 3 months ago third-party.php 5 months ago upgrades.php 2 months ago validation.php 5 months ago wpml.php 5 months ago
class-acf-data.php
389 lines
1 <?php
2 /**
3 * @package ACF
4 * @author WP Engine
5 *
6 * © 2026 Advanced Custom Fields (ACF®). All rights reserved.
7 * "ACF" is a trademark of WP Engine.
8 * Licensed under the GNU General Public License v2 or later.
9 * https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 if ( ! class_exists( 'ACF_Data' ) ) :
17 class ACF_Data {
18
19 /**
20 * Unique identifier.
21 * @var string
22 */
23 public $cid = '';
24
25 /**
26 * Storage for data.
27 * @var array
28 */
29 public $data = array();
30
31 /**
32 * Storage for data aliases.
33 * @var array
34 */
35 public $aliases = array();
36
37 /**
38 * Enables unique data per site.
39 * @var boolean
40 */
41 public $multisite = false;
42
43 /**
44 * Storage for multisite data.
45 * @var array
46 */
47 public $site_data = array();
48
49 /**
50 * Storage for multisite aliases.
51 * @var array
52 */
53 public $site_aliases = array();
54
55 /**
56 * __construct
57 *
58 * Sets up the class functionality.
59 *
60 * @date 9/1/19
61 * @since 5.7.10
62 *
63 * @param array $data Optional data to set.
64 * @return void
65 */
66 function __construct( $data = false ) {
67
68 // Set cid.
69 $this->cid = acf_uniqid();
70
71 // Set data.
72 if ( $data ) {
73 $this->set( $data );
74 }
75
76 // Initialize.
77 $this->initialize();
78 }
79
80 /**
81 * initialize
82 *
83 * Called during constructor to setup class functionality.
84 *
85 * @date 9/1/19
86 * @since 5.7.10
87 *
88 * @param void
89 * @return void
90 */
91 function initialize() {
92 // Do nothing.
93 }
94
95 /**
96 * prop
97 *
98 * Sets a property for the given name and returns $this for chaining.
99 *
100 * @date 9/1/19
101 * @since 5.7.10
102 *
103 * @param (string|array) $name The data name or an array of data.
104 * @param mixed $value The data value.
105 * @return ACF_Data
106 */
107 function prop( $name = '', $value = null ) {
108
109 // Update property.
110 $this->{$name} = $value;
111
112 // Return this for chaining.
113 return $this;
114 }
115
116 /**
117 * _key
118 *
119 * Returns a key for the given name allowing aliasses to work.
120 *
121 * @date 18/1/19
122 * @since 5.7.10
123 *
124 * @param type $var Description. Default.
125 * @return type Description.
126 */
127 function _key( $name = '' ) {
128 return isset( $this->aliases[ $name ] ) ? $this->aliases[ $name ] : $name;
129 }
130
131 /**
132 * has
133 *
134 * Returns true if this has data for the given name.
135 *
136 * @date 9/1/19
137 * @since 5.7.10
138 *
139 * @param string $name The data name.
140 * @return boolean
141 */
142 function has( $name = '' ) {
143 $key = $this->_key( $name );
144 return isset( $this->data[ $key ] );
145 }
146
147 /**
148 * is
149 *
150 * Similar to has() but does not check aliases.
151 *
152 * @date 7/2/19
153 * @since 5.7.11
154 *
155 * @param type $var Description. Default.
156 * @return type Description.
157 */
158 function is( $key = '' ) {
159 return isset( $this->data[ $key ] );
160 }
161
162 /**
163 * get
164 *
165 * Returns data for the given name of null if doesn't exist.
166 *
167 * @date 9/1/19
168 * @since 5.7.10
169 *
170 * @param string $name The data name.
171 * @return mixed
172 */
173 function get( $name = false ) {
174
175 // Get all.
176 if ( $name === false ) {
177 return $this->data;
178
179 // Get specific.
180 } else {
181 $key = $this->_key( $name );
182 return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null;
183 }
184 }
185
186 /**
187 * get_data
188 *
189 * Returns an array of all data.
190 *
191 * @date 9/1/19
192 * @since 5.7.10
193 *
194 * @param void
195 * @return array
196 */
197 function get_data() {
198 return $this->data;
199 }
200
201 /**
202 * set
203 *
204 * Sets data for the given name and returns $this for chaining.
205 *
206 * @date 9/1/19
207 * @since 5.7.10
208 *
209 * @param (string|array) $name The data name or an array of data.
210 * @param mixed $value The data value.
211 * @return ACF_Data
212 */
213 function set( $name = '', $value = null ) {
214
215 // Set multiple.
216 if ( is_array( $name ) ) {
217 $this->data = array_merge( $this->data, $name );
218
219 // Set single.
220 } else {
221 $this->data[ $name ] = $value;
222 }
223
224 // Return this for chaining.
225 return $this;
226 }
227
228 /**
229 * append
230 *
231 * Appends data for the given name and returns $this for chaining.
232 *
233 * @date 9/1/19
234 * @since 5.7.10
235 *
236 * @param mixed $value The data value.
237 * @return ACF_Data
238 */
239 function append( $value = null ) {
240
241 // Append.
242 $this->data[] = $value;
243
244 // Return this for chaining.
245 return $this;
246 }
247
248 /**
249 * remove
250 *
251 * Removes data for the given name.
252 *
253 * @date 9/1/19
254 * @since 5.7.10
255 *
256 * @param string $name The data name.
257 * @return ACF_Data
258 */
259 function remove( $name = '' ) {
260
261 // Remove data.
262 unset( $this->data[ $name ] );
263
264 // Return this for chaining.
265 return $this;
266 }
267
268 /**
269 * reset
270 *
271 * Resets the data.
272 *
273 * @date 22/1/19
274 * @since 5.7.10
275 *
276 * @param void
277 * @return void
278 */
279 function reset() {
280 $this->data = array();
281 $this->aliases = array();
282 }
283
284 /**
285 * count
286 *
287 * Returns the data count.
288 *
289 * @date 23/1/19
290 * @since 5.7.10
291 *
292 * @param void
293 * @return integer
294 */
295 function count() {
296 return count( $this->data );
297 }
298
299 /**
300 * query
301 *
302 * Returns a filtered array of data based on the set of key => value arguments.
303 *
304 * @date 23/1/19
305 * @since 5.7.10
306 *
307 * @param void
308 * @return integer
309 */
310 function query( $args, $operator = 'AND' ) {
311 return wp_list_filter( $this->data, $args, $operator );
312 }
313
314 /**
315 * alias
316 *
317 * Sets an alias for the given name allowing data to be found via multiple identifiers.
318 *
319 * @date 18/1/19
320 * @since 5.7.10
321 *
322 * @param type $var Description. Default.
323 * @return type Description.
324 */
325 function alias( $name = '' /*, $alias, $alias2, etc */ ) {
326
327 // Get all aliases.
328 $args = func_get_args();
329 array_shift( $args );
330
331 // Loop over aliases and add to data.
332 foreach ( $args as $alias ) {
333 $this->aliases[ $alias ] = $name;
334 }
335
336 // Return this for chaining.
337 return $this;
338 }
339
340 /**
341 * switch_site
342 *
343 * Triggered when switching between sites on a multisite installation.
344 *
345 * @date 13/2/19
346 * @since 5.7.11
347 *
348 * @param integer $site_id New blog ID.
349 * @param int prev_blog_id Prev blog ID.
350 * @return void
351 */
352 function switch_site( $site_id, $prev_site_id ) {
353
354 // Bail early if not multisite compatible.
355 if ( ! $this->multisite ) {
356 return;
357 }
358
359 // Bail early if no change in blog ID.
360 if ( $site_id === $prev_site_id ) {
361 return;
362 }
363
364 // Create storage.
365 if ( ! isset( $this->site_data ) ) {
366 $this->site_data = array();
367 $this->site_aliases = array();
368 }
369
370 // Save state.
371 $this->site_data[ $prev_site_id ] = $this->data;
372 $this->site_aliases[ $prev_site_id ] = $this->aliases;
373
374 // Reset state.
375 $this->data = array();
376 $this->aliases = array();
377
378 // Load state.
379 if ( isset( $this->site_data[ $site_id ] ) ) {
380 $this->data = $this->site_data[ $site_id ];
381 $this->aliases = $this->site_aliases[ $site_id ];
382 unset( $this->site_data[ $site_id ] );
383 unset( $this->site_aliases[ $site_id ] );
384 }
385 }
386 }
387
388 endif; // class_exists check
389