PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.2
Secure Custom Fields v6.4.2
6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / loop.php
secure-custom-fields / includes Last commit date
Blocks 1 year ago admin 1 year ago ajax 1 year ago api 1 year ago fields 1 year ago forms 1 year ago legacy 1 year ago locations 1 year ago post-types 1 year ago rest-api 1 year ago walkers 1 year ago acf-bidirectional-functions.php 1 year ago acf-field-functions.php 1 year ago acf-field-group-functions.php 1 year ago acf-form-functions.php 1 year ago acf-helper-functions.php 1 year ago acf-hook-functions.php 1 year ago acf-input-functions.php 1 year ago acf-internal-post-type-functions.php 1 year ago acf-meta-functions.php 1 year ago acf-post-functions.php 1 year ago acf-post-type-functions.php 1 year ago acf-taxonomy-functions.php 1 year ago acf-user-functions.php 1 year ago acf-utility-functions.php 1 year ago acf-value-functions.php 1 year ago acf-wp-functions.php 1 year ago assets.php 1 year ago blocks.php 1 year ago class-acf-data.php 1 year ago class-acf-internal-post-type.php 1 year ago class-acf-options-page.php 1 year ago class-acf-site-health.php 1 year ago compatibility.php 1 year ago deprecated.php 1 year ago fields.php 1 year ago index.php 1 year ago l10n.php 1 year ago local-fields.php 1 year ago local-json.php 1 year ago local-meta.php 1 year ago locations.php 1 year ago loop.php 1 year ago media.php 1 year ago rest-api.php 1 year ago revisions.php 1 year ago scf-ui-options-page-functions.php 1 year ago third-party.php 1 year ago upgrades.php 1 year ago validation.php 1 year ago wpml.php 1 year ago
loop.php
298 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'acf_loop' ) ) :
8 #[AllowDynamicProperties]
9 class acf_loop {
10
11
12 /**
13 * This function will setup the class functionality
14 *
15 * @type function
16 * @date 5/03/2014
17 * @since ACF 5.0.0
18 *
19 * @param n/a
20 * @return n/a
21 */
22 function __construct() {
23
24 // vars
25 $this->loops = array();
26 }
27
28
29 /**
30 * This function will return true if no loops exist
31 *
32 * @type function
33 * @date 3/03/2016
34 * @since ACF 5.3.2
35 *
36 * @param n/a
37 * @return (boolean)
38 */
39 function is_empty() {
40
41 return empty( $this->loops );
42 }
43
44
45 /**
46 * This function will return true if a loop exists for the given array index
47 *
48 * @type function
49 * @date 3/03/2016
50 * @since ACF 5.3.2
51 *
52 * @param $i (int)
53 * @return (boolean)
54 */
55 function is_loop( $i = 0 ) {
56
57 return isset( $this->loops[ $i ] );
58 }
59
60
61 /**
62 * This function will return a valid array index for the given $i
63 *
64 * @type function
65 * @date 3/03/2016
66 * @since ACF 5.3.2
67 *
68 * @param $i (mixed)
69 * @return (int)
70 */
71 function get_i( $i = 0 ) {
72
73 // 'active'
74 if ( $i === 'active' ) {
75 $i = -1;
76 }
77
78 // 'previous'
79 if ( $i === 'previous' ) {
80 $i = -2;
81 }
82
83 // allow negative to look at end of loops
84 if ( $i < 0 ) {
85 $i = count( $this->loops ) + $i;
86 }
87
88 // return
89 return $i;
90 }
91
92
93 /**
94 * This function will add a new loop
95 *
96 * @type function
97 * @date 3/03/2016
98 * @since ACF 5.3.2
99 *
100 * @param $loop (array)
101 * @return n/a
102 */
103 function add_loop( $loop = array() ) {
104
105 // defaults
106 $loop = wp_parse_args(
107 $loop,
108 array(
109 'selector' => '',
110 'name' => '',
111 'value' => false,
112 'field' => false,
113 'i' => -1,
114 'post_id' => 0,
115 'key' => '',
116 )
117 );
118
119 // ensure array
120 $loop['value'] = acf_get_array( $loop['value'] );
121
122 // Re-index values if this loop starts from index 0.
123 // This allows ajax previews to work ($_POST data contains random unique array keys)
124 if ( $loop['i'] == -1 ) {
125 $loop['value'] = array_values( $loop['value'] );
126 }
127
128 // append
129 $this->loops[] = $loop;
130
131 // return
132 return $loop;
133 }
134
135
136 /**
137 * This function will update a loop's setting
138 *
139 * @type function
140 * @date 3/03/2016
141 * @since ACF 5.3.2
142 *
143 * @param $i (mixed)
144 * @param $key (string) the loop setting name
145 * @param $value (mixed) the loop setting value
146 * @return (boolean) true on success
147 */
148 function update_loop( $i = 'active', $key = null, $value = null ) {
149
150 // i
151 $i = $this->get_i( $i );
152
153 // bail early if no set
154 if ( ! $this->is_loop( $i ) ) {
155 return false;
156 }
157
158 // set
159 $this->loops[ $i ][ $key ] = $value;
160
161 // return
162 return true;
163 }
164
165
166 /**
167 * This function will return a loop, or loop's setting for a given index & key
168 *
169 * @type function
170 * @date 3/03/2016
171 * @since ACF 5.3.2
172 *
173 * @param $i (mixed)
174 * @param $key (string) the loop setting name
175 * @return (mixed) false on failure
176 */
177 function get_loop( $i = 'active', $key = null ) {
178
179 // i
180 $i = $this->get_i( $i );
181
182 // bail early if no set
183 if ( ! $this->is_loop( $i ) ) {
184 return false;
185 }
186
187 // check for key
188 if ( $key !== null ) {
189 return $this->loops[ $i ][ $key ];
190 }
191
192 // return
193 return $this->loops[ $i ];
194 }
195
196
197 /**
198 * This function will remove a loop
199 *
200 * @type function
201 * @date 3/03/2016
202 * @since ACF 5.3.2
203 *
204 * @param $i (mixed)
205 * @return (boolean) true on success
206 */
207 function remove_loop( $i = 'active' ) {
208
209 // i
210 $i = $this->get_i( $i );
211
212 // bail early if no set
213 if ( ! $this->is_loop( $i ) ) {
214 return false;
215 }
216
217 // remove
218 unset( $this->loops[ $i ] );
219
220 // reset keys
221 $this->loops = array_values( $this->loops );
222
223 // PHP 7.2 no longer resets array keys for empty value
224 if ( $this->is_empty() ) {
225 $this->loops = array();
226 }
227 }
228 }
229
230 // initialize
231 acf()->loop = new acf_loop();
232 endif; // class_exists check
233
234
235
236 /**
237 * alias of acf()->loop->add_loop()
238 *
239 * @type function
240 * @date 6/10/13
241 * @since ACF 5.0.0
242 *
243 * @param n/a
244 * @return n/a
245 */
246 function acf_add_loop( $loop = array() ) {
247
248 return acf()->loop->add_loop( $loop );
249 }
250
251
252 /**
253 * alias of acf()->loop->update_loop()
254 *
255 * @type function
256 * @date 6/10/13
257 * @since ACF 5.0.0
258 *
259 * @param n/a
260 * @return n/a
261 */
262 function acf_update_loop( $i = 'active', $key = null, $value = null ) {
263
264 return acf()->loop->update_loop( $i, $key, $value );
265 }
266
267
268 /**
269 * alias of acf()->loop->get_loop()
270 *
271 * @type function
272 * @date 6/10/13
273 * @since ACF 5.0.0
274 *
275 * @param n/a
276 * @return n/a
277 */
278 function acf_get_loop( $i = 'active', $key = null ) {
279
280 return acf()->loop->get_loop( $i, $key );
281 }
282
283
284 /**
285 * alias of acf()->loop->remove_loop()
286 *
287 * @type function
288 * @date 6/10/13
289 * @since ACF 5.0.0
290 *
291 * @param n/a
292 * @return n/a
293 */
294 function acf_remove_loop( $i = 'active' ) {
295
296 return acf()->loop->remove_loop( $i );
297 }
298