1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Name: Pages |
4
|
|
|
* |
5
|
|
|
* Description: Creates advanced URL structures using wildcards in order to enable the front-end display of Pods Advanced Content Types. Not recommended for use with other content types. |
6
|
|
|
* |
7
|
|
|
* Version: 2.3 |
8
|
|
|
* |
9
|
|
|
* Category: Advanced |
10
|
|
|
* |
11
|
|
|
* Menu Page: edit.php?post_type=_pods_page |
12
|
|
|
* Menu Add Page: post-new.php?post_type=_pods_page |
13
|
|
|
* |
14
|
|
|
* @package Pods\Components |
15
|
|
|
* @subpackage Pages |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
if ( class_exists( 'Pods_Pages' ) ) |
19
|
|
|
return; |
20
|
|
|
|
21
|
|
|
class Pods_Pages extends PodsComponent { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Current Pod Page |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
* |
28
|
|
|
* @since 2.0 |
29
|
|
|
*/ |
30
|
|
|
static $exists = null; |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Object type |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
* |
37
|
|
|
* @since 2.0 |
38
|
|
|
*/ |
39
|
|
|
private $object_type = '_pods_page'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Whether the page has been checked already |
43
|
|
|
* |
44
|
|
|
* @var bool |
45
|
|
|
* |
46
|
|
|
* @since 2.1 |
47
|
|
|
*/ |
48
|
|
|
static $checked = false; |
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Keep track of if pods_content has been called yet |
52
|
|
|
* |
53
|
|
|
* @var bool |
54
|
|
|
* |
55
|
|
|
* @since 2.3 |
56
|
|
|
*/ |
57
|
|
|
static $content_called = false; |
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The capability type. |
61
|
|
|
* @link https://codex.wordpress.org/Function_Reference/register_post_type |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
private $capability_type = 'pods_page'; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Do things like register/enqueue scripts and stylesheets |
68
|
|
|
* |
69
|
|
|
* @since 2.0 |
70
|
|
|
*/ |
71
|
|
|
public function __construct () { |
72
|
|
|
add_shortcode( 'pods-content', array( $this, 'shortcode' ) ); |
73
|
|
|
|
74
|
|
|
$args = array( |
75
|
|
|
'label' => 'Pod Pages', |
76
|
|
|
'labels' => array( 'singular_name' => 'Pod Page' ), |
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_page', $args ) ); |
95
|
|
|
|
96
|
|
|
add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 2 ); |
97
|
|
|
|
98
|
|
|
if ( !is_admin() ) |
99
|
|
|
add_action( 'load_textdomain', array( $this, 'page_check' ), 12 ); |
100
|
|
View Code Duplication |
else { |
101
|
|
|
add_filter( 'post_updated_messages', array( $this, 'setup_updated_messages' ), 10, 1 ); |
102
|
|
|
|
103
|
|
|
add_action( 'dbx_post_advanced', array( $this, 'edit_page_form' ), 10 ); |
104
|
|
|
|
105
|
|
|
add_action( 'pods_meta_groups', array( $this, 'add_meta_boxes' ) ); |
106
|
|
|
add_filter( 'get_post_metadata', array( $this, 'get_meta' ), 10, 4 ); |
107
|
|
|
add_filter( 'update_post_metadata', array( $this, 'save_meta' ), 10, 4 ); |
108
|
|
|
|
109
|
|
|
add_action( 'pods_meta_save_pre_post__pods_page', array( $this, 'fix_filters' ), 10, 5 ); |
110
|
|
|
add_action( 'post_updated', array( $this, 'clear_cache' ), 10, 3 ); |
111
|
|
|
add_action( 'delete_post', array( $this, 'clear_cache' ), 10, 1 ); |
112
|
|
|
add_filter( 'post_row_actions', array( $this, 'remove_row_actions' ), 10, 2 ); |
113
|
|
|
add_filter( 'bulk_actions-edit-' . $this->object_type, array( $this, 'remove_bulk_actions' ) ); |
114
|
|
|
|
115
|
|
|
add_filter( 'builder_layout_filter_non_layout_post_types', array( $this, 'disable_builder_layout' ) ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
add_filter( 'members_get_capabilities', array( $this, 'get_capabilities' ) ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
View Code Duplication |
public function get_capabilities( $caps ) { |
|
|
|
|
122
|
|
|
$caps = array_merge( $caps, array( |
123
|
|
|
'edit_' . $this->capability_type, |
124
|
|
|
'read_' . $this->capability_type, |
125
|
|
|
'delete_' . $this->capability_type, |
126
|
|
|
'edit_' . $this->capability_type . 's', |
127
|
|
|
'edit_others_' . $this->capability_type . 's', |
128
|
|
|
'publish_' . $this->capability_type . 's', |
129
|
|
|
'read_private_' . $this->capability_type . 's', |
130
|
|
|
'edit_' . $this->capability_type . 's', |
131
|
|
|
) ); |
132
|
|
|
return $caps; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Pod Page Content Shortcode support for use anywhere that supports WP Shortcodes |
137
|
|
|
* |
138
|
|
|
* @param array $tags An associative array of shortcode properties |
139
|
|
|
* @param string $content Not currently used |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
* @since 2.3.9 |
143
|
|
|
*/ |
144
|
|
|
public function shortcode ( $tags, $content = null ) { |
145
|
|
View Code Duplication |
if ( !isset( $tags[ 'page' ] ) || empty( $tags[ 'page' ] ) ) |
146
|
|
|
$tags[ 'page' ] = null; |
147
|
|
|
|
148
|
|
|
$pods_page = Pods_Pages::exists( $tags[ 'page' ] ); |
149
|
|
|
|
150
|
|
|
if ( empty( $pods_page ) ) |
151
|
|
|
return '<p>Pods Page not found</p>'; |
152
|
|
|
|
153
|
|
|
return Pods_Pages::content( true, $pods_page ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Disable this Post Type from appearing in the Builder layouts list |
158
|
|
|
* |
159
|
|
|
* @param array $post_types |
160
|
|
|
* @return array |
161
|
|
|
*/ |
162
|
|
|
public function disable_builder_layout ( $post_types ) { |
163
|
|
|
$post_types[] = $this->object_type; |
164
|
|
|
|
165
|
|
|
return $post_types; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Update Post Type messages |
170
|
|
|
* |
171
|
|
|
* @param array $messages |
172
|
|
|
* |
173
|
|
|
* @return array |
174
|
|
|
* @since 2.0.2 |
175
|
|
|
*/ |
176
|
|
View Code Duplication |
public function setup_updated_messages ( $messages ) { |
|
|
|
|
177
|
|
|
global $post, $post_ID; |
|
|
|
|
178
|
|
|
|
179
|
|
|
$post_type = get_post_type_object( $this->object_type ); |
180
|
|
|
|
181
|
|
|
$labels = $post_type->labels; |
182
|
|
|
|
183
|
|
|
$messages[ $post_type->name ] = array( |
184
|
|
|
1 => sprintf( __( '%s updated. <a href="%s">%s</a>', 'pods' ), $labels->singular_name, esc_url( get_permalink( $post_ID ) ), $labels->view_item ), |
185
|
|
|
2 => __( 'Custom field updated.', 'pods' ), |
186
|
|
|
3 => __( 'Custom field deleted.', 'pods' ), |
187
|
|
|
4 => sprintf( __( '%s updated.', 'pods' ), $labels->singular_name ), |
188
|
|
|
/* translators: %s: date and time of the revision */ |
189
|
|
|
5 => isset( $_GET[ 'revision' ] ) ? sprintf( __( '%s restored to revision from %s', 'pods' ), $labels->singular_name, wp_post_revision_title( (int) $_GET[ 'revision' ], false ) ) : false, |
190
|
|
|
6 => sprintf( __( '%s published. <a href="%s">%s</a>', 'pods' ), $labels->singular_name, esc_url( get_permalink( $post_ID ) ), $labels->view_item ), |
191
|
|
|
7 => sprintf( __( '%s saved.', 'pods' ), $labels->singular_name ), |
192
|
|
|
8 => sprintf( __( '%s submitted. <a target="_blank" href="%s">Preview %s</a>', 'pods' ), |
193
|
|
|
$labels->singular_name, |
194
|
|
|
esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ), |
195
|
|
|
$labels->singular_name |
196
|
|
|
), |
197
|
|
|
9 => sprintf( __( '%s scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview %s</a>', 'pods' ), |
198
|
|
|
$labels->singular_name, |
199
|
|
|
// translators: Publish box date format, see http://php.net/date |
200
|
|
|
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), |
201
|
|
|
esc_url( get_permalink( $post_ID ) ), |
202
|
|
|
$labels->singular_name |
203
|
|
|
), |
204
|
|
|
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 ) |
205
|
|
|
); |
206
|
|
|
|
207
|
|
|
if ( false === (boolean) $post_type->public ) { |
208
|
|
|
$messages[ $post_type->name ][ 1 ] = sprintf( __( '%s updated.', 'pods' ), $labels->singular_name ); |
209
|
|
|
$messages[ $post_type->name ][ 6 ] = sprintf( __( '%s published.', 'pods' ), $labels->singular_name ); |
210
|
|
|
$messages[ $post_type->name ][ 8 ] = sprintf( __( '%s submitted.', 'pods' ), $labels->singular_name ); |
211
|
|
|
$messages[ $post_type->name ][ 9 ] = sprintf( __( '%s scheduled for: <strong>%1$s</strong>.', 'pods' ), |
212
|
|
|
$labels->singular_name, |
213
|
|
|
// translators: Publish box date format, see http://php.net/date |
214
|
|
|
date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) |
215
|
|
|
); |
216
|
|
|
$messages[ $post_type->name ][ 10 ] = sprintf( __( '%s draft updated.', 'pods' ), $labels->singular_name ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
return $messages; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Enqueue styles |
224
|
|
|
* |
225
|
|
|
* @since 2.0 |
226
|
|
|
*/ |
227
|
|
|
public function admin_assets () { |
228
|
|
|
wp_enqueue_style( 'pods-admin' ); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Fix filters, specifically removing balanceTags |
233
|
|
|
* |
234
|
|
|
* @since 2.0.1 |
235
|
|
|
*/ |
236
|
|
|
public function fix_filters ( $data, $pod = null, $id = null, $groups = null, $post = null ) { |
237
|
|
|
remove_filter( 'content_save_pre', 'balanceTags', 50 ); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Remove unused row actions |
242
|
|
|
* |
243
|
|
|
* @since 2.0.5 |
244
|
|
|
*/ |
245
|
|
View Code Duplication |
public function remove_row_actions ( $actions, $post ) { |
|
|
|
|
246
|
|
|
global $current_screen; |
|
|
|
|
247
|
|
|
|
248
|
|
|
if ( !is_object( $current_screen ) || $this->object_type != $current_screen->post_type ) |
249
|
|
|
return $actions; |
250
|
|
|
|
251
|
|
|
if ( isset( $actions[ 'view' ] ) ) |
252
|
|
|
unset( $actions[ 'view' ] ); |
253
|
|
|
|
254
|
|
|
if ( isset( $actions[ 'inline hide-if-no-js' ] ) ) |
255
|
|
|
unset( $actions[ 'inline hide-if-no-js' ] ); |
256
|
|
|
|
257
|
|
|
// W3 Total Cache |
258
|
|
|
if ( isset( $actions[ 'pgcache_purge' ] ) ) |
259
|
|
|
unset( $actions[ 'pgcache_purge' ] ); |
260
|
|
|
|
261
|
|
|
return $actions; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Remove unused bulk actions |
266
|
|
|
* |
267
|
|
|
* @since 2.0.5 |
268
|
|
|
*/ |
269
|
|
|
public function remove_bulk_actions ( $actions ) { |
270
|
|
|
if ( isset( $actions[ 'edit' ] ) ) |
271
|
|
|
unset( $actions[ 'edit' ] ); |
272
|
|
|
|
273
|
|
|
return $actions; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Clear cache on save |
278
|
|
|
* |
279
|
|
|
* @since 2.0 |
280
|
|
|
*/ |
281
|
|
|
public function clear_cache ( $data, $pod = null, $id = null, $groups = null, $post = null ) { |
282
|
|
|
$old_post = $id; |
283
|
|
|
|
284
|
|
|
if ( !is_object( $id ) ) |
285
|
|
|
$old_post = null; |
286
|
|
|
|
287
|
|
|
if ( is_object( $post ) && $this->object_type != $post->post_type ) |
288
|
|
|
return; |
289
|
|
|
|
290
|
|
|
if ( !is_array( $data ) && 0 < $data ) { |
291
|
|
|
$post = $data; |
292
|
|
|
$post = get_post( $post ); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
if ( $this->object_type == $post->post_type ) { |
296
|
|
|
pods_transient_clear( 'pods_object_pages' ); |
297
|
|
|
|
298
|
|
|
if ( is_object( $old_post ) && $this->object_type == $old_post->post_type ) |
299
|
|
|
pods_cache_clear( $old_post->post_title, 'pods_object_page_wildcard' ); |
300
|
|
|
|
301
|
|
|
pods_cache_clear( $post->post_title, 'pods_object_page_wildcard' ); |
302
|
|
|
|
303
|
|
|
self::flush_rewrites(); |
304
|
|
|
} |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Change post title placeholder text |
309
|
|
|
* |
310
|
|
|
* @since 2.0 |
311
|
|
|
*/ |
312
|
|
|
public function set_title_text ( $text, $post ) { |
313
|
|
|
return __( 'Enter URL here', 'pods' ); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Edit page form |
318
|
|
|
* |
319
|
|
|
* @since 2.0 |
320
|
|
|
*/ |
321
|
|
View Code Duplication |
public function edit_page_form () { |
|
|
|
|
322
|
|
|
global $post_type; |
|
|
|
|
323
|
|
|
|
324
|
|
|
if ( $this->object_type != $post_type ) |
325
|
|
|
return; |
326
|
|
|
|
327
|
|
|
add_filter( 'enter_title_here', array( $this, 'set_title_text' ), 10, 2 ); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Filter permalinks and adjust for pod pages |
332
|
|
|
* |
333
|
|
|
* @param $post_link |
334
|
|
|
* @param $post |
335
|
|
|
* |
336
|
|
|
* @return mixed |
337
|
|
|
*/ |
338
|
|
|
public function post_type_link ( $post_link, $post ) { |
339
|
|
|
if ( empty( $post ) || $this->object_type != $post->post_type ) |
340
|
|
|
return $post_link; |
341
|
|
|
|
342
|
|
|
$post_link = get_site_url() . '/'; |
343
|
|
|
|
344
|
|
|
if ( false === strpos( $post->post_title, '*' ) ) |
345
|
|
|
$post_link .= trim( $post->post_title, '/ ' ) . '/'; |
346
|
|
|
|
347
|
|
|
return $post_link; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Add meta boxes to the page |
352
|
|
|
* |
353
|
|
|
* @since 2.0 |
354
|
|
|
*/ |
355
|
|
|
public function add_meta_boxes () { |
356
|
|
|
$pod = array( |
357
|
|
|
'name' => $this->object_type, |
358
|
|
|
'type' => 'post_type' |
359
|
|
|
); |
360
|
|
|
|
361
|
|
|
if ( isset( PodsMeta::$post_types[ $pod[ 'name' ] ] ) ) |
362
|
|
|
return; |
363
|
|
|
|
364
|
|
|
if ( !function_exists( 'get_page_templates' ) ) |
365
|
|
|
include_once ABSPATH . 'wp-admin/includes/theme.php'; |
366
|
|
|
|
367
|
|
|
$page_templates = apply_filters( 'pods_page_templates', get_page_templates() ); |
368
|
|
|
|
369
|
|
|
$page_templates[ __( '-- Page Template --', 'pods' ) ] = ''; |
370
|
|
|
|
371
|
|
|
$page_templates[ __( 'Custom (uses only Pod Page content)', 'pods' ) ] = '_custom'; |
372
|
|
|
|
373
|
|
View Code Duplication |
if ( !in_array( 'pods.php', $page_templates ) && locate_template( array( 'pods.php', false ) ) ) |
374
|
|
|
$page_templates[ __( 'Pods (Pods Default)', 'pods' ) ] = 'pods.php'; |
375
|
|
|
|
376
|
|
View Code Duplication |
if ( !in_array( 'page.php', $page_templates ) && locate_template( array( 'page.php', false ) ) ) |
377
|
|
|
$page_templates[ __( 'Page (WP Default)', 'pods' ) ] = 'page.php'; |
378
|
|
|
|
379
|
|
View Code Duplication |
if ( !in_array( 'index.php', $page_templates ) && locate_template( array( 'index.php', false ) ) ) |
380
|
|
|
$page_templates[ __( 'Index (WP Fallback)', 'pods' ) ] = 'index.php'; |
381
|
|
|
|
382
|
|
|
ksort( $page_templates ); |
383
|
|
|
|
384
|
|
|
$page_templates = array_flip( $page_templates ); |
385
|
|
|
|
386
|
|
|
$fields = array( |
387
|
|
|
array( |
388
|
|
|
'name' => 'page_title', |
389
|
|
|
'label' => __( 'Page Title', 'pods' ), |
390
|
|
|
'type' => 'text' |
391
|
|
|
), |
392
|
|
|
array( |
393
|
|
|
'name' => 'code', |
394
|
|
|
'label' => __( 'Page Code', 'pods' ), |
395
|
|
|
'type' => 'code', |
396
|
|
|
'attributes' => array( |
397
|
|
|
'id' => 'content' |
398
|
|
|
), |
399
|
|
|
'label_options' => array( |
400
|
|
|
'attributes' => array( |
401
|
|
|
'for' => 'content' |
402
|
|
|
) |
403
|
|
|
) |
404
|
|
|
), |
405
|
|
|
array( |
406
|
|
|
'name' => 'precode', |
407
|
|
|
'label' => __( 'Page Precode', 'pods' ), |
408
|
|
|
'type' => 'code', |
409
|
|
|
'help' => __( 'Precode will run before your theme outputs the page. It is expected that this value will be a block of PHP. You must open the PHP tag here, as we do not open it for you by default.', 'pods' ) |
410
|
|
|
), |
411
|
|
|
array( |
412
|
|
|
'name' => 'page_template', |
413
|
|
|
'label' => __( 'Page Template', 'pods' ), |
414
|
|
|
'type' => 'pick', |
415
|
|
|
'data' => $page_templates |
416
|
|
|
) |
417
|
|
|
); |
418
|
|
|
|
419
|
|
|
pods_group_add( $pod, __( 'Page', 'pods' ), $fields, 'normal', 'high' ); |
420
|
|
|
|
421
|
|
|
$associated_pods = array( |
422
|
|
|
0 => __( '-- Select a Pod --', 'pods' ) |
423
|
|
|
); |
424
|
|
|
|
425
|
|
|
$all_pods = pods_api()->load_pods( array( 'names' => true ) ); |
426
|
|
|
|
427
|
|
|
if ( !empty( $all_pods ) ) { |
428
|
|
|
foreach ( $all_pods as $pod_name => $pod_label ) { |
|
|
|
|
429
|
|
|
$associated_pods[ $pod_name ] = $pod_label . ' (' . $pod_name . ')'; |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
else |
433
|
|
|
$associated_pods[ 0 ] = __( 'None Found', 'pods' ); |
434
|
|
|
|
435
|
|
|
$fields = array( |
436
|
|
|
array( |
437
|
|
|
'name' => 'pod', |
438
|
|
|
'label' => __( 'Associated Pod', 'pods' ), |
439
|
|
|
'default' => 0, |
440
|
|
|
'type' => 'pick', |
441
|
|
|
'data' => $associated_pods, |
442
|
|
|
'dependency' => true |
443
|
|
|
), |
444
|
|
|
array( |
445
|
|
|
'name' => 'pod_slug', |
446
|
|
|
'label' => __( 'Wildcard Slug', 'pods' ), |
447
|
|
|
'help' => __( 'Setting the Wildcard Slug is an easy way to setup a detail page. You can use the special tag {@url.2} to match the *third* level of the URL of a Pod Page named "first/second/*" part of the pod page. This is functionally the same as using pods_v_sanitized( 2, "url" ) in PHP.', 'pods' ), |
448
|
|
|
'type' => 'text', |
449
|
|
|
'excludes-on' => array( 'pod' => 0 ) |
450
|
|
|
) |
451
|
|
|
); |
452
|
|
|
|
453
|
|
|
pods_group_add( $pod, __( 'Pod Association', 'pods' ), $fields, 'normal', 'high' ); |
454
|
|
|
|
455
|
|
|
$fields = array( |
456
|
|
|
array( |
457
|
|
|
'name' => 'admin_only', |
458
|
|
|
'label' => __( 'Restrict access to Admins?', 'pods' ), |
459
|
|
|
'default' => 0, |
460
|
|
|
'type' => 'boolean', |
461
|
|
|
'dependency' => true |
462
|
|
|
), |
463
|
|
|
array( |
464
|
|
|
'name' => 'restrict_role', |
465
|
|
|
'label' => __( 'Restrict access by Role?', 'pods' ), |
466
|
|
|
'help' => array( |
467
|
|
|
__( '<h6>Roles</h6> Roles are assigned to users to provide them access to specific functionality in WordPress. Please see the Roles and Capabilities component in Pods for an easy tool to add your own roles and edit existing ones.', 'pods' ), |
468
|
|
|
'http://codex.wordpress.org/Roles_and_Capabilities' |
469
|
|
|
), |
470
|
|
|
'default' => 0, |
471
|
|
|
'type' => 'boolean', |
472
|
|
|
'dependency' => true |
473
|
|
|
), |
474
|
|
|
array( |
475
|
|
|
'name' => 'roles_allowed', |
476
|
|
|
'label' => __( 'Role(s) Allowed', 'pods' ), |
477
|
|
|
'type' => 'pick', |
478
|
|
|
'pick_object' => 'role', |
479
|
|
|
'pick_format_type' => 'multi', |
480
|
|
|
'pick_format_multi' => 'autocomplete', |
481
|
|
|
'pick_ajax' => false, |
482
|
|
|
'default' => '', |
483
|
|
|
'depends-on' => array( |
484
|
|
|
'restrict_role' => true |
485
|
|
|
) |
486
|
|
|
), |
487
|
|
|
array( |
488
|
|
|
'name' => 'restrict_capability', |
489
|
|
|
'label' => __( 'Restrict access by Capability?', 'pods' ), |
490
|
|
|
'help' => array( |
491
|
|
|
__( '<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' ), |
492
|
|
|
'http://codex.wordpress.org/Roles_and_Capabilities' |
493
|
|
|
), |
494
|
|
|
'default' => 0, |
495
|
|
|
'type' => 'boolean', |
496
|
|
|
'dependency' => true |
497
|
|
|
), |
498
|
|
|
array( |
499
|
|
|
'name' => 'capability_allowed', |
500
|
|
|
'label' => __( 'Capability Allowed', 'pods' ), |
501
|
|
|
'type' => 'pick', |
502
|
|
|
'pick_object' => 'capability', |
503
|
|
|
'pick_format_type' => 'multi', |
504
|
|
|
'pick_format_multi' => 'autocomplete', |
505
|
|
|
'pick_ajax' => false, |
506
|
|
|
'default' => '', |
507
|
|
|
'depends-on' => array( |
508
|
|
|
'restrict_capability' => true |
509
|
|
|
) |
510
|
|
|
), |
511
|
|
|
array( |
512
|
|
|
'name' => 'restrict_redirect', |
513
|
|
|
'label' => __( 'Redirect if Restricted?', 'pods' ), |
514
|
|
|
'default' => 0, |
515
|
|
|
'type' => 'boolean', |
516
|
|
|
'dependency' => true |
517
|
|
|
), |
518
|
|
|
array( |
519
|
|
|
'name' => 'restrict_redirect_login', |
520
|
|
|
'label' => __( 'Redirect to WP Login page', 'pods' ), |
521
|
|
|
'default' => 0, |
522
|
|
|
'type' => 'boolean', |
523
|
|
|
'dependency' => true, |
524
|
|
|
'depends-on' => array( |
525
|
|
|
'restrict_redirect' => true |
526
|
|
|
) |
527
|
|
|
), |
528
|
|
|
array( |
529
|
|
|
'name' => 'restrict_redirect_url', |
530
|
|
|
'label' => __( 'Redirect to a Custom URL', 'pods' ), |
531
|
|
|
'default' => '', |
532
|
|
|
'type' => 'text', |
533
|
|
|
'depends-on' => array( |
534
|
|
|
'restrict_redirect' => true, |
535
|
|
|
'restrict_redirect_login' => false |
536
|
|
|
) |
537
|
|
|
), |
538
|
|
|
); |
539
|
|
|
|
540
|
|
|
pods_group_add( $pod, __( 'Restrict Access', 'pods' ), $fields, 'normal', 'high' ); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* Get the fields |
545
|
|
|
* |
546
|
|
|
* @param null $_null |
547
|
|
|
* @param int $post_ID |
548
|
|
|
* @param string $meta_key |
549
|
|
|
* @param bool $single |
550
|
|
|
* |
551
|
|
|
* @return array|bool|int|mixed|null|string|void |
552
|
|
|
*/ |
553
|
|
View Code Duplication |
public function get_meta ( $_null, $post_ID = null, $meta_key = null, $single = false ) { |
|
|
|
|
554
|
|
|
if ( 'code' == $meta_key ) { |
555
|
|
|
$post = get_post( $post_ID ); |
556
|
|
|
|
557
|
|
|
if ( is_object( $post ) && $this->object_type == $post->post_type ) |
558
|
|
|
return $post->post_content; |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
return $_null; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* Save the fields |
566
|
|
|
* |
567
|
|
|
* @param $_null |
568
|
|
|
* @param int $post_ID |
569
|
|
|
* @param string $meta_key |
570
|
|
|
* @param null $meta_value |
571
|
|
|
* |
572
|
|
|
* @return bool|int|null |
573
|
|
|
*/ |
574
|
|
View Code Duplication |
public function save_meta ( $_null, $post_ID = null, $meta_key = null, $meta_value = null ) { |
|
|
|
|
575
|
|
|
if ( 'code' == $meta_key ) { |
576
|
|
|
$post = get_post( $post_ID ); |
577
|
|
|
|
578
|
|
|
if ( is_object( $post ) && $this->object_type == $post->post_type ) { |
579
|
|
|
$postdata = array( |
580
|
|
|
'ID' => $post_ID, |
581
|
|
|
'post_content' => $meta_value |
582
|
|
|
); |
583
|
|
|
|
584
|
|
|
remove_filter( current_filter(), array( $this, __FUNCTION__ ), 10 ); |
585
|
|
|
|
586
|
|
|
$revisions = false; |
587
|
|
|
|
588
|
|
|
if ( has_action( 'pre_post_update', 'wp_save_post_revision' ) ) { |
589
|
|
|
remove_action( 'pre_post_update', 'wp_save_post_revision' ); |
590
|
|
|
|
591
|
|
|
$revisions = true; |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
wp_update_post( (object) $postdata ); // objects will be automatically sanitized |
595
|
|
|
|
596
|
|
|
if ( $revisions ) |
597
|
|
|
add_action( 'pre_post_update', 'wp_save_post_revision' ); |
598
|
|
|
|
599
|
|
|
return true; |
600
|
|
|
} |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
return $_null; |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* Flush Pod Page Rewrite cache |
608
|
|
|
* |
609
|
|
|
* @return array Pod Page Rewrites |
610
|
|
|
* |
611
|
|
|
* @since 2.3.4 |
612
|
|
|
*/ |
613
|
|
|
public static function flush_rewrites () { |
614
|
|
|
$args = array( |
615
|
|
|
'post_type' => '_pods_page', |
616
|
|
|
'nopaging' => true, |
617
|
|
|
'posts_per_page' => -1, |
618
|
|
|
'post_status' => 'publish', |
619
|
|
|
'order' => 'ASC', |
620
|
|
|
'orderby' => 'title' |
621
|
|
|
); |
622
|
|
|
|
623
|
|
|
$pod_pages = get_posts( $args ); |
624
|
|
|
|
625
|
|
|
$pod_page_rewrites = array(); |
626
|
|
|
|
627
|
|
|
foreach ( $pod_pages as $pod_page ) { |
628
|
|
|
$pod_page_rewrites[ $pod_page->ID ] = $pod_page->post_title; |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
uksort( $pod_page_rewrites, 'pods_page_length_sort' ); |
632
|
|
|
|
633
|
|
|
pods_transient_set( 'pods_object_page_rewrites', $pod_page_rewrites ); |
634
|
|
|
|
635
|
|
|
$pod_page_rewrites = array_flip( $pod_page_rewrites ); |
636
|
|
|
|
637
|
|
|
return $pod_page_rewrites; |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* Check to see if Pod Page exists and return data |
642
|
|
|
* |
643
|
|
|
* $uri not required, if NULL then returns REQUEST_URI matching Pod Page |
644
|
|
|
* |
645
|
|
|
* @param string $uri The Pod Page URI to check if exists |
646
|
|
|
* |
647
|
|
|
* @return array|bool |
648
|
|
|
*/ |
649
|
|
|
public static function exists ( $uri = null ) { |
650
|
|
|
if ( null === $uri ) { |
651
|
|
|
$uri = parse_url( pods_current_url() ); |
652
|
|
|
$uri = $uri[ 'path' ]; |
653
|
|
|
} |
654
|
|
|
else { |
655
|
|
|
$uri = explode( '?', $uri ); |
656
|
|
|
$uri = explode( '#', $uri[ 0 ] ); |
657
|
|
|
$uri = $uri[ 0 ]; |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
$home = parse_url( get_home_url() ); |
661
|
|
|
|
662
|
|
|
if ( !empty( $home ) && isset( $home[ 'path' ] ) && '/' != $home[ 'path' ] ) |
663
|
|
|
$uri = substr( $uri, strlen( $home[ 'path' ] ) ); |
664
|
|
|
|
665
|
|
|
$uri = trim( $uri, '/' ); |
666
|
|
|
$uri_depth = count( array_filter( explode( '/', $uri ) ) ) - 1; |
667
|
|
|
|
668
|
|
|
$pods_page_exclusions = array( |
669
|
|
|
'wp-admin', |
670
|
|
|
'wp-content', |
671
|
|
|
'wp-includes', |
672
|
|
|
'index.php', |
673
|
|
|
'wp-login.php', |
674
|
|
|
'wp-signup.php' |
675
|
|
|
); |
676
|
|
|
|
677
|
|
|
$pods_page_exclusions = apply_filters( 'pods_page_exclusions', $pods_page_exclusions ); |
678
|
|
|
|
679
|
|
|
if ( is_admin() || empty( $uri ) ) |
680
|
|
|
return false; |
681
|
|
|
|
682
|
|
|
foreach ( $pods_page_exclusions as $exclusion ) { |
683
|
|
|
if ( 0 === strpos( $uri, $exclusion ) ) |
684
|
|
|
return false; |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
$object = apply_filters( 'pods_page_exists', false, $uri ); |
688
|
|
|
if ( !empty ( $object ) ) { |
689
|
|
|
return $object; |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
if ( false === strpos( $uri, '*' ) && ! apply_filters( 'pods_page_regex_matching', false ) ) { |
693
|
|
|
$object = pods_by_title( $uri, ARRAY_A, '_pods_page', 'publish' ); |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
$wildcard = false; |
697
|
|
|
|
698
|
|
|
if ( empty( $object ) ) { |
699
|
|
|
if ( false === strpos( $uri, '*' ) ) { |
700
|
|
|
$object = pods_cache_get( $uri, 'pods_object_page_wildcard' ); |
701
|
|
|
|
702
|
|
|
if ( !empty( $object ) ) |
703
|
|
|
return $object; |
704
|
|
|
} |
705
|
|
|
|
706
|
|
|
$pod_page_rewrites = pods_transient_get( 'pods_object_page_rewrites' ); |
707
|
|
|
|
708
|
|
|
if ( empty( $pod_page_rewrites ) ) |
709
|
|
|
$pod_page_rewrites = self::flush_rewrites(); |
710
|
|
|
else |
711
|
|
|
$pod_page_rewrites = array_flip( $pod_page_rewrites ); |
712
|
|
|
|
713
|
|
|
$found_rewrite_page_id = 0; |
714
|
|
|
|
715
|
|
|
if ( !empty( $pod_page_rewrites ) ) { |
716
|
|
|
foreach ( $pod_page_rewrites as $pod_page => $pod_page_id ) { |
717
|
|
|
if ( !apply_filters( 'pods_page_regex_matching', false ) ) { |
718
|
|
|
if ( false === strpos( $pod_page, '*' ) ) |
719
|
|
|
continue; |
720
|
|
|
|
721
|
|
|
$depth_check = strlen( $pod_page ) - strlen( str_replace( '/', '', $pod_page ) ); |
722
|
|
|
|
723
|
|
|
$pod_page = preg_quote( $pod_page, '/' ); |
724
|
|
|
|
725
|
|
|
$pod_page = str_replace( '\\*', '(.*)', $pod_page ); |
726
|
|
|
|
727
|
|
|
if ( $uri_depth == $depth_check && preg_match( '/^' . $pod_page . '$/', $uri ) ) { |
728
|
|
|
$found_rewrite_page_id = $pod_page_id; |
729
|
|
|
|
730
|
|
|
break; |
731
|
|
|
} |
732
|
|
|
} |
733
|
|
|
elseif ( preg_match( '/^' . str_replace( '/', '\\/', $pod_page ) . '$/', $uri ) ) { |
734
|
|
|
$found_rewrite_page_id = $pod_page_id; |
735
|
|
|
|
736
|
|
|
break; |
737
|
|
|
} |
738
|
|
|
} |
739
|
|
|
|
740
|
|
|
if ( !empty( $found_rewrite_page_id ) ) { |
741
|
|
|
$object = get_post( $found_rewrite_page_id, ARRAY_A ); |
742
|
|
|
|
743
|
|
|
if ( empty( $object ) || '_pods_page' != $object[ 'post_type' ] ) |
744
|
|
|
$object = false; |
745
|
|
|
} |
746
|
|
|
} |
747
|
|
|
|
748
|
|
|
$wildcard = true; |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
if ( !empty( $object ) ) { |
752
|
|
|
$object = array( |
753
|
|
|
'id' => $object[ 'ID' ], |
754
|
|
|
'uri' => $object[ 'post_title' ], |
755
|
|
|
'code' => $object[ 'post_content' ], |
756
|
|
|
'phpcode' => $object[ 'post_content' ], // phpcode is deprecated |
757
|
|
|
'precode' => get_post_meta( $object[ 'ID' ], 'precode', true ), |
758
|
|
|
'page_template' => get_post_meta( $object[ 'ID' ], 'page_template', true ), |
759
|
|
|
'title' => get_post_meta( $object[ 'ID' ], 'page_title', true ), |
760
|
|
|
'options' => array( |
761
|
|
|
'admin_only' => (boolean) get_post_meta( $object[ 'ID' ], 'admin_only', true ), |
762
|
|
|
'restrict_role' => (boolean) get_post_meta( $object[ 'ID' ], 'restrict_role', true ), |
763
|
|
|
'restrict_capability' => (boolean) get_post_meta( $object[ 'ID' ], 'restrict_capability', true ), |
764
|
|
|
'roles_allowed' => get_post_meta( $object[ 'ID' ], 'roles_allowed', true ), |
765
|
|
|
'capability_allowed' => get_post_meta( $object[ 'ID' ], 'capability_allowed', true ), |
766
|
|
|
'restrict_redirect' => (boolean) get_post_meta( $object[ 'ID' ], 'restrict_redirect', true ), |
767
|
|
|
'restrict_redirect_login' => (boolean) get_post_meta( $object[ 'ID' ], 'restrict_redirect_login', true ), |
768
|
|
|
'restrict_redirect_url' => get_post_meta( $object[ 'ID' ], 'restrict_redirect_url', true ), |
769
|
|
|
'pod' => get_post_meta( $object[ 'ID' ], 'pod', true ), |
770
|
|
|
'pod_slug' => get_post_meta( $object[ 'ID' ], 'pod_slug', true ), |
771
|
|
|
) |
772
|
|
|
); |
773
|
|
|
|
774
|
|
|
if ( $wildcard ) |
775
|
|
|
pods_cache_set( $uri, $object, 'pods_object_page_wildcard', 3600 ); |
776
|
|
|
|
777
|
|
|
return $object; |
778
|
|
|
} |
779
|
|
|
|
780
|
|
|
return false; |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
/** |
784
|
|
|
* Check if a Pod Page exists |
785
|
|
|
*/ |
786
|
|
|
public function page_check () { |
787
|
|
|
if ( self::$checked ) |
788
|
|
|
return; |
789
|
|
|
|
790
|
|
|
global $pods; |
|
|
|
|
791
|
|
|
|
792
|
|
|
// Fix any global confusion wherever this runs |
793
|
|
View Code Duplication |
if ( isset( $pods ) && !isset( $GLOBALS[ 'pods' ] ) ) |
794
|
|
|
$GLOBALS[ 'pods' ] =& $pods; |
795
|
|
|
elseif ( !isset( $pods ) && isset( $GLOBALS[ 'pods' ] ) ) |
796
|
|
|
$pods =& $GLOBALS[ 'pods' ]; |
797
|
|
|
|
798
|
|
|
if ( !defined( 'PODS_DISABLE_POD_PAGE_CHECK' ) || !PODS_DISABLE_POD_PAGE_CHECK ) { |
799
|
|
|
if ( null === self::$exists ) |
800
|
|
|
self::$exists = pod_page_exists(); |
801
|
|
|
|
802
|
|
|
if ( false !== self::$exists ) { |
803
|
|
|
$pods = apply_filters( 'pods_global', $pods, self::$exists ); |
804
|
|
|
|
805
|
|
|
if ( !is_wp_error( $pods ) && ( is_object( $pods ) || 404 != $pods ) ) { |
806
|
|
|
add_action( 'template_redirect', array( $this, 'template_redirect' ) ); |
807
|
|
|
add_filter( 'redirect_canonical', '__return_false' ); |
808
|
|
|
add_action( 'wp_head', array( $this, 'wp_head' ) ); |
809
|
|
|
add_filter( 'wp_title', array( $this, 'wp_title' ), 0, 3 ); |
810
|
|
|
add_filter( 'body_class', array( $this, 'body_class' ), 0, 1 ); |
811
|
|
|
add_filter( 'status_header', array( $this, 'status_header' ) ); |
812
|
|
|
add_action( 'after_setup_theme', array( $this, 'precode' ) ); |
813
|
|
|
add_action( 'wp', array( $this, 'silence_404' ), 1 ); |
814
|
|
|
|
815
|
|
|
// Genesis theme integration |
816
|
|
|
add_action( 'genesis_loop', 'pods_content', 11 ); |
817
|
|
|
} |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
self::$checked = true; |
821
|
|
|
} |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
/** |
825
|
|
|
* Output Pod Page Content |
826
|
|
|
* |
827
|
|
|
* @param bool $return Whether to return or not (default is to echo) |
828
|
|
|
* |
829
|
|
|
* @return string |
830
|
|
|
*/ |
831
|
|
|
public static function content ( $return = false, $pods_page = false ) { |
832
|
|
|
if ( empty( $pods_page ) ) |
833
|
|
|
$pods_page = self::$exists; |
834
|
|
|
|
835
|
|
|
$content = false; |
836
|
|
|
|
837
|
|
|
if ( $pods_page == self::$exists && self::$content_called ) |
838
|
|
|
return $content; |
839
|
|
|
|
840
|
|
|
if ( !empty( $pods_page ) ) { |
841
|
|
|
/** |
842
|
|
|
* @var $pods \Pods |
843
|
|
|
*/ |
844
|
|
|
global $pods; |
|
|
|
|
845
|
|
|
|
846
|
|
|
// Fix any global confusion wherever this runs |
847
|
|
View Code Duplication |
if ( isset( $pods ) && !isset( $GLOBALS[ 'pods' ] ) ) |
848
|
|
|
$GLOBALS[ 'pods' ] =& $pods; |
849
|
|
|
elseif ( !isset( $pods ) && isset( $GLOBALS[ 'pods' ] ) ) |
850
|
|
|
$pods =& $GLOBALS[ 'pods' ]; |
851
|
|
|
|
852
|
|
|
if ( 0 < strlen( trim( $pods_page[ 'code' ] ) ) ) |
853
|
|
|
$content = trim( $pods_page[ 'code' ] ); |
854
|
|
|
|
855
|
|
|
ob_start(); |
856
|
|
|
|
857
|
|
|
do_action( 'pods_content_pre', $pods_page, $content ); |
858
|
|
|
|
859
|
|
|
if ( 0 < strlen( $content ) ) { |
860
|
|
|
if ( false !== strpos( $content, '<?' ) && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) ) { |
861
|
|
|
pods_deprecated( 'Pod Page PHP code has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' ); |
862
|
|
|
|
863
|
|
|
eval( "?>$content" ); |
|
|
|
|
864
|
|
|
} |
865
|
|
|
elseif ( is_object( $pods ) && !empty( $pods->id ) ) |
866
|
|
|
echo $pods->do_magic_tags( $content ); |
867
|
|
|
else |
868
|
|
|
echo $content; |
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
do_action( 'pods_content_post', $pods_page, $content ); |
872
|
|
|
|
873
|
|
|
$content = ob_get_clean(); |
874
|
|
|
|
875
|
|
|
if ( $pods_page == self::$exists ) |
876
|
|
|
self::$content_called = true; |
877
|
|
|
} |
878
|
|
|
|
879
|
|
|
$content = apply_filters( 'pods_content', $content, $pods_page ); |
880
|
|
|
|
881
|
|
|
if ( $return ) |
882
|
|
|
return $content; |
883
|
|
|
|
884
|
|
|
echo $content; |
885
|
|
|
} |
886
|
|
|
|
887
|
|
|
/** |
888
|
|
|
* Run any precode for current Pod Page |
889
|
|
|
*/ |
890
|
|
|
public function precode () { |
891
|
|
|
global $pods; |
|
|
|
|
892
|
|
|
|
893
|
|
|
// Fix any global confusion wherever this runs |
894
|
|
View Code Duplication |
if ( isset( $pods ) && !isset( $GLOBALS[ 'pods' ] ) ) |
895
|
|
|
$GLOBALS[ 'pods' ] =& $pods; |
896
|
|
|
elseif ( !isset( $pods ) && isset( $GLOBALS[ 'pods' ] ) ) |
897
|
|
|
$pods =& $GLOBALS[ 'pods' ]; |
898
|
|
|
|
899
|
|
|
if ( false !== self::$exists ) { |
900
|
|
|
$permission = pods_permission( self::$exists[ 'options' ] ); |
901
|
|
|
|
902
|
|
|
$permission = (boolean) apply_filters( 'pods_pages_permission', $permission, self::$exists ); |
903
|
|
|
|
904
|
|
|
if ( $permission ) { |
905
|
|
|
$content = false; |
906
|
|
|
|
907
|
|
|
if ( !is_object( $pods ) && 404 != $pods && 0 < strlen( pods_var( 'pod', self::$exists[ 'options' ] ) ) ) { |
908
|
|
|
$slug = pods_var_raw( 'pod_slug', self::$exists[ 'options' ], null, null, true ); |
909
|
|
|
|
910
|
|
|
// Handle special magic tags |
911
|
|
|
if ( 0 < strlen( $slug ) ) { |
912
|
|
|
$slug = pods_evaluate_tags( $slug, true ); |
913
|
|
|
} |
914
|
|
|
|
915
|
|
|
$pods = pods( pods_var( 'pod', self::$exists[ 'options' ] ), $slug ); |
916
|
|
|
|
917
|
|
|
// Auto 404 handling if item doesn't exist |
918
|
|
|
if ( 0 < strlen( $slug ) && !$pods->exists() && apply_filters( 'pods_pages_auto_404', true, $slug, $pods, self::$exists ) ) { |
919
|
|
|
$pods = 404; |
920
|
|
|
} |
921
|
|
|
} |
922
|
|
|
|
923
|
|
|
if ( 0 < strlen( trim( self::$exists[ 'precode' ] ) ) ) |
924
|
|
|
$content = self::$exists[ 'precode' ]; |
925
|
|
|
|
926
|
|
|
if ( false !== $content && ( !defined( 'PODS_DISABLE_EVAL' ) || !PODS_DISABLE_EVAL ) ) { |
927
|
|
|
pods_deprecated( 'Pod Page Precode has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' ); |
928
|
|
|
|
929
|
|
|
eval( "?>$content" ); |
|
|
|
|
930
|
|
|
} |
931
|
|
|
|
932
|
|
|
do_action( 'pods_page_precode', self::$exists, $pods, $content ); |
933
|
|
|
} |
934
|
|
|
elseif ( self::$exists[ 'options' ][ 'restrict_redirect' ] ) { |
935
|
|
|
$redirect_url = ''; |
936
|
|
|
|
937
|
|
|
if ( self::$exists[ 'options' ][ 'restrict_redirect_login' ] ) { |
938
|
|
|
$redirect_url = wp_login_url( pods_current_url() ); |
939
|
|
|
} |
940
|
|
|
elseif ( !empty( self::$exists[ 'options' ][ 'restrict_redirect_url' ] ) ) { |
941
|
|
|
$redirect_url = self::$exists[ 'options' ][ 'restrict_redirect_url' ]; |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
if ( !empty( $redirect_url ) ) { |
945
|
|
|
wp_redirect( $redirect_url ); |
946
|
|
|
die(); |
947
|
|
|
} |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
if ( !$permission || ( !is_object( $pods ) && ( 404 == $pods || is_wp_error( $pods ) ) ) ) { |
951
|
|
|
remove_action( 'template_redirect', array( $this, 'template_redirect' ) ); |
952
|
|
|
remove_action( 'wp_head', array( $this, 'wp_head' ) ); |
953
|
|
|
remove_filter( 'redirect_canonical', '__return_false' ); |
954
|
|
|
remove_filter( 'wp_title', array( $this, 'wp_title' ) ); |
955
|
|
|
remove_filter( 'body_class', array( $this, 'body_class' ) ); |
956
|
|
|
remove_filter( 'status_header', array( $this, 'status_header' ) ); |
957
|
|
|
remove_action( 'wp', array( $this, 'silence_404' ), 1 ); |
958
|
|
|
} |
959
|
|
|
} |
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* |
964
|
|
|
*/ |
965
|
|
|
public function wp_head () { |
966
|
|
|
global $pods; |
|
|
|
|
967
|
|
|
|
968
|
|
|
do_action( 'pods_wp_head' ); |
969
|
|
|
|
970
|
|
|
if ( !defined( 'PODS_DISABLE_VERSION_OUTPUT' ) || !PODS_DISABLE_VERSION_OUTPUT ) { |
971
|
|
|
?> |
972
|
|
|
<!-- Pods Framework <?php echo esc_html( PODS_VERSION ); ?> --> |
973
|
|
|
<?php |
974
|
|
|
} |
975
|
|
|
if ( ( !defined( 'PODS_DISABLE_META' ) || !PODS_DISABLE_META ) && is_object( $pods ) && !is_wp_error( $pods ) ) { |
976
|
|
|
|
977
|
|
View Code Duplication |
if ( isset( $pods->meta ) && is_array( $pods->meta ) && !empty( $pods->meta ) ) { |
978
|
|
|
foreach ( $pods->meta as $name => $content ) { |
979
|
|
|
if ( 'title' == $name ) |
980
|
|
|
continue; |
981
|
|
|
?> |
982
|
|
|
<meta name="<?php echo esc_attr( $name ); ?>" content="<?php echo esc_attr( $content ); ?>" /> |
983
|
|
|
<?php |
984
|
|
|
} |
985
|
|
|
} |
986
|
|
|
|
987
|
|
View Code Duplication |
if ( isset( $pods->meta_properties ) && is_array( $pods->meta_properties ) && !empty( $pods->meta_properties ) ) { |
988
|
|
|
foreach ( $pods->meta_properties as $property => $content ) { |
989
|
|
|
?> |
990
|
|
|
<meta property="<?php echo esc_attr( $property ); ?>" content="<?php echo esc_attr( $content ); ?>" /> |
991
|
|
|
<?php |
992
|
|
|
} |
993
|
|
|
} |
994
|
|
|
|
995
|
|
|
if ( isset( $pods->meta_extra ) && 0 < strlen( $pods->meta_extra ) ) |
996
|
|
|
echo $pods->meta_extra; |
997
|
|
|
} |
998
|
|
|
} |
999
|
|
|
|
1000
|
|
|
/** |
1001
|
|
|
* @param $title |
1002
|
|
|
* @param $sep |
1003
|
|
|
* @param $seplocation |
1004
|
|
|
* |
1005
|
|
|
* @return mixed|void |
1006
|
|
|
*/ |
1007
|
|
|
public function wp_title ( $title, $sep, $seplocation ) { |
1008
|
|
|
global $pods; |
|
|
|
|
1009
|
|
|
|
1010
|
|
|
$page_title = trim( self::$exists[ 'title' ] ); |
1011
|
|
|
|
1012
|
|
|
if ( 0 < strlen( $page_title ) ) { |
1013
|
|
|
if ( is_object( $pods ) && !is_wp_error( $pods ) ) |
1014
|
|
|
$page_title = $pods->do_magic_tags( $page_title ); |
1015
|
|
|
|
1016
|
|
|
$title = ( 'right' == $seplocation ) ? "{$page_title} {$sep} " : " {$sep} {$page_title}"; |
1017
|
|
|
} |
1018
|
|
|
elseif ( strlen( trim( $title ) ) < 1 ) { |
1019
|
|
|
$uri = explode( '?', $_SERVER[ 'REQUEST_URI' ] ); |
1020
|
|
|
$uri = preg_replace( '@^([/]?)(.*?)([/]?)$@', '$2', $uri[ 0 ] ); |
1021
|
|
|
$uri = preg_replace( '@(-|_)@', ' ', $uri ); |
1022
|
|
|
$uri = explode( '/', $uri ); |
1023
|
|
|
|
1024
|
|
|
$title = ''; |
1025
|
|
|
|
1026
|
|
|
foreach ( $uri as $key => $page_title ) { |
1027
|
|
|
$title .= ( 'right' == $seplocation ) ? ucwords( $page_title ) . " {$sep} " : " {$sep} " . ucwords( $page_title ); |
1028
|
|
|
} |
1029
|
|
|
} |
1030
|
|
|
|
1031
|
|
|
if ( ( !defined( 'PODS_DISABLE_META' ) || !PODS_DISABLE_META ) && is_object( $pods ) && !is_wp_error( $pods ) && isset( $pods->meta ) && is_array( $pods->meta ) && isset( $pods->meta[ 'title' ] ) ) |
1032
|
|
|
$title = $pods->meta[ 'title' ]; |
1033
|
|
|
|
1034
|
|
|
return apply_filters( 'pods_title', $title, $sep, $seplocation, self::$exists ); |
1035
|
|
|
} |
1036
|
|
|
|
1037
|
|
|
/** |
1038
|
|
|
* @param $classes |
1039
|
|
|
* |
1040
|
|
|
* @return mixed|void |
1041
|
|
|
*/ |
1042
|
|
|
public function body_class ( $classes ) { |
1043
|
|
|
global $pods; |
|
|
|
|
1044
|
|
|
|
1045
|
|
|
if ( defined( 'PODS_DISABLE_BODY_CLASSES' ) && PODS_DISABLE_BODY_CLASSES ) |
1046
|
|
|
return $classes; |
1047
|
|
|
|
1048
|
|
|
$classes[] = 'pods'; |
1049
|
|
|
|
1050
|
|
|
$uri = explode( '?', self::$exists[ 'uri' ] ); |
1051
|
|
|
$uri = explode( '#', $uri[ 0 ] ); |
1052
|
|
|
|
1053
|
|
|
$class = str_replace( array( '*', '/' ), array( '_w_', '-' ), $uri[ 0 ] ); |
1054
|
|
|
$class = sanitize_title( $class ); |
1055
|
|
|
$class = str_replace( array( '_', '--', '--' ), '-', $class ); |
1056
|
|
|
$class = trim( $class, '-' ); |
1057
|
|
|
|
1058
|
|
|
$classes[] = 'pod-page-' . $class; |
1059
|
|
|
|
1060
|
|
|
if ( is_object( $pods ) && !is_wp_error( $pods ) ) { |
1061
|
|
|
$class = sanitize_title( $pods->pod ); |
1062
|
|
|
$class = str_replace( array( '_', '--', '--' ), '-', $class ); |
1063
|
|
|
$class = trim( $class, '-' ); |
1064
|
|
|
$classes[] = 'pod-' . $class; |
1065
|
|
|
} |
1066
|
|
|
|
1067
|
|
|
if ( is_object( $pods ) && !is_wp_error( $pods ) && isset( $pods->body_classes ) ) |
1068
|
|
|
$classes[] = $pods->body_classes; |
1069
|
|
|
|
1070
|
|
|
return apply_filters( 'pods_body_class', $classes, $uri ); |
1071
|
|
|
} |
1072
|
|
|
|
1073
|
|
|
/** |
1074
|
|
|
* @return string |
1075
|
|
|
*/ |
1076
|
|
|
public function status_header () { |
1077
|
|
|
return $_SERVER[ 'SERVER_PROTOCOL' ] . ' 200 OK'; |
1078
|
|
|
} |
1079
|
|
|
|
1080
|
|
|
/** |
1081
|
|
|
* |
1082
|
|
|
*/ |
1083
|
|
|
public function silence_404 () { |
1084
|
|
|
global $wp_query; |
|
|
|
|
1085
|
|
|
|
1086
|
|
|
$wp_query->query_vars[ 'error' ] = ''; |
1087
|
|
|
$wp_query->is_404 = false; |
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
/** |
1091
|
|
|
* |
1092
|
|
|
*/ |
1093
|
|
|
public function template_redirect () { |
1094
|
|
|
global $pods; |
|
|
|
|
1095
|
|
|
|
1096
|
|
|
if ( false !== self::$exists ) { |
1097
|
|
|
/* |
1098
|
|
|
* Create pods.php in your theme directory, and |
1099
|
|
|
* style it to suit your needs. Some helpful functions: |
1100
|
|
|
* |
1101
|
|
|
* get_header() |
1102
|
|
|
* pods_content() |
1103
|
|
|
* get_sidebar() |
1104
|
|
|
* get_footer() |
1105
|
|
|
*/ |
1106
|
|
|
$template = self::$exists[ 'page_template' ]; |
1107
|
|
|
$template = apply_filters( 'pods_page_template', $template, self::$exists ); |
1108
|
|
|
|
1109
|
|
|
$render_function = apply_filters( 'pods_template_redirect', null, $template, self::$exists ); |
1110
|
|
|
|
1111
|
|
|
do_action( 'pods_page', $template, self::$exists ); |
1112
|
|
|
|
1113
|
|
|
if ( '_custom' == $template ) |
1114
|
|
|
pods_content(); |
1115
|
|
|
elseif ( null !== $render_function && is_callable( $render_function ) ) |
1116
|
|
|
call_user_func( $render_function, $template, self::$exists ); |
1117
|
|
|
elseif ( ( !defined( 'PODS_DISABLE_DYNAMIC_TEMPLATE' ) || !PODS_DISABLE_DYNAMIC_TEMPLATE ) && is_object( $pods ) && !is_wp_error( $pods ) && isset( $pods->page_template ) && !empty( $pods->page_template ) && '' != locate_template( array( $pods->page_template ), true ) ) { |
1118
|
|
|
$template = $pods->page_template; |
1119
|
|
|
// found the template and included it, we're good to go! |
1120
|
|
|
} |
1121
|
|
|
elseif ( !empty( self::$exists[ 'page_template' ] ) && '' != locate_template( array( self::$exists[ 'page_template' ] ), true ) ) { |
1122
|
|
|
$template = self::$exists[ 'page_template' ]; |
1123
|
|
|
// found the template and included it, we're good to go! |
1124
|
|
|
} |
1125
|
|
|
else { |
1126
|
|
|
$default_templates = array(); |
1127
|
|
|
|
1128
|
|
|
$uri = explode( '?', self::$exists[ 'uri' ] ); |
1129
|
|
|
$uri = explode( '#', $uri[ 0 ] ); |
1130
|
|
|
|
1131
|
|
|
$page_path = explode( '/', $uri[ 0 ] ); |
1132
|
|
|
|
1133
|
|
|
while ( $last = array_pop( $page_path ) ) { |
1134
|
|
|
$file_name = str_replace( '*', '-w-', implode( '/', $page_path ) . '/' . $last ); |
1135
|
|
|
$sanitized = sanitize_title( $file_name ); |
1136
|
|
|
|
1137
|
|
|
$default_templates[] = 'pods/' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php'; |
1138
|
|
|
$default_templates[] = 'pods-' . trim( str_replace( '--', '-', $sanitized ), ' -' ) . '.php'; |
1139
|
|
|
} |
1140
|
|
|
|
1141
|
|
|
$default_templates[] = 'pods.php'; |
1142
|
|
|
|
1143
|
|
|
$default_templates = apply_filters( 'pods_page_default_templates', $default_templates ); |
1144
|
|
|
|
1145
|
|
|
$template = locate_template( $default_templates, true ); |
1146
|
|
|
|
1147
|
|
|
if ( '' != $template ) { |
|
|
|
|
1148
|
|
|
// found the template and included it, we're good to go! |
1149
|
|
|
} |
1150
|
|
|
else { |
1151
|
|
|
$template = false; |
1152
|
|
|
|
1153
|
|
|
// templates not found in theme, default output |
1154
|
|
|
do_action( 'pods_page_default', $template, self::$exists ); |
1155
|
|
|
|
1156
|
|
|
get_header(); |
1157
|
|
|
pods_content(); |
1158
|
|
|
get_sidebar(); |
1159
|
|
|
get_footer(); |
1160
|
|
|
} |
1161
|
|
|
} |
1162
|
|
|
|
1163
|
|
|
do_action( 'pods_page_end', $template, self::$exists ); |
1164
|
|
|
|
1165
|
|
|
exit; |
1166
|
|
|
} |
1167
|
|
|
} |
1168
|
|
|
} |
1169
|
|
|
|
1170
|
|
|
/** |
1171
|
|
|
* Find out if the current page is a Pod Page |
1172
|
|
|
* |
1173
|
|
|
* @param string $uri The Pod Page URI to check if currently on |
1174
|
|
|
* |
1175
|
|
|
* @return bool |
1176
|
|
|
* @since 1.7.5 |
1177
|
|
|
*/ |
1178
|
|
|
function is_pod_page ( $uri = null ) { |
1179
|
|
|
if ( false !== Pods_Pages::$exists && ( null === $uri || $uri == Pods_Pages::$exists[ 'uri' ] || $uri == Pods_Pages::$exists[ 'id' ] ) ) |
|
|
|
|
1180
|
|
|
return true; |
1181
|
|
|
|
1182
|
|
|
return false; |
1183
|
|
|
} |
1184
|
|
|
|
1185
|
|
|
/** |
1186
|
|
|
* Check for a specific page template for the current pod page |
1187
|
|
|
* |
1188
|
|
|
* @param string $template The theme template file |
1189
|
|
|
* |
1190
|
|
|
* @return bool |
1191
|
|
|
* @since 2.3.7 |
1192
|
|
|
*/ |
1193
|
|
|
function is_pod_page_template ( $template = null ) { |
1194
|
|
|
if ( false !== Pods_Pages::$exists && $template == Pods_Pages::$exists[ 'page_template' ] ) |
|
|
|
|
1195
|
|
|
return true; |
1196
|
|
|
|
1197
|
|
|
return false; |
1198
|
|
|
} |
1199
|
|
|
|
1200
|
|
|
/** |
1201
|
|
|
* Get the current Pod Page URI |
1202
|
|
|
* |
1203
|
|
|
* @return string|bool |
1204
|
|
|
* @since 2.3.3 |
1205
|
|
|
*/ |
1206
|
|
|
function get_pod_page_uri () { |
1207
|
|
|
$pod_page = Pods_Pages::exists(); |
1208
|
|
|
|
1209
|
|
|
if ( !empty( $pod_page ) ) |
1210
|
|
|
return $pod_page[ 'uri' ]; |
1211
|
|
|
|
1212
|
|
|
return false; |
1213
|
|
|
} |
1214
|
|
|
|
1215
|
|
|
/** |
1216
|
|
|
* Check to see if Pod Page exists and return data |
1217
|
|
|
* |
1218
|
|
|
* $uri not required, if NULL then returns REQUEST_URI matching Pod Page |
1219
|
|
|
* |
1220
|
|
|
* @param string $uri The Pod Page URI to check if exists |
1221
|
|
|
* |
1222
|
|
|
* @return array |
1223
|
|
|
* |
1224
|
|
|
* @since 1.7.5 |
1225
|
|
|
*/ |
1226
|
|
|
function pod_page_exists ( $uri = null ) { |
1227
|
|
|
return Pods_Pages::exists( $uri ); |
1228
|
|
|
} |
1229
|
|
|
|
1230
|
|
|
/** |
1231
|
|
|
* Output Pod Page Content |
1232
|
|
|
* |
1233
|
|
|
* @param bool $return Whether to return or not (default is to echo) |
1234
|
|
|
* |
1235
|
|
|
* @return string |
1236
|
|
|
* |
1237
|
|
|
* @since 1.7.0 |
1238
|
|
|
*/ |
1239
|
|
|
function pods_content ( $return = false, $pods_page = false ) { |
1240
|
|
|
return Pods_Pages::content( $return, $pods_page ); |
1241
|
|
|
} |
1242
|
|
|
|
1243
|
|
|
/** |
1244
|
|
|
* Sort an array by length of items, descending, for use with uksort() |
1245
|
|
|
* |
1246
|
|
|
* @param string $a First array item |
1247
|
|
|
* @param string $b Second array item |
1248
|
|
|
* |
1249
|
|
|
* @return int Length difference |
1250
|
|
|
* |
1251
|
|
|
* @since 2.3.4 |
1252
|
|
|
*/ |
1253
|
|
|
function pods_page_length_sort ( $a, $b ) { |
1254
|
|
|
return strlen( $b ) - strlen( $a ); |
1255
|
|
|
} |
1256
|
|
|
|
1257
|
|
|
/** |
1258
|
|
|
* Flush Pod Page Rewrite cache |
1259
|
|
|
* |
1260
|
|
|
* @return array Pod Page Rewrites |
1261
|
|
|
* |
1262
|
|
|
* @since 2.3.4 |
1263
|
|
|
*/ |
1264
|
|
|
function pods_page_flush_rewrites () { |
1265
|
|
|
return Pods_Pages::flush_rewrites(); |
1266
|
|
|
} |
1267
|
|
|
|
1268
|
|
|
/* |
1269
|
|
|
* Deprecated global variable |
1270
|
|
|
*/ |
1271
|
|
|
$GLOBALS[ 'pod_page_exists' ] =& Pods_Pages::$exists; |
|
|
|
|
1272
|
|
|
|
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.