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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 / local-meta.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
local-meta.php
266 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_Local_Meta' ) ) :
17
18 class ACF_Local_Meta {
19
20 /** @var array Storage for meta data. */
21 var $meta = array();
22
23 /** @var mixed Storage for the current post_id. */
24 var $post_id = 0;
25
26 /**
27 * __construct
28 *
29 * Sets up the class functionality.
30 *
31 * @date 8/10/18
32 * @since 5.8.0
33 *
34 * @param void
35 * @return void
36 */
37 function __construct() {
38
39 // add filters
40 add_filter( 'acf/pre_load_post_id', array( $this, 'pre_load_post_id' ), 1, 2 );
41 add_filter( 'acf/pre_load_meta', array( $this, 'pre_load_meta' ), 1, 2 );
42 add_filter( 'acf/pre_load_metadata', array( $this, 'pre_load_metadata' ), 1, 4 );
43 }
44
45 /**
46 * add
47 *
48 * Adds postmeta to storage.
49 * Accepts data in either raw or request format.
50 *
51 * @date 8/10/18
52 * @since 5.8.0
53 *
54 * @param array $meta An array of metdata to store.
55 * @param mixed $post_id The post_id for this data.
56 * @param boolean $is_main Makes this postmeta visible to get_field() without a $post_id value.
57 * @return array
58 */
59 function add( $meta = array(), $post_id = 0, $is_main = false ) {
60
61 // Capture meta if supplied meta is from a REQUEST.
62 if ( $this->is_request( $meta ) ) {
63 $meta = $this->capture( $meta, $post_id );
64 }
65
66 // Add to storage.
67 $this->meta[ $post_id ] = $meta;
68
69 // Set $post_id reference when is the "main" postmeta.
70 if ( $is_main ) {
71 $this->post_id = $post_id;
72 }
73
74 // Return meta.
75 return $meta;
76 }
77
78 /**
79 * is_request
80 *
81 * Returns true if the supplied $meta is from a REQUEST (serialized <form> data).
82 *
83 * @date 11/3/19
84 * @since 5.7.14
85 *
86 * @param array $meta An array of metdata to check.
87 * @return boolean
88 */
89 function is_request( $meta = array() ) {
90 return acf_is_field_key( key( $meta ) );
91 }
92
93 /**
94 * capture
95 *
96 * Returns a flattened array of meta for the given postdata.
97 * This is achieved by simulating a save whilst capturing all meta changes.
98 *
99 * @date 26/2/19
100 * @since 5.7.13
101 *
102 * @param array $values An array of raw values.
103 * @param mixed $post_id The post_id for this data.
104 * @return array
105 */
106 function capture( $values = array(), $post_id = 0 ) {
107
108 // Reset meta.
109 $this->meta[ $post_id ] = array();
110
111 // Listen for any added meta.
112 add_filter( 'acf/pre_update_metadata', array( $this, 'capture_update_metadata' ), 1, 5 );
113
114 // Simulate update.
115 if ( $values ) {
116 acf_update_values( $values, $post_id );
117 }
118
119 // Remove listener filter.
120 remove_filter( 'acf/pre_update_metadata', array( $this, 'capture_update_metadata' ), 1, 5 );
121
122 // Return meta.
123 return $this->meta[ $post_id ];
124 }
125
126 /**
127 * capture_update_metadata
128 *
129 * Records all meta activity and returns a non null value to bypass DB updates.
130 *
131 * @date 26/2/19
132 * @since 5.7.13
133 *
134 * @param null $null .
135 * @param (int|string) $post_id The post id.
136 * @param string $name The meta name.
137 * @param mixed $value The meta value.
138 * @param boolean $hidden If the meta is hidden (starts with an underscore).
139 * @return false.
140 */
141 function capture_update_metadata( $null, $post_id, $name, $value, $hidden ) {
142 $name = ( $hidden ? '_' : '' ) . $name;
143 $this->meta[ $post_id ][ $name ] = $value;
144
145 // Return non null value to escape update process.
146 return true;
147 }
148
149 /**
150 * remove
151 *
152 * Removes postmeta from storage.
153 *
154 * @date 8/10/18
155 * @since 5.8.0
156 *
157 * @param mixed $post_id The post_id for this data.
158 * @return void
159 */
160 function remove( $post_id = 0 ) {
161
162 // unset meta
163 unset( $this->meta[ $post_id ] );
164
165 // reset post_id
166 if ( $post_id === $this->post_id ) {
167 $this->post_id = 0;
168 }
169 }
170
171 /**
172 * pre_load_meta
173 *
174 * Injects the local meta.
175 *
176 * @date 8/10/18
177 * @since 5.8.0
178 *
179 * @param null $null An empty parameter. Return a non null value to short-circuit the function.
180 * @param mixed $post_id The post_id for this data.
181 * @return mixed
182 */
183 function pre_load_meta( $null, $post_id ) {
184 if ( isset( $this->meta[ $post_id ] ) ) {
185 return $this->meta[ $post_id ];
186 }
187 return $null;
188 }
189
190 /**
191 * pre_load_metadata
192 *
193 * Injects the local meta.
194 *
195 * @date 8/10/18
196 * @since 5.8.0
197 *
198 * @param null $null An empty parameter. Return a non null value to short-circuit the function.
199 * @param (int|string) $post_id The post id.
200 * @param string $name The meta name.
201 * @param boolean $hidden If the meta is hidden (starts with an underscore).
202 * @return mixed
203 */
204 function pre_load_metadata( $null, $post_id, $name, $hidden ) {
205 $name = ( $hidden ? '_' : '' ) . $name;
206 if ( isset( $this->meta[ $post_id ] ) ) {
207 if ( isset( $this->meta[ $post_id ][ $name ] ) ) {
208 return $this->meta[ $post_id ][ $name ];
209 }
210 return '__return_null';
211 }
212 return $null;
213 }
214
215 /**
216 * pre_load_post_id
217 *
218 * Injects the local post_id.
219 *
220 * @date 8/10/18
221 * @since 5.8.0
222 *
223 * @param null $null An empty parameter. Return a non null value to short-circuit the function.
224 * @param mixed $post_id The post_id for this data.
225 * @return mixed
226 */
227 function pre_load_post_id( $null, $post_id ) {
228 if ( ! $post_id && $this->post_id ) {
229 return $this->post_id;
230 }
231 return $null;
232 }
233 }
234
235 endif; // class_exists check
236
237 /**
238 * acf_setup_meta
239 *
240 * Adds postmeta to storage.
241 *
242 * @date 8/10/18
243 * @since 5.8.0
244 * @see ACF_Local_Meta::add() for list of parameters.
245 *
246 * @return array
247 */
248 function acf_setup_meta( $meta = array(), $post_id = 0, $is_main = false ) {
249 return acf_get_instance( 'ACF_Local_Meta' )->add( $meta, $post_id, $is_main );
250 }
251
252 /**
253 * acf_reset_meta
254 *
255 * Removes postmeta to storage.
256 *
257 * @date 8/10/18
258 * @since 5.8.0
259 * @see ACF_Local_Meta::remove() for list of parameters.
260 *
261 * @return void
262 */
263 function acf_reset_meta( $post_id = 0 ) {
264 return acf_get_instance( 'ACF_Local_Meta' )->remove( $post_id );
265 }
266