Completed
Pull Request — 2.x (#4855)
by Scott Kingsley
06:03
created

acf.php ➔ delete_sub_field()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 25 and the first side effect is on line 106.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Compatibility functions for integration with other plugins.
4
 */
5
6
/**
7
 * Enable backwards compatibility with ACF functions.
8
 *
9
 * @param bool $acf_backwards_compatibility Whether to enable backwards compatibility for ACF functions.
10
 *
11
 * @since 2.7.2
12
 */
13
$acf_backwards_compatibility = apply_filters( 'pods_acf_backwards_compatibility', true );
14
15
if ( $acf_backwards_compatibility ) {
16
	if ( ! function_exists( 'the_field' ) ) {
17
		/**
18
		 * Backwards compatibility function for the_field() from ACF.
19
		 *
20
		 * @param string|array $field The field name, or an associative array of parameters.
21
		 * @param mixed|false  $id    The ID or slug to load a single item, array of $params to run find.
22
		 *
23
		 * @since 2.7.2
24
		 */
25
		function the_field( $field, $id = false ) {
26
			echo pods_field_display( null, $id, $field, true );
27
		}
28
	}
29
30
	if ( ! function_exists( 'get_field' ) ) {
31
		/**
32
		 * Backwards compatibility function for get_field() from ACF.
33
		 *
34
		 * @param string|array $field The field name, or an associative array of parameters.
35
		 * @param mixed|false  $id    The ID or slug to load a single item, array of $params to run find.
36
		 *
37
		 * @return mixed Field value.
38
		 *
39
		 * @since 2.7.2
40
		 */
41
		function get_field( $field, $id = false ) {
42
			return pods_field( null, $id, $field, true );
43
		}
44
	}
45
46
	if ( ! function_exists( 'update_field' ) ) {
47
		/**
48
		 * Backwards compatibility function for update_field() from ACF.
49
		 *
50
		 * @param string|array $field The field name, or an associative array of parameters.
51
		 * @param mixed        $value The value to save.
52
		 * @param mixed|false  $id    The ID or slug to load a single item, array of $params to run find.
53
		 *
54
		 * @return int|false The item ID or false if not saved.
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|array|false? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
55
		 *
56
		 * @since 2.7.2
57
		 */
58
		function update_field( $field, $value, $id = false ) {
59
			return pods_field_update( null, $id, $field, $value );
60
		}
61
	}
62
63
	if ( ! function_exists( 'delete_field' ) ) {
64
		/**
65
		 * Backwards compatibility function for delete_field() from ACF.
66
		 *
67
		 * @param string|array $field The field name, or an associative array of parameters.
68
		 * @param mixed|false  $id    The ID or slug to load a single item, array of $params to run find.
69
		 *
70
		 * @return int|false The item ID or false if not saved.
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|array|false? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
71
		 *
72
		 * @since 2.7.2
73
		 */
74
		function delete_field( $field, $id = false ) {
75
			return pods_field_update( null, $id, $field, null );
76
		}
77
	}
78
79
	if ( ! shortcode_exists( 'acf' ) ) {
80
		/**
81
		 * Backwards compatibility function for [acf] shortcode from ACF.
82
		 *
83
		 * @param array  $tags    An associative array of shortcode properties.
84
		 * @param string $content A string that represents a template override.
85
		 *
86
		 * @return string
87
		 *
88
		 * @since 2.7.2
89
		 */
90
		function pods_acf_shortcode( $tags, $content ) {
91
92
			$post_id = null;
93
94
			if ( ! empty( $tags['post_id'] ) ) {
95
				$post_id = $tags['post_id'];
96
			}
97
98
			$tags = array(
99
				'field' => $tags['field'],
100
				'id'    => $post_id,
101
			);
102
103
			return pods_shortcode( $tags, $content );
104
		}
105
106
		add_shortcode( 'acf', 'pods_acf_shortcode' );
107
	}
108
109
	/**
110
	 * These functions below will do nothing for now. We might add some sort of further compatibility later.
111
	 */
112
113
	if ( ! function_exists( 'get_field_object' ) ) {
114
		/**
115
		 * Backwards compatibility function for get_field_object() from ACF.
116
		 *
117
		 * @return array
118
		 *
119
		 * @since 2.7.2
120
		 */
121
		function get_field_object() {
122
			return array();
123
		}
124
	}
125
126
	if ( ! function_exists( 'get_fields' ) ) {
127
		/**
128
		 * Backwards compatibility function for get_fields() from ACF.
129
		 *
130
		 * @return array
131
		 *
132
		 * @since 2.7.2
133
		 */
134
		function get_fields() {
135
			return array();
136
		}
137
	}
138
139
	if ( ! function_exists( 'get_field_objects' ) ) {
140
		/**
141
		 * Backwards compatibility function for get_field_objects() from ACF.
142
		 *
143
		 * @return array
144
		 *
145
		 * @since 2.7.2
146
		 */
147
		function get_field_objects() {
148
			return array();
149
		}
150
	}
151
152
	if ( ! function_exists( 'have_rows' ) ) {
153
		/**
154
		 * Backwards compatibility function for have_rows() from ACF.
155
		 *
156
		 * @return false
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
157
		 *
158
		 * @since 2.7.2
159
		 */
160
		function have_rows() {
161
			return false;
162
		}
163
	}
164
165
	if ( ! function_exists( 'get_sub_field' ) ) {
166
		/**
167
		 * Backwards compatibility function for get_sub_field() from ACF.
168
		 *
169
		 * @return false
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
170
		 *
171
		 * @since 2.7.2
172
		 */
173
		function get_sub_field() {
174
			return false;
175
		}
176
	}
177
178
	if ( ! function_exists( 'the_sub_field' ) ) {
179
		/**
180
		 * Backwards compatibility function for the_sub_field() from ACF.
181
		 *
182
		 * @return null
183
		 *
184
		 * @since 2.7.2
185
		 */
186
		function the_sub_field() {
187
			return null;
188
		}
189
	}
190
191
	if ( ! function_exists( 'get_sub_field_object' ) ) {
192
		/**
193
		 * Backwards compatibility function for get_sub_field_object() from ACF.
194
		 *
195
		 * @return array
196
		 *
197
		 * @since 2.7.2
198
		 */
199
		function get_sub_field_object() {
200
			return array();
201
		}
202
	}
203
204
	if ( ! function_exists( 'get_row' ) ) {
205
		/**
206
		 * Backwards compatibility function for get_row() from ACF.
207
		 *
208
		 * @return array
209
		 *
210
		 * @since 2.7.2
211
		 */
212
		function get_row() {
213
			return array();
214
		}
215
	}
216
217
	if ( ! function_exists( 'get_row_index' ) ) {
218
		/**
219
		 * Backwards compatibility function for get_row_index() from ACF.
220
		 *
221
		 * @return int
222
		 *
223
		 * @since 2.7.2
224
		 */
225
		function get_row_index() {
226
			return 0;
227
		}
228
	}
229
230
	if ( ! function_exists( 'get_row_layout' ) ) {
231
		/**
232
		 * Backwards compatibility function for get_row_layout() from ACF.
233
		 *
234
		 * @return null
235
		 *
236
		 * @since 2.7.2
237
		 */
238
		function get_row_layout() {
239
			return null;
240
		}
241
	}
242
243
	if ( ! function_exists( 'delete_sub_field' ) ) {
244
		/**
245
		 * Backwards compatibility function for delete_sub_field() from ACF.
246
		 *
247
		 * @return null
248
		 *
249
		 * @since 2.7.2
250
		 */
251
		function delete_sub_field() {
252
			return null;
253
		}
254
	}
255
256
	if ( ! function_exists( 'update_sub_field' ) ) {
257
		/**
258
		 * Backwards compatibility function for update_sub_field() from ACF.
259
		 *
260
		 * @return null
261
		 *
262
		 * @since 2.7.2
263
		 */
264
		function update_sub_field() {
265
			return null;
266
		}
267
	}
268
269
	if ( ! function_exists( 'add_row' ) ) {
270
		/**
271
		 * Backwards compatibility function for add_row() from ACF.
272
		 *
273
		 * @return null
274
		 *
275
		 * @since 2.7.2
276
		 */
277
		function add_row() {
278
			return null;
279
		}
280
	}
281
282
	if ( ! function_exists( 'update_row' ) ) {
283
		/**
284
		 * Backwards compatibility function for update_row() from ACF.
285
		 *
286
		 * @return null
287
		 *
288
		 * @since 2.7.2
289
		 */
290
		function update_row() {
291
			return null;
292
		}
293
	}
294
295
	if ( ! function_exists( 'delete_row' ) ) {
296
		/**
297
		 * Backwards compatibility function for delete_row() from ACF.
298
		 *
299
		 * @return null
300
		 *
301
		 * @since 2.7.2
302
		 */
303
		function delete_row() {
304
			return null;
305
		}
306
	}
307
308
	if ( ! function_exists( 'add_sub_row' ) ) {
309
		/**
310
		 * Backwards compatibility function for add_sub_row() from ACF.
311
		 *
312
		 * @return null
313
		 *
314
		 * @since 2.7.2
315
		 */
316
		function add_sub_row() {
317
			return null;
318
		}
319
	}
320
321
	if ( ! function_exists( 'update_sub_row' ) ) {
322
		/**
323
		 * Backwards compatibility function for update_sub_row() from ACF.
324
		 *
325
		 * @return null
326
		 *
327
		 * @since 2.7.2
328
		 */
329
		function update_sub_row() {
330
			return null;
331
		}
332
	}
333
334
	if ( ! function_exists( 'delete_sub_row' ) ) {
335
		/**
336
		 * Backwards compatibility function for delete_sub_row() from ACF.
337
		 *
338
		 * @return null
339
		 *
340
		 * @since 2.7.2
341
		 */
342
		function delete_sub_row() {
343
			return null;
344
		}
345
	}
346
347
	if ( ! function_exists( 'acf_add_options_page' ) ) {
348
		/**
349
		 * Backwards compatibility function for acf_add_options_page() from ACF.
350
		 *
351
		 * @return null
352
		 *
353
		 * @since 2.7.2
354
		 */
355
		function acf_add_options_page() {
356
			return null;
357
		}
358
	}
359
360
	if ( ! function_exists( 'acf_add_options_sub_page' ) ) {
361
		/**
362
		 * Backwards compatibility function for acf_add_options_sub_page() from ACF.
363
		 *
364
		 * @return null
365
		 *
366
		 * @since 2.7.2
367
		 */
368
		function acf_add_options_sub_page() {
369
			return null;
370
		}
371
	}
372
373
	if ( ! function_exists( 'acf_form_head' ) ) {
374
		/**
375
		 * Backwards compatibility function for acf_form_head() from ACF.
376
		 *
377
		 * @return null
378
		 *
379
		 * @since 2.7.2
380
		 */
381
		function acf_form_head() {
382
			return null;
383
		}
384
	}
385
386
	if ( ! function_exists( 'acf_form' ) ) {
387
		/**
388
		 * Backwards compatibility function for acf_form() from ACF.
389
		 *
390
		 * @return null
391
		 *
392
		 * @since 2.7.2
393
		 */
394
		function acf_form() {
395
			return null;
396
		}
397
	}
398
399
	if ( ! function_exists( 'acf_register_form' ) ) {
400
		/**
401
		 * Backwards compatibility function for acf_register_form() from ACF.
402
		 *
403
		 * @return null
404
		 *
405
		 * @since 2.7.2
406
		 */
407
		function acf_register_form() {
408
			return null;
409
		}
410
	}
411
}
412