1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Name: Helpers |
4
|
|
|
* |
5
|
|
|
* Description: A holdover from Pods 1.x for backwards compatibility purposes, you most likely don't need these and we |
6
|
|
|
* recommend you use our WP filters and actions instead. |
7
|
|
|
* |
8
|
|
|
* Version: 2.3 |
9
|
|
|
* |
10
|
|
|
* Category: Advanced |
11
|
|
|
* |
12
|
|
|
* Menu Page: edit.php?post_type=_pods_helper |
13
|
|
|
* Menu Add Page: post-new.php?post_type=_pods_helper |
14
|
|
|
* |
15
|
|
|
* External: pods-helpers/pods-helpers.php |
16
|
|
|
* |
17
|
|
|
* @package Pods\Components |
18
|
|
|
* @subpackage Helpers |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
if ( class_exists( 'Pods_Helpers' ) ) { |
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
class Pods_Helpers extends PodsComponent { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Pods object |
29
|
|
|
* |
30
|
|
|
* @var object |
31
|
|
|
* |
32
|
|
|
* @since 2.0 |
33
|
|
|
*/ |
34
|
|
|
static $obj = null; |
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Object type |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
* |
41
|
|
|
* @since 2.0 |
42
|
|
|
*/ |
43
|
|
|
private $object_type = '_pods_helper'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function init() { |
49
|
|
|
|
50
|
|
|
$args = array( |
51
|
|
|
'label' => 'Pod Helpers', |
52
|
|
|
'labels' => array( 'singular_name' => 'Pod Helper' ), |
53
|
|
|
'public' => false, |
54
|
|
|
'can_export' => false, |
55
|
|
|
'show_ui' => true, |
56
|
|
|
'show_in_menu' => false, |
57
|
|
|
'query_var' => false, |
58
|
|
|
'rewrite' => false, |
59
|
|
|
'has_archive' => false, |
60
|
|
|
'hierarchical' => false, |
61
|
|
|
'supports' => array( 'title', 'author', 'revisions' ), |
62
|
|
|
'menu_icon' => 'dashicons-pods', |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
if ( ! pods_is_admin() ) { |
66
|
|
|
$args['capability_type'] = 'pods_helper'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$args = PodsInit::object_label_fix( $args, 'post_type' ); |
70
|
|
|
|
71
|
|
|
register_post_type( $this->object_type, apply_filters( 'pods_internal_register_post_type_object_helper', $args ) ); |
72
|
|
|
|
73
|
|
|
if ( is_admin() ) { |
74
|
|
|
add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 ); |
75
|
|
|
|
76
|
|
|
add_action( 'dbx_post_advanced', array( $this, 'edit_page_form' ) ); |
77
|
|
|
|
78
|
|
|
add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) ); |
79
|
|
|
add_filter( 'get_post_metadata', array( $this, 'get_meta' ), 10, 4 ); |
80
|
|
|
add_filter( 'update_post_metadata', array( $this, 'save_meta' ), 10, 4 ); |
81
|
|
|
|
82
|
|
|
add_action( 'pods_meta_save_pre_post__pods_helper', array( $this, 'fix_filters' ), 10, 5 ); |
83
|
|
|
add_action( 'post_updated', array( $this, 'clear_cache' ), 10, 3 ); |
84
|
|
|
add_action( 'delete_post', array( $this, 'clear_cache' ), 10, 1 ); |
85
|
|
|
add_filter( 'post_row_actions', array( $this, 'remove_row_actions' ), 10, 2 ); |
86
|
|
|
add_filter( 'bulk_actions-edit-' . $this->object_type, array( $this, 'remove_bulk_actions' ) ); |
87
|
|
|
|
88
|
|
|
add_filter( 'builder_layout_filter_non_layout_post_types', array( $this, 'disable_builder_layout' ) ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function disable_builder_layout( $post_types ) { |
94
|
|
|
|
95
|
|
|
$post_types[] = $this->object_type; |
96
|
|
|
|
97
|
|
|
return $post_types; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Update Post Type messages |
102
|
|
|
* |
103
|
|
|
* @param array $messages |
104
|
|
|
* |
105
|
|
|
* @return array |
|
|
|
|
106
|
|
|
* @since 2.0.2 |
107
|
|
|
*/ |
108
|
|
|
public function setup_updated_messages( $messages ) { |
109
|
|
|
|
110
|
|
|
global $post, $post_ID; |
|
|
|
|
111
|
|
|
|
112
|
|
|
$post_type = get_post_type_object( $this->object_type ); |
|
|
|
|
113
|
|
|
|
114
|
|
|
$labels = $post_type->labels; |
115
|
|
|
|
116
|
|
|
$messages[ $post_type->name ] = array( |
117
|
|
|
1 => sprintf( __( '%1$s updated. <a href="%2$s">%3$s</a>', 'pods' ), $labels->singular_name, esc_url( get_permalink( $post_ID ) ), $labels->view_item ), |
118
|
|
|
2 => __( 'Custom field updated.', 'pods' ), |
119
|
|
|
3 => __( 'Custom field deleted.', 'pods' ), |
120
|
|
|
4 => sprintf( __( '%s updated.', 'pods' ), $labels->singular_name ), |
121
|
|
|
/* translators: %s: date and time of the revision */ |
122
|
|
|
5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'pods' ), $labels->singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
123
|
|
|
6 => sprintf( __( '%1$s published. <a href="%2$s">%3$s</a>', 'pods' ), $labels->singular_name, esc_url( get_permalink( $post_ID ) ), $labels->view_item ), |
124
|
|
|
7 => sprintf( __( '%s saved.', 'pods' ), $labels->singular_name ), |
125
|
|
|
8 => sprintf( __( '%1$s submitted. <a target="_blank" href="%2$s">Preview %3$s</a>', 'pods' ), $labels->singular_name, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $labels->singular_name ), |
126
|
|
|
9 => sprintf( |
127
|
|
|
__( '%s scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview %s</a>', 'pods' ), $labels->singular_name, |
128
|
|
|
// translators: Publish box date format, see http://php.net/date |
129
|
|
|
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ), $labels->singular_name |
130
|
|
|
), |
131
|
|
|
10 => sprintf( __( '%1$s draft updated. <a target="_blank" href="%2$s">Preview %3$s</a>', 'pods' ), $labels->singular_name, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $labels->singular_name ), |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
if ( false === (boolean) $post_type->public ) { |
135
|
|
|
$messages[ $post_type->name ][1] = sprintf( __( '%s updated.', 'pods' ), $labels->singular_name ); |
136
|
|
|
$messages[ $post_type->name ][6] = sprintf( __( '%s published.', 'pods' ), $labels->singular_name ); |
137
|
|
|
$messages[ $post_type->name ][8] = sprintf( __( '%s submitted.', 'pods' ), $labels->singular_name ); |
138
|
|
|
$messages[ $post_type->name ][9] = sprintf( |
139
|
|
|
__( '%s scheduled for: <strong>%1$s</strong>.', 'pods' ), $labels->singular_name, |
140
|
|
|
// translators: Publish box date format, see http://php.net/date |
141
|
|
|
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) |
142
|
|
|
); |
143
|
|
|
$messages[ $post_type->name ][10] = sprintf( __( '%s draft updated.', 'pods' ), $labels->singular_name ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return $messages; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Enqueue styles |
151
|
|
|
* |
152
|
|
|
* @since 2.0 |
153
|
|
|
*/ |
154
|
|
|
public function admin_assets() { |
155
|
|
|
|
156
|
|
|
wp_enqueue_style( 'pods-styles' ); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Fix filters, specifically removing balanceTags |
161
|
|
|
* |
162
|
|
|
* @since 2.0.1 |
163
|
|
|
*/ |
164
|
|
|
public function fix_filters( $data, $pod = null, $id = null, $groups = null, $post = null ) { |
|
|
|
|
165
|
|
|
|
166
|
|
|
remove_filter( 'content_save_pre', 'balanceTags', 50 ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Remove unused row actions |
171
|
|
|
* |
172
|
|
|
* @since 2.0.5 |
173
|
|
|
*/ |
174
|
|
|
public function remove_row_actions( $actions, $post ) { |
|
|
|
|
175
|
|
|
|
176
|
|
|
global $current_screen; |
|
|
|
|
177
|
|
|
|
178
|
|
|
if ( ! is_object( $current_screen ) || $this->object_type != $current_screen->post_type ) { |
179
|
|
|
return $actions; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
if ( isset( $actions['view'] ) ) { |
183
|
|
|
unset( $actions['view'] ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
if ( isset( $actions['inline hide-if-no-js'] ) ) { |
187
|
|
|
unset( $actions['inline hide-if-no-js'] ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
// W3 Total Cache |
191
|
|
|
if ( isset( $actions['pgcache_purge'] ) ) { |
192
|
|
|
unset( $actions['pgcache_purge'] ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return $actions; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Remove unused bulk actions |
200
|
|
|
* |
201
|
|
|
* @since 2.0.5 |
202
|
|
|
*/ |
203
|
|
|
public function remove_bulk_actions( $actions ) { |
|
|
|
|
204
|
|
|
|
205
|
|
|
if ( isset( $actions['edit'] ) ) { |
206
|
|
|
unset( $actions['edit'] ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
return $actions; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Clear cache on save |
214
|
|
|
* |
215
|
|
|
* @since 2.0 |
216
|
|
|
*/ |
217
|
|
|
public function clear_cache( $data, $pod = null, $id = null, $groups = null, $post = null ) { |
|
|
|
|
218
|
|
|
|
219
|
|
|
$old_post = $id; |
220
|
|
|
|
221
|
|
|
if ( ! is_object( $id ) ) { |
222
|
|
|
$old_post = null; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
if ( is_object( $post ) && $this->object_type != $post->post_type ) { |
226
|
|
|
return; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
if ( ! is_array( $data ) && 0 < $data ) { |
230
|
|
|
$post = $data; |
|
|
|
|
231
|
|
|
$post = get_post( $post ); |
|
|
|
|
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
if ( $this->object_type == $post->object_type ) { |
235
|
|
|
pods_transient_clear( 'pods_object_helpers' ); |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Change post title placeholder text |
241
|
|
|
* |
242
|
|
|
* @since 2.0 |
243
|
|
|
*/ |
244
|
|
|
public function set_title_text( $text, $post ) { |
|
|
|
|
245
|
|
|
|
246
|
|
|
return __( 'Enter helper name here', 'pods' ); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Edit page form |
251
|
|
|
* |
252
|
|
|
* @since 2.0 |
253
|
|
|
*/ |
254
|
|
|
public function edit_page_form() { |
255
|
|
|
|
256
|
|
|
global $post_type; |
|
|
|
|
257
|
|
|
|
258
|
|
|
if ( $this->object_type != $post_type ) { |
259
|
|
|
return; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
add_filter( 'enter_title_here', array( $this, 'set_title_text' ), 10, 2 ); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Add meta boxes to the page |
267
|
|
|
* |
268
|
|
|
* @since 2.0 |
269
|
|
|
*/ |
270
|
|
|
public function add_meta_boxes() { |
271
|
|
|
|
272
|
|
|
$pod = array( |
273
|
|
|
'name' => $this->object_type, |
274
|
|
|
'type' => 'post_type', |
275
|
|
|
); |
276
|
|
|
|
277
|
|
|
if ( isset( PodsMeta::$post_types[ $pod['name'] ] ) ) { |
278
|
|
|
return; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
$fields = array( |
282
|
|
|
array( |
283
|
|
|
'name' => 'helper_type', |
284
|
|
|
'label' => __( 'Helper Type', 'pods' ), |
285
|
|
|
'type' => 'pick', |
286
|
|
|
'default' => 'display', |
287
|
|
|
'data' => array( |
288
|
|
|
'input' => 'Input (change form fields)', |
289
|
|
|
'display' => 'Display (change field output when using magic tags)', |
290
|
|
|
'pre_save' => 'Pre-Save (change form fields before saving)', |
291
|
|
|
'post_save' => 'Post-Save', |
292
|
|
|
'pre_delete' => 'Pre-Delete', |
293
|
|
|
'post_delete' => 'Post-Delete', |
294
|
|
|
), |
295
|
|
|
), |
296
|
|
|
array( |
297
|
|
|
'name' => 'code', |
298
|
|
|
'label' => __( 'Code', 'pods' ), |
299
|
|
|
'type' => 'code', |
300
|
|
|
), |
301
|
|
|
); |
302
|
|
|
|
303
|
|
|
pods_group_add( $pod, __( 'Helper', 'pods' ), $fields, 'normal', 'high' ); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Get the fields |
308
|
|
|
* |
309
|
|
|
* @param null $_null |
310
|
|
|
* @param null $post_ID |
311
|
|
|
* @param null $meta_key |
312
|
|
|
* @param bool $single |
313
|
|
|
* |
314
|
|
|
* @return array|bool|int|mixed|null|string|void |
315
|
|
|
*/ |
316
|
|
|
public function get_meta( $_null, $post_ID = null, $meta_key = null, $single = false ) { |
|
|
|
|
317
|
|
|
|
318
|
|
|
if ( 'code' == $meta_key ) { |
319
|
|
|
$post = get_post( $post_ID ); |
|
|
|
|
320
|
|
|
|
321
|
|
|
if ( is_object( $post ) && $this->object_type == $post->post_type ) { |
322
|
|
|
return $post->post_content; |
323
|
|
|
} |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
return $_null; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Save the fields |
331
|
|
|
* |
332
|
|
|
* @param $_null |
333
|
|
|
* @param int $post_ID |
|
|
|
|
334
|
|
|
* @param string $meta_key |
|
|
|
|
335
|
|
|
* @param string $meta_value |
|
|
|
|
336
|
|
|
* |
337
|
|
|
* @return bool|int|null |
338
|
|
|
*/ |
339
|
|
|
public function save_meta( $_null, $post_ID = null, $meta_key = null, $meta_value = null ) { |
|
|
|
|
340
|
|
|
|
341
|
|
|
if ( 'code' == $meta_key ) { |
342
|
|
|
$post = get_post( $post_ID ); |
|
|
|
|
343
|
|
|
|
344
|
|
|
if ( is_object( $post ) && $this->object_type == $post->post_type ) { |
345
|
|
|
$postdata = array( |
346
|
|
|
'ID' => $post_ID, |
347
|
|
|
'post_content' => $meta_value, |
348
|
|
|
); |
349
|
|
|
|
350
|
|
|
remove_filter( current_filter(), array( $this, __FUNCTION__ ) ); |
351
|
|
|
|
352
|
|
|
$revisions = false; |
353
|
|
|
|
354
|
|
|
if ( has_action( 'pre_post_update', 'wp_save_post_revision' ) ) { |
355
|
|
|
remove_action( 'pre_post_update', 'wp_save_post_revision' ); |
356
|
|
|
|
357
|
|
|
$revisions = true; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
wp_update_post( (object) $postdata ); |
361
|
|
|
// objects will be automatically sanitized |
362
|
|
|
if ( $revisions ) { |
363
|
|
|
add_action( 'pre_post_update', 'wp_save_post_revision' ); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
return true; |
367
|
|
|
}//end if |
368
|
|
|
}//end if |
369
|
|
|
|
370
|
|
|
return $_null; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* @static |
375
|
|
|
* |
376
|
|
|
* Run a helper within a Pod Page or WP Template |
377
|
|
|
* |
378
|
|
|
* $params['helper'] string Helper name |
379
|
|
|
* $params['value'] string Value to run Helper on |
380
|
|
|
* $params['name'] string Field name |
381
|
|
|
* |
382
|
|
|
* @param array $params An associative array of parameters |
383
|
|
|
* @param null $obj |
384
|
|
|
* |
385
|
|
|
* @return mixed Anything returned by the helper |
386
|
|
|
* @since 2.0 |
387
|
|
|
*/ |
388
|
|
|
public static function helper( $params, $obj = null ) { |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* @var $obj Pods |
392
|
|
|
*/ |
393
|
|
|
if ( ! empty( $obj ) ) { |
394
|
|
|
self::$obj =& $obj; |
395
|
|
|
} else { |
396
|
|
|
$obj =& self::$obj; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
if ( empty( $obj ) || ! is_object( $obj ) ) { |
400
|
|
|
return ''; |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
$defaults = array( |
404
|
|
|
'helper' => '', |
405
|
|
|
'value' => '', |
406
|
|
|
'name' => '', |
407
|
|
|
'deprecated' => false, |
408
|
|
|
); |
409
|
|
|
|
410
|
|
|
if ( is_array( $params ) ) { |
411
|
|
|
$params = array_merge( $defaults, $params ); |
412
|
|
|
} else { |
413
|
|
|
$params = $defaults; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
$params = (object) $params; |
417
|
|
|
|
418
|
|
|
if ( empty( $params->helper ) ) { |
419
|
|
|
return pods_error( 'Helper name required', $obj ); |
420
|
|
|
} elseif ( ! is_array( $params->helper ) ) { |
421
|
|
|
$params->helper = trim( $params->helper ); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
if ( ! isset( $params->value ) ) { |
425
|
|
|
$params->value = null; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
if ( true === $params->deprecated && is_array( $params->value ) && ! empty( $params->value ) && ! isset( $params->value[0] ) ) { |
429
|
|
|
$params->value = array( $params->value ); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
if ( ! isset( $params->name ) ) { |
433
|
|
|
$params->name = null; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
$helper = $obj->api->load_helper( array( 'name' => $params->helper ) ); |
437
|
|
|
|
438
|
|
|
ob_start(); |
439
|
|
|
|
440
|
|
|
if ( ! empty( $helper ) && ! empty( $helper['code'] ) ) { |
441
|
|
|
$code = $helper['code']; |
442
|
|
|
|
443
|
|
|
$code = str_replace( '$this->', '$obj->', $code ); |
444
|
|
|
|
445
|
|
|
$value =& $params->value; |
446
|
|
|
$name =& $params->name; |
447
|
|
|
|
448
|
|
|
$_safe_params = $params; |
449
|
|
|
|
450
|
|
|
if ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) { |
451
|
|
|
eval( "?>{$code}" ); |
|
|
|
|
452
|
|
|
} else { |
453
|
|
|
echo $code; |
454
|
|
|
} |
455
|
|
|
|
456
|
|
|
$params = $_safe_params; |
457
|
|
|
} elseif ( is_callable( (string) $params->helper ) ) { |
458
|
|
|
$params->helper = (string) $params->helper; |
459
|
|
|
|
460
|
|
|
$disallowed = array( |
461
|
|
|
'system', |
462
|
|
|
'exec', |
463
|
|
|
'popen', |
464
|
|
|
'eval', |
465
|
|
|
'preg_replace', |
466
|
|
|
'create_function', |
467
|
|
|
'include', |
468
|
|
|
'include_once', |
469
|
|
|
'require', |
470
|
|
|
'require_once', |
471
|
|
|
); |
472
|
|
|
|
473
|
|
|
$allowed = array(); |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* Allows adjusting the disallowed callbacks as needed. |
477
|
|
|
* |
478
|
|
|
* @param array $disallowed List of callbacks not allowed. |
479
|
|
|
* @param array $params Parameters used by Pods::helper() method. |
480
|
|
|
* |
481
|
|
|
* @since 2.7 |
482
|
|
|
*/ |
483
|
|
|
$disallowed = apply_filters( 'pods_helper_disallowed_callbacks', $disallowed, get_object_vars( $params ) ); |
484
|
|
|
|
485
|
|
|
/** |
486
|
|
|
* Allows adjusting the allowed allowed callbacks as needed. |
487
|
|
|
* |
488
|
|
|
* @param array $allowed List of callbacks explicitly allowed. |
489
|
|
|
* @param array $params Parameters used by Pods::helper() method. |
490
|
|
|
* |
491
|
|
|
* @since 2.7 |
492
|
|
|
*/ |
493
|
|
|
$allowed = apply_filters( 'pods_helper_allowed_callbacks', $allowed, get_object_vars( $params ) ); |
494
|
|
|
|
495
|
|
|
// Clean up helper callback (if string) |
496
|
|
|
$params->helper = strip_tags( str_replace( array( '`', chr( 96 ) ), "'", $params->helper ) ); |
497
|
|
|
|
498
|
|
|
$is_allowed = false; |
499
|
|
|
|
500
|
|
|
if ( ! empty( $allowed ) ) { |
501
|
|
|
if ( in_array( $params->helper, $allowed, true ) ) { |
502
|
|
|
$is_allowed = true; |
503
|
|
|
} |
504
|
|
|
} elseif ( ! in_array( $params->helper, $disallowed, true ) ) { |
505
|
|
|
$is_allowed = true; |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
if ( $is_allowed ) { |
509
|
|
|
echo call_user_func( $params->helper, $params->value, $params->name, $params, $obj ); |
510
|
|
|
} |
511
|
|
|
}//end if |
512
|
|
|
|
513
|
|
|
$out = ob_get_clean(); |
514
|
|
|
|
515
|
|
|
$out = apply_filters( 'pods_helpers_post_helper', $out, $params, $helper ); |
516
|
|
|
$out = apply_filters( 'pods_helpers_post_helper_' . $helper['slug'], $out, $params, $helper ); |
517
|
|
|
|
518
|
|
|
return $out; |
519
|
|
|
} |
520
|
|
|
} |
521
|
|
|
|
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.