1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Name: Templates |
4
|
|
|
* |
5
|
|
|
* Description: An easy to use templating engine for Pods. Use {@field_name} magic tags to output values, within your HTML markup. |
6
|
|
|
* |
7
|
|
|
* Version: 2.3 |
8
|
|
|
* |
9
|
|
|
* Category: Advanced |
10
|
|
|
* |
11
|
|
|
* Menu Page: edit.php?post_type=_pods_template |
12
|
|
|
* Menu Add Page: post-new.php?post_type=_pods_template |
13
|
|
|
* |
14
|
|
|
* @package Pods\Components |
15
|
|
|
* @subpackage Templates |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
// Pull in the functions |
19
|
|
|
require_once( plugin_dir_path( __FILE__ ) . '/includes/functions-view_template.php' ); |
20
|
|
|
require_once( plugin_dir_path( __FILE__ ) . '/includes/functions-pod_reference.php' ); |
21
|
|
|
|
22
|
|
|
// Pull in the Frontier Template System |
23
|
|
|
require_once( plugin_dir_path( __FILE__ ) . 'class-pods_templates.php' ); |
24
|
|
|
|
25
|
|
|
//Pull in Auto Template |
26
|
|
|
require_once( dirname( __FILE__ ) . '/includes/auto-template/Pods_Templates_Auto_Template_Settings.php' ); |
27
|
|
|
new Pods_Templates_Auto_Template_Settings(); |
28
|
|
|
|
29
|
|
|
Pods_Templates_Frontier::get_instance(); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class Pods_Templates extends PodsComponent { |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Pods object |
36
|
|
|
* |
37
|
|
|
* @var object |
38
|
|
|
* |
39
|
|
|
* @since 2.0 |
40
|
|
|
*/ |
41
|
|
|
static $obj = null; |
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Whether to enable deprecated functionality based on old function usage |
45
|
|
|
* |
46
|
|
|
* @var bool |
47
|
|
|
* |
48
|
|
|
* @since 2.0 |
49
|
|
|
*/ |
50
|
|
|
static $deprecated = false; |
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Object type |
54
|
|
|
* |
55
|
|
|
* @var string |
56
|
|
|
* |
57
|
|
|
* @since 2.0 |
58
|
|
|
*/ |
59
|
|
|
private $object_type = '_pods_template'; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The capability type. |
63
|
|
|
* @link https://codex.wordpress.org/Function_Reference/register_post_type |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
private $capability_type = 'pods_template'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Do things like register/enqueue scripts and stylesheets |
70
|
|
|
* |
71
|
|
|
* @since 2.0 |
72
|
|
|
*/ |
73
|
|
|
public function __construct () { |
74
|
|
|
$args = array( |
75
|
|
|
'label' => 'Pod Templates', |
76
|
|
|
'labels' => array( 'singular_name' => 'Pod Template' ), |
77
|
|
|
'public' => false, |
78
|
|
|
'can_export' => false, |
79
|
|
|
'show_ui' => true, |
80
|
|
|
'show_in_menu' => false, |
81
|
|
|
'query_var' => false, |
82
|
|
|
'rewrite' => false, |
83
|
|
|
'has_archive' => false, |
84
|
|
|
'hierarchical' => false, |
85
|
|
|
'supports' => array( 'title', 'author', 'revisions' ), |
86
|
|
|
'menu_icon' => 'dashicons-pods' |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
if ( !pods_is_admin() ) |
90
|
|
|
$args[ 'capability_type' ] = $this->capability_type; |
91
|
|
|
|
92
|
|
|
$args = PodsInit::object_label_fix( $args, 'post_type' ); |
93
|
|
|
|
94
|
|
|
register_post_type( $this->object_type, apply_filters( 'pods_internal_register_post_type_object_template', $args ) ); |
95
|
|
|
|
96
|
|
View Code Duplication |
if ( is_admin() ) { |
97
|
|
|
add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 ); |
98
|
|
|
|
99
|
|
|
add_action( 'dbx_post_advanced', array( $this, 'edit_page_form' ), 10 ); |
100
|
|
|
|
101
|
|
|
add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) ); |
102
|
|
|
|
103
|
|
|
add_filter( 'get_post_metadata', array( $this, 'get_meta' ), 10, 4 ); |
104
|
|
|
add_filter( 'update_post_metadata', array( $this, 'save_meta' ), 10, 4 ); |
105
|
|
|
|
106
|
|
|
add_action( 'pods_meta_save_pre_post__pods_template', array( $this, 'fix_filters' ), 10, 5 ); |
107
|
|
|
add_action( 'post_updated', array( $this, 'clear_cache' ), 10, 3 ); |
108
|
|
|
add_action( 'delete_post', array( $this, 'clear_cache' ), 10, 1 ); |
109
|
|
|
add_filter( 'post_row_actions', array( $this, 'remove_row_actions' ), 10, 2 ); |
110
|
|
|
add_filter( 'bulk_actions-edit-' . $this->object_type, array( $this, 'remove_bulk_actions' ) ); |
111
|
|
|
|
112
|
|
|
add_filter( 'builder_layout_filter_non_layout_post_types', array( $this, 'disable_builder_layout' ) ); |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
add_filter( 'members_get_capabilities', array( $this, 'get_capabilities' ) ); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
View Code Duplication |
public function get_capabilities( $caps ) { |
|
|
|
|
120
|
|
|
$caps = array_merge( $caps, array( |
121
|
|
|
'edit_' . $this->capability_type, |
122
|
|
|
'read_' . $this->capability_type, |
123
|
|
|
'delete_' . $this->capability_type, |
124
|
|
|
'edit_' . $this->capability_type . 's', |
125
|
|
|
'edit_others_' . $this->capability_type . 's', |
126
|
|
|
'publish_' . $this->capability_type . 's', |
127
|
|
|
'read_private_' . $this->capability_type . 's', |
128
|
|
|
'edit_' . $this->capability_type . 's', |
129
|
|
|
) ); |
130
|
|
|
return $caps; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function disable_builder_layout ( $post_types ) { |
134
|
|
|
$post_types[] = $this->object_type; |
135
|
|
|
|
136
|
|
|
return $post_types; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Update Post Type messages |
141
|
|
|
* |
142
|
|
|
* @param array $messages |
143
|
|
|
* |
144
|
|
|
* @return array |
145
|
|
|
* @since 2.0.2 |
146
|
|
|
*/ |
147
|
|
View Code Duplication |
public function setup_updated_messages ( $messages ) { |
|
|
|
|
148
|
|
|
global $post, $post_ID; |
|
|
|
|
149
|
|
|
|
150
|
|
|
$post_type = get_post_type_object( $this->object_type ); |
151
|
|
|
|
152
|
|
|
$labels = $post_type->labels; |
153
|
|
|
|
154
|
|
|
$messages[ $post_type->name ] = array( |
155
|
|
|
1 => sprintf( __( '%s updated. <a href="%s">%s</a>', 'pods' ), $labels->singular_name, esc_url( get_permalink( $post_ID ) ), $labels->view_item ), |
156
|
|
|
2 => __( 'Custom field updated.', 'pods' ), |
157
|
|
|
3 => __( 'Custom field deleted.', 'pods' ), |
158
|
|
|
4 => sprintf( __( '%s updated.', 'pods' ), $labels->singular_name ), |
159
|
|
|
/* translators: %s: date and time of the revision */ |
160
|
|
|
5 => isset( $_GET[ 'revision' ] ) ? sprintf( __( '%s restored to revision from %s', 'pods' ), $labels->singular_name, wp_post_revision_title( (int) $_GET[ 'revision' ], false ) ) : false, |
161
|
|
|
6 => sprintf( __( '%s published. <a href="%s">%s</a>', 'pods' ), $labels->singular_name, esc_url( get_permalink( $post_ID ) ), $labels->view_item ), |
162
|
|
|
7 => sprintf( __( '%s saved.', 'pods' ), $labels->singular_name ), |
163
|
|
|
8 => sprintf( __( '%s submitted. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), |
164
|
|
|
$labels->singular_name, |
165
|
|
|
esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), |
166
|
|
|
$labels->singular_name |
167
|
|
|
), |
168
|
|
|
9 => sprintf( __( '%s scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview %s</a>', 'pods' ), |
169
|
|
|
$labels->singular_name, |
170
|
|
|
// translators: Publish box date format, see http://php.net/date |
171
|
|
|
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), |
172
|
|
|
esc_url( get_permalink( $post_ID ) ), |
173
|
|
|
$labels->singular_name |
174
|
|
|
), |
175
|
|
|
10 => sprintf( __( '%s draft updated. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), $labels->singular_name, esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), $labels->singular_name ) |
176
|
|
|
); |
177
|
|
|
|
178
|
|
|
if ( false === (boolean) $post_type->public ) { |
179
|
|
|
$messages[ $post_type->name ][ 1 ] = sprintf( __( '%s updated.', 'pods' ), $labels->singular_name ); |
180
|
|
|
$messages[ $post_type->name ][ 6 ] = sprintf( __( '%s published.', 'pods' ), $labels->singular_name ); |
181
|
|
|
$messages[ $post_type->name ][ 8 ] = sprintf( __( '%s submitted.', 'pods' ), $labels->singular_name ); |
182
|
|
|
$messages[ $post_type->name ][ 9 ] = sprintf( __( '%s scheduled for: <strong>%1$s</strong>.', 'pods' ), |
183
|
|
|
$labels->singular_name, |
184
|
|
|
// translators: Publish box date format, see http://php.net/date |
185
|
|
|
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) |
186
|
|
|
); |
187
|
|
|
$messages[ $post_type->name ][ 10 ] = sprintf( __( '%s draft updated.', 'pods' ), $labels->singular_name ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
return $messages; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Enqueue styles |
195
|
|
|
* |
196
|
|
|
* @since 2.0 |
197
|
|
|
*/ |
198
|
|
|
public function admin_assets () { |
199
|
|
|
wp_enqueue_style( 'pods-admin' ); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Fix filters, specifically removing balanceTags |
204
|
|
|
* |
205
|
|
|
* @since 2.0.1 |
206
|
|
|
*/ |
207
|
|
|
public function fix_filters ( $data, $pod = null, $id = null, $groups = null, $post = null ) { |
208
|
|
|
remove_filter( 'content_save_pre', 'balanceTags', 50 ); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Remove unused row actions |
213
|
|
|
* |
214
|
|
|
* @since 2.0.5 |
215
|
|
|
*/ |
216
|
|
View Code Duplication |
function remove_row_actions ( $actions, $post ) { |
|
|
|
|
217
|
|
|
global $current_screen; |
|
|
|
|
218
|
|
|
|
219
|
|
|
if ( !is_object( $current_screen ) || $this->object_type != $current_screen->post_type ) |
220
|
|
|
return $actions; |
221
|
|
|
|
222
|
|
|
if ( isset( $actions[ 'view' ] ) ) |
223
|
|
|
unset( $actions[ 'view' ] ); |
224
|
|
|
|
225
|
|
|
if ( isset( $actions[ 'inline hide-if-no-js' ] ) ) |
226
|
|
|
unset( $actions[ 'inline hide-if-no-js' ] ); |
227
|
|
|
|
228
|
|
|
// W3 Total Cache |
229
|
|
|
if ( isset( $actions[ 'pgcache_purge' ] ) ) |
230
|
|
|
unset( $actions[ 'pgcache_purge' ] ); |
231
|
|
|
|
232
|
|
|
return $actions; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Remove unused bulk actions |
237
|
|
|
* |
238
|
|
|
* @since 2.0.5 |
239
|
|
|
*/ |
240
|
|
|
public function remove_bulk_actions ( $actions ) { |
241
|
|
|
if ( isset( $actions[ 'edit' ] ) ) |
242
|
|
|
unset( $actions[ 'edit' ] ); |
243
|
|
|
|
244
|
|
|
return $actions; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Clear cache on save |
249
|
|
|
* |
250
|
|
|
* @since 2.0 |
251
|
|
|
*/ |
252
|
|
View Code Duplication |
public function clear_cache ( $data, $pod = null, $id = null, $groups = null, $post = null ) { |
|
|
|
|
253
|
|
|
$old_post = $id; |
254
|
|
|
|
255
|
|
|
if ( !is_object( $id ) ) |
256
|
|
|
$old_post = null; |
257
|
|
|
|
258
|
|
|
if ( is_object( $post ) && $this->object_type != $post->post_type ) |
259
|
|
|
return; |
260
|
|
|
|
261
|
|
|
if ( !is_array( $data ) && 0 < $data ) { |
262
|
|
|
$post = $data; |
263
|
|
|
$post = get_post( $post ); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
if ( $this->object_type == $post->object_type ) |
267
|
|
|
pods_transient_clear( 'pods_object_templates' ); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Change post title placeholder text |
272
|
|
|
* |
273
|
|
|
* @since 2.0 |
274
|
|
|
*/ |
275
|
|
|
public function set_title_text ( $text, $post ) { |
276
|
|
|
return __( 'Enter template name here', 'pods' ); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Edit page form |
281
|
|
|
* |
282
|
|
|
* @since 2.0 |
283
|
|
|
*/ |
284
|
|
View Code Duplication |
public function edit_page_form () { |
|
|
|
|
285
|
|
|
global $post_type; |
|
|
|
|
286
|
|
|
|
287
|
|
|
if ( $this->object_type != $post_type ) |
288
|
|
|
return; |
289
|
|
|
|
290
|
|
|
add_filter( 'enter_title_here', array( $this, 'set_title_text' ), 10, 2 ); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Add meta boxes to the page |
295
|
|
|
* |
296
|
|
|
* @since 2.0 |
297
|
|
|
*/ |
298
|
|
|
public function add_meta_boxes () { |
299
|
|
|
$pod = array( |
300
|
|
|
'name' => $this->object_type, |
301
|
|
|
'type' => 'post_type' |
302
|
|
|
); |
303
|
|
|
|
304
|
|
|
if ( isset( PodsMeta::$post_types[ $pod[ 'name' ] ] ) ) |
305
|
|
|
return; |
306
|
|
|
|
307
|
|
|
$fields = array( |
308
|
|
|
array( |
309
|
|
|
'name' => 'admin_only', |
310
|
|
|
'label' => __( 'Show to Admins Only?', 'pods' ), |
311
|
|
|
'default' => 0, |
312
|
|
|
'type' => 'boolean', |
313
|
|
|
'dependency' => true |
314
|
|
|
), |
315
|
|
|
array( |
316
|
|
|
'name' => 'restrict_capability', |
317
|
|
|
'label' => __( 'Restrict access by Capability?', 'pods' ), |
318
|
|
|
'help' => array( |
319
|
|
|
__( '<h6>Capabilities</h6> Capabilities denote access to specific functionality in WordPress, and are assigned to specific User Roles. Please see the Roles and Capabilities component in Pods for an easy tool to add your own capabilities and roles.', 'pods' ), |
320
|
|
|
'http://codex.wordpress.org/Roles_and_Capabilities' |
321
|
|
|
), |
322
|
|
|
'default' => 0, |
323
|
|
|
'type' => 'boolean', |
324
|
|
|
'dependency' => true |
325
|
|
|
), |
326
|
|
|
array( |
327
|
|
|
'name' => 'capability_allowed', |
328
|
|
|
'label' => __( 'Capability Allowed', 'pods' ), |
329
|
|
|
'type' => 'pick', |
330
|
|
|
'pick_object' => 'capability', |
331
|
|
|
'pick_format_type' => 'multi', |
332
|
|
|
'pick_format_multi' => 'autocomplete', |
333
|
|
|
'pick_ajax' => false, |
334
|
|
|
'default' => '', |
335
|
|
|
'depends-on' => array( |
336
|
|
|
'restrict_capability' => true |
337
|
|
|
) |
338
|
|
|
) |
339
|
|
|
); |
340
|
|
|
|
341
|
|
|
pods_group_add( $pod, __( 'Restrict Access', 'pods' ), $fields, 'normal', 'high' ); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Get the fields |
346
|
|
|
* |
347
|
|
|
* @param null $_null |
348
|
|
|
* @param int $post_ID |
349
|
|
|
* @param string $meta_key |
350
|
|
|
* @param bool $single |
351
|
|
|
* |
352
|
|
|
* @return array|bool|int|mixed|null|string|void |
353
|
|
|
*/ |
354
|
|
View Code Duplication |
public function get_meta ( $_null, $post_ID = null, $meta_key = null, $single = false ) { |
|
|
|
|
355
|
|
|
if ( 'code' == $meta_key ) { |
356
|
|
|
$post = get_post( $post_ID ); |
357
|
|
|
|
358
|
|
|
if ( is_object( $post ) && $this->object_type == $post->post_type ) |
359
|
|
|
return $post->post_content; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
return $_null; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Save the fields |
367
|
|
|
* |
368
|
|
|
* @param $_null |
369
|
|
|
* @param int $post_ID |
370
|
|
|
* @param string $meta_key |
371
|
|
|
* @param string $meta_value |
372
|
|
|
* |
373
|
|
|
* @return bool|int|null |
374
|
|
|
*/ |
375
|
|
View Code Duplication |
public function save_meta ( $_null, $post_ID = null, $meta_key = null, $meta_value = null ) { |
|
|
|
|
376
|
|
|
if ( 'code' == $meta_key ) { |
377
|
|
|
$post = get_post( $post_ID ); |
378
|
|
|
|
379
|
|
|
if ( is_object( $post ) && $this->object_type == $post->post_type ) { |
380
|
|
|
$postdata = array( |
381
|
|
|
'ID' => $post_ID, |
382
|
|
|
'post_content' => $meta_value |
383
|
|
|
); |
384
|
|
|
|
385
|
|
|
remove_filter( current_filter(), array( $this, __FUNCTION__ ), 10 ); |
386
|
|
|
|
387
|
|
|
$revisions = false; |
388
|
|
|
|
389
|
|
|
if ( has_action( 'pre_post_update', 'wp_save_post_revision' ) ) { |
390
|
|
|
remove_action( 'pre_post_update', 'wp_save_post_revision' ); |
391
|
|
|
|
392
|
|
|
$revisions = true; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
wp_update_post( (object) $postdata ); // objects will be automatically sanitized |
396
|
|
|
|
397
|
|
|
if ( $revisions ) |
398
|
|
|
add_action( 'pre_post_update', 'wp_save_post_revision' ); |
399
|
|
|
|
400
|
|
|
return true; |
401
|
|
|
} |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
return $_null; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Display the page template |
409
|
|
|
* |
410
|
|
|
* @param string $template_name The template name |
411
|
|
|
* @param string $code Custom template code to use instead |
412
|
|
|
* @param object $obj The Pods object |
413
|
|
|
* @param bool $deprecated Whether to use deprecated functionality based on old function usage |
414
|
|
|
* |
415
|
|
|
* @return mixed|string|void |
416
|
|
|
* @since 2.0 |
417
|
|
|
*/ |
418
|
|
|
public static function template ( $template_name, $code = null, $obj = null, $deprecated = false ) { |
419
|
|
|
if ( !empty( $obj ) ) |
420
|
|
|
self::$obj =& $obj; |
421
|
|
|
else |
422
|
|
|
$obj =& self::$obj; |
423
|
|
|
|
424
|
|
|
self::$deprecated = $deprecated; |
425
|
|
|
|
426
|
|
|
if ( empty( $obj ) || !is_object( $obj ) ) |
427
|
|
|
return ''; |
428
|
|
|
|
429
|
|
|
$template = array( |
430
|
|
|
'id' => 0, |
431
|
|
|
'slug' => $template_name, |
432
|
|
|
'code' => $code, |
433
|
|
|
'options' => array(), |
434
|
|
|
); |
435
|
|
|
|
436
|
|
|
if ( empty( $code ) && !empty( $template_name ) ) { |
437
|
|
|
$template_obj = $obj->api->load_template( array( 'name' => $template_name ) ); |
438
|
|
|
|
439
|
|
|
if ( !empty( $template_obj ) ) { |
440
|
|
|
$template = $template_obj; |
441
|
|
|
|
442
|
|
|
if ( !empty( $template[ 'code' ] ) ) |
443
|
|
|
$code = $template[ 'code' ]; |
444
|
|
|
|
445
|
|
|
$permission = pods_permission( $template[ 'options' ] ); |
446
|
|
|
|
447
|
|
|
$permission = (boolean) apply_filters( 'pods_templates_permission', $permission, $code, $template, $obj ); |
448
|
|
|
|
449
|
|
|
if ( !$permission ) { |
450
|
|
|
return apply_filters( 'pods_templates_permission_denied', __( 'You do not have access to view this content.', 'pods' ), $code, $template, $obj ); |
451
|
|
|
} |
452
|
|
|
} |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
$code = apply_filters( 'pods_templates_pre_template', $code, $template, $obj ); |
456
|
|
|
$code = apply_filters( 'pods_templates_pre_template_' . $template[ 'slug' ], $code, $template, $obj ); |
457
|
|
|
|
458
|
|
|
ob_start(); |
459
|
|
|
|
460
|
|
|
if ( !empty( $code ) ) { |
461
|
|
|
// Only detail templates need $this->id |
462
|
|
|
if ( empty( $obj->id ) ) { |
463
|
|
|
while ( $obj->fetch() ) { |
464
|
|
|
echo self::do_template( $code, $obj ); |
465
|
|
|
} |
466
|
|
|
} |
467
|
|
|
else |
468
|
|
|
echo self::do_template( $code, $obj ); |
469
|
|
|
} |
470
|
|
|
elseif ( $template_name == trim( preg_replace( '/[^a-zA-Z0-9_\-\/]/', '', $template_name ), ' /-' ) ) { |
471
|
|
|
$default_templates = array( |
472
|
|
|
'pods/' . $template_name, |
473
|
|
|
'pods-' . $template_name, |
474
|
|
|
$template_name |
475
|
|
|
); |
476
|
|
|
|
477
|
|
|
$default_templates = apply_filters( 'pods_template_default_templates', $default_templates ); |
478
|
|
|
|
479
|
|
View Code Duplication |
if ( empty( $obj->id ) ) { |
480
|
|
|
while ( $obj->fetch() ) { |
481
|
|
|
pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) ); |
482
|
|
|
} |
483
|
|
|
} |
484
|
|
|
else |
485
|
|
|
pods_template_part( $default_templates, compact( array_keys( get_defined_vars() ) ) ); |
486
|
|
|
|
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
$out = ob_get_clean(); |
490
|
|
|
|
491
|
|
|
$out = apply_filters( 'pods_templates_post_template', $out, $code, $template, $obj ); |
492
|
|
|
$out = apply_filters( 'pods_templates_post_template_' . $template[ 'slug' ], $out, $code, $template, $obj ); |
493
|
|
|
|
494
|
|
|
return $out; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Parse a template string |
499
|
|
|
* |
500
|
|
|
* @param string $code The template string to parse |
501
|
|
|
* @param object $obj The Pods object |
502
|
|
|
* |
503
|
|
|
* @since 1.8.5 |
504
|
|
|
*/ |
505
|
|
|
public static function do_template ( $code, $obj = null ) { |
506
|
|
|
if ( !empty( $obj ) ) |
507
|
|
|
self::$obj =& $obj; |
508
|
|
|
else |
509
|
|
|
$obj =& self::$obj; |
510
|
|
|
|
511
|
|
|
if ( empty( $obj ) || !is_object( $obj ) ) |
512
|
|
|
return ''; |
513
|
|
|
|
514
|
|
|
$code = trim( $code ); |
515
|
|
|
|
516
|
|
|
if ( false !== strpos( $code, '<?' ) && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) ) { |
517
|
|
|
pods_deprecated( 'Pod Template PHP code has been deprecated, please use WP Templates instead of embedding PHP.', '2.3' ); |
518
|
|
|
|
519
|
|
|
$code = str_replace( '$this->', '$obj->', $code ); |
520
|
|
|
|
521
|
|
|
ob_start(); |
522
|
|
|
|
523
|
|
|
eval( "?>$code" ); |
|
|
|
|
524
|
|
|
|
525
|
|
|
$out = ob_get_clean(); |
526
|
|
|
} |
527
|
|
|
else |
528
|
|
|
$out = $code; |
529
|
|
|
|
530
|
|
|
$out = $obj->do_magic_tags( $out ); |
531
|
|
|
|
532
|
|
|
return apply_filters( 'pods_templates_do_template', $out, $code, $obj ); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
} |
536
|
|
|
|
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.