|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package Pods |
|
4
|
|
|
*/ |
|
5
|
|
|
class PodsAdmin { |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @var PodsAdmin |
|
9
|
|
|
*/ |
|
10
|
|
|
static $instance = null; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Singleton handling for a basic pods_admin() request |
|
14
|
|
|
* |
|
15
|
|
|
* @return \PodsAdmin |
|
16
|
|
|
* |
|
17
|
|
|
* @since 2.3.5 |
|
18
|
|
|
*/ |
|
19
|
|
|
public static function init () { |
|
20
|
|
|
if ( !is_object( self::$instance ) ) |
|
21
|
|
|
self::$instance = new PodsAdmin(); |
|
22
|
|
|
|
|
23
|
|
|
return self::$instance; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Setup and Handle Admin functionality |
|
28
|
|
|
* |
|
29
|
|
|
* @return \PodsAdmin |
|
|
|
|
|
|
30
|
|
|
* |
|
31
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html |
|
32
|
|
|
* @since 2.0 |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct () { |
|
35
|
|
|
// Scripts / Stylesheets |
|
36
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'admin_head' ), 20 ); |
|
37
|
|
|
|
|
38
|
|
|
// AJAX $_POST fix |
|
39
|
|
|
add_action( 'admin_init', array( $this, 'admin_init' ), 9 ); |
|
40
|
|
|
|
|
41
|
|
|
// Menus |
|
42
|
|
|
add_action( 'admin_menu', array( $this, 'admin_menu' ), 99 ); |
|
43
|
|
|
|
|
44
|
|
|
// AJAX for Admin |
|
45
|
|
|
add_action( 'wp_ajax_pods_admin', array( $this, 'admin_ajax' ) ); |
|
46
|
|
|
add_action( 'wp_ajax_nopriv_pods_admin', array( $this, 'admin_ajax' ) ); |
|
47
|
|
|
|
|
48
|
|
|
// Add Media Bar button for Shortcode |
|
49
|
|
|
add_action( 'media_buttons', array( $this, 'media_button' ), 12 ); |
|
50
|
|
|
|
|
51
|
|
|
// Add the Pods capabilities |
|
52
|
|
|
add_filter( 'members_get_capabilities', array( $this, 'admin_capabilities' ) ); |
|
53
|
|
|
|
|
54
|
|
|
add_action( 'admin_head-media-upload-popup', array( $this, 'register_media_assets' ) ); |
|
55
|
|
|
|
|
56
|
|
|
$this->rest_admin(); |
|
57
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Init the admin area |
|
62
|
|
|
* |
|
63
|
|
|
* @since 2.0 |
|
64
|
|
|
*/ |
|
65
|
|
|
public function admin_init () { |
|
66
|
|
|
// Fix for plugins that *don't do it right* so we don't cause issues for users |
|
67
|
|
|
if ( defined( 'DOING_AJAX' ) && !empty( $_POST ) ) { |
|
68
|
|
|
$pods_admin_ajax_actions = array( |
|
69
|
|
|
'pods_admin', |
|
70
|
|
|
'pods_relationship', |
|
71
|
|
|
'pods_upload', |
|
72
|
|
|
'pods_admin_components' |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Admin AJAX Callbacks |
|
77
|
|
|
* |
|
78
|
|
|
* @since unknown |
|
79
|
|
|
* |
|
80
|
|
|
* @param array $pods_admin_ajax_actions Array of actions to handle |
|
81
|
|
|
*/ |
|
82
|
|
|
$pods_admin_ajax_actions = apply_filters( 'pods_admin_ajax_actions', $pods_admin_ajax_actions ); |
|
83
|
|
|
|
|
84
|
|
|
if ( in_array( pods_var( 'action', 'get' ), $pods_admin_ajax_actions ) || in_array( pods_var( 'action', 'post' ), $pods_admin_ajax_actions ) ) { |
|
85
|
|
|
foreach ( $_POST as $key => $value ) { |
|
86
|
|
|
if ( 'action' == $key || 0 === strpos( $key, '_podsfix_' ) ) |
|
87
|
|
|
continue; |
|
88
|
|
|
|
|
89
|
|
|
unset( $_POST[ $key ] ); |
|
90
|
|
|
|
|
91
|
|
|
$_POST[ '_podsfix_' . $key ] = $value; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Attach requirements to admin header |
|
99
|
|
|
* |
|
100
|
|
|
* @since 2.0 |
|
101
|
|
|
*/ |
|
102
|
|
|
public function admin_head () { |
|
103
|
|
|
wp_register_style( 'pods-admin', PODS_URL . 'ui/css/pods-admin.css', array(), PODS_VERSION ); |
|
104
|
|
|
|
|
105
|
|
|
wp_register_style( 'pods-font', PODS_URL . 'ui/css/pods-font.css', array(), PODS_VERSION ); |
|
106
|
|
|
|
|
107
|
|
|
wp_register_script( 'pods-floatmenu', PODS_URL . 'ui/js/floatmenu.js', array(), PODS_VERSION ); |
|
108
|
|
|
|
|
109
|
|
|
wp_register_script( 'pods-admin-importer', PODS_URL . 'ui/js/admin-importer.js', array(), PODS_VERSION ); |
|
110
|
|
|
|
|
111
|
|
|
wp_register_style( 'pods-manage', PODS_URL . 'ui/css/pods-manage.css', array(), PODS_VERSION ); |
|
112
|
|
|
|
|
113
|
|
|
wp_register_style( 'pods-wizard', PODS_URL . 'ui/css/pods-wizard.css', array(), PODS_VERSION ); |
|
114
|
|
|
|
|
115
|
|
|
wp_register_script( 'pods-upgrade', PODS_URL . 'ui/js/jquery.pods.upgrade.js', array(), PODS_VERSION ); |
|
116
|
|
|
|
|
117
|
|
|
wp_register_script( 'pods-migrate', PODS_URL . 'ui/js/jquery.pods.migrate.js', array(), PODS_VERSION ); |
|
118
|
|
|
|
|
119
|
|
|
if ( isset( $_GET[ 'page' ] ) ) { |
|
120
|
|
|
$page = $_GET[ 'page' ]; |
|
121
|
|
|
if ( 'pods' == $page || ( false !== strpos( $page, 'pods-' ) && 0 === strpos( $page, 'pods-' ) ) ) { |
|
122
|
|
|
?> |
|
123
|
|
|
<script type="text/javascript"> |
|
124
|
|
|
var PODS_URL = "<?php echo esc_js( PODS_URL ); ?>"; |
|
125
|
|
|
</script> |
|
126
|
|
|
<?php |
|
127
|
|
|
wp_enqueue_script( 'jquery' ); |
|
128
|
|
|
wp_enqueue_script( 'jquery-ui-core' ); |
|
129
|
|
|
wp_enqueue_script( 'jquery-ui-sortable' ); |
|
130
|
|
|
|
|
131
|
|
|
wp_enqueue_style( 'jquery-ui' ); |
|
132
|
|
|
|
|
133
|
|
|
wp_enqueue_script( 'pods-floatmenu' ); |
|
134
|
|
|
|
|
135
|
|
|
wp_enqueue_style( 'jquery-qtip2' ); |
|
136
|
|
|
wp_enqueue_script( 'jquery-qtip2' ); |
|
137
|
|
|
wp_enqueue_script( 'pods-qtip-init' ); |
|
138
|
|
|
|
|
139
|
|
|
wp_enqueue_script( 'pods' ); |
|
140
|
|
|
|
|
141
|
|
|
if ( 0 === strpos( $page, 'pods-manage-' ) || 0 === strpos( $page, 'pods-add-new-' ) ) |
|
142
|
|
|
wp_enqueue_script( 'post' ); |
|
143
|
|
|
elseif ( 0 === strpos( $page, 'pods-settings-' ) ) { |
|
144
|
|
|
wp_enqueue_script( 'post' ); |
|
145
|
|
|
wp_enqueue_style( 'pods-admin' ); |
|
146
|
|
|
} |
|
147
|
|
|
else |
|
148
|
|
|
wp_enqueue_style( 'pods-admin' ); |
|
149
|
|
|
|
|
150
|
|
|
if ( 'pods-advanced' == $page ) { |
|
151
|
|
|
wp_register_style( 'pods-advanced', PODS_URL . 'ui/css/pods-advanced.css', array(), '1.0' ); |
|
152
|
|
|
wp_enqueue_style( 'pods-advanced' ); |
|
153
|
|
|
|
|
154
|
|
|
wp_enqueue_script( 'jquery-ui-effects-core', PODS_URL . 'ui/js/jquery-ui/jquery.effects.core.js', array( 'jquery' ), '1.8.8' ); |
|
155
|
|
|
wp_enqueue_script( 'jquery-ui-effects-fade', PODS_URL . 'ui/js/jquery-ui/jquery.effects.fade.js', array( 'jquery' ), '1.8.8' ); |
|
156
|
|
|
wp_enqueue_script( 'jquery-ui-dialog' ); |
|
157
|
|
|
|
|
158
|
|
|
wp_register_script( 'pods-advanced', PODS_URL . 'ui/js/advanced.js', array(), PODS_VERSION ); |
|
159
|
|
|
wp_enqueue_script( 'pods-advanced' ); |
|
160
|
|
|
} |
|
161
|
|
|
elseif ( 'pods-packages' == $page ) |
|
162
|
|
|
wp_enqueue_style( 'pods-wizard' ); |
|
163
|
|
|
elseif ( 'pods-wizard' == $page || 'pods-upgrade' == $page || ( in_array( $page, array( 'pods', 'pods-add-new' ) ) && in_array( pods_var( 'action', 'get', 'manage' ), array( 'add', 'manage' ) ) ) ) { |
|
164
|
|
|
wp_enqueue_style( 'pods-wizard' ); |
|
165
|
|
|
|
|
166
|
|
|
if ( 'pods-upgrade' == $page ) |
|
167
|
|
|
wp_enqueue_script( 'pods-upgrade' ); |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
wp_enqueue_style( 'pods-font' ); |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Build the admin menus |
|
177
|
|
|
* |
|
178
|
|
|
* @since 2.0 |
|
179
|
|
|
*/ |
|
180
|
|
|
public function admin_menu () { |
|
181
|
|
|
$advanced_content_types = PodsMeta::$advanced_content_types; |
|
182
|
|
|
$taxonomies = PodsMeta::$taxonomies; |
|
183
|
|
|
$settings = PodsMeta::$settings; |
|
184
|
|
|
|
|
185
|
|
|
$all_pods = pods_api()->load_pods( array( 'count' => true ) ); |
|
186
|
|
|
|
|
187
|
|
|
if ( !PodsInit::$upgrade_needed || ( pods_is_admin() && 1 == pods_var( 'pods_upgrade_bypass' ) ) ) { |
|
|
|
|
|
|
188
|
|
|
$submenu_items = array(); |
|
189
|
|
|
|
|
190
|
|
|
if ( !empty( $advanced_content_types ) ) { |
|
191
|
|
|
$submenu = array(); |
|
192
|
|
|
|
|
193
|
|
|
$pods_pages = 0; |
|
194
|
|
|
|
|
195
|
|
|
foreach ( (array) $advanced_content_types as $pod ) { |
|
196
|
|
|
if ( !isset( $pod[ 'name' ] ) || !isset( $pod[ 'options' ] ) || empty( $pod[ 'fields' ] ) ) |
|
197
|
|
|
continue; |
|
198
|
|
|
elseif ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ], 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) ) |
|
199
|
|
|
continue; |
|
200
|
|
|
|
|
201
|
|
|
if ( 1 == pods_var( 'show_in_menu', $pod[ 'options' ], 0 ) ) { |
|
202
|
|
|
$page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); |
|
203
|
|
|
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod ); |
|
204
|
|
|
|
|
205
|
|
|
$menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true ); |
|
206
|
|
|
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod ); |
|
207
|
|
|
|
|
208
|
|
|
$singular_label = pods_var_raw( 'label_singular', $pod[ 'options' ], pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ), null, true ); |
|
209
|
|
|
$plural_label = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); |
|
210
|
|
|
|
|
211
|
|
|
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'objects' ); |
|
212
|
|
|
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); |
|
213
|
|
|
|
|
214
|
|
|
$menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true ); |
|
215
|
|
|
$menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true ); |
|
216
|
|
|
|
|
217
|
|
|
if ( empty( $menu_position ) ) |
|
218
|
|
|
$menu_position = null; |
|
219
|
|
|
|
|
220
|
|
|
$parent_page = null; |
|
221
|
|
|
|
|
222
|
|
|
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ], 'pods_delete_' . $pod[ 'name' ] ) ) ) { |
|
223
|
|
|
if ( !empty( $menu_location_custom ) ) { |
|
224
|
|
|
if ( !isset( $submenu_items[ $menu_location_custom ] ) ) |
|
225
|
|
|
$submenu_items[ $menu_location_custom ] = array(); |
|
226
|
|
|
|
|
227
|
|
|
$submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', 'pods-manage-' . $pod[ 'name' ], array( $this, 'admin_content' ) ); |
|
228
|
|
|
|
|
229
|
|
|
continue; |
|
230
|
|
|
} |
|
231
|
|
|
else { |
|
232
|
|
|
$pods_pages++; |
|
233
|
|
|
|
|
234
|
|
|
$parent_page = $page = 'pods-manage-' . $pod[ 'name' ]; |
|
235
|
|
|
|
|
236
|
|
|
if ( empty( $menu_position ) ) |
|
237
|
|
|
$menu_position = null; |
|
238
|
|
|
add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position ); |
|
239
|
|
|
|
|
240
|
|
|
$all_title = $plural_label; |
|
241
|
|
|
$all_label = __( 'All', 'pods' ) . ' ' . $plural_label; |
|
242
|
|
|
|
|
243
|
|
View Code Duplication |
if ( $page == pods_var( 'page', 'get' ) ) { |
|
244
|
|
|
if ( 'edit' == pods_var( 'action', 'get', 'manage' ) ) |
|
245
|
|
|
$all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label; |
|
246
|
|
|
elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) ) |
|
247
|
|
|
$all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) ); |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_add_' . $pod[ 'name' ] ) ) ) { |
|
255
|
|
|
$page = 'pods-add-new-' . $pod[ 'name' ]; |
|
256
|
|
|
|
|
257
|
|
|
if ( null === $parent_page ) { |
|
258
|
|
|
$pods_pages++; |
|
259
|
|
|
|
|
260
|
|
|
$parent_page = $page; |
|
261
|
|
|
|
|
262
|
|
|
if ( empty( $menu_position ) ) |
|
263
|
|
|
$menu_position = null; |
|
264
|
|
|
add_menu_page( $page_title, $menu_label, 'read', $parent_page, '', $menu_icon, $menu_position ); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
$add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; |
|
268
|
|
|
$add_label = __( 'Add New', 'pods' ); |
|
269
|
|
|
|
|
270
|
|
|
add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) ); |
|
271
|
|
|
} |
|
272
|
|
|
} |
|
273
|
|
|
else |
|
274
|
|
|
$submenu[] = $pod; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
$submenu = apply_filters( 'pods_admin_menu_secondary_content', $submenu ); |
|
278
|
|
|
|
|
279
|
|
|
if ( !empty( $submenu ) && ( !defined( 'PODS_DISABLE_CONTENT_MENU' ) || !PODS_DISABLE_CONTENT_MENU ) ) { |
|
280
|
|
|
$parent_page = null; |
|
281
|
|
|
|
|
282
|
|
|
foreach ( $submenu as $item ) { |
|
283
|
|
|
$singular_label = pods_var_raw( 'label_singular', $item[ 'options' ], pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true ), null, true ); |
|
284
|
|
|
$plural_label = pods_var_raw( 'label', $item, ucwords( str_replace( '_', ' ', $item[ 'name' ] ) ), null, true ); |
|
285
|
|
|
|
|
286
|
|
|
if ( pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $item[ 'name' ], 'pods_delete_' . $item[ 'name' ] ) ) ) { |
|
287
|
|
|
$page = 'pods-manage-' . $item[ 'name' ]; |
|
288
|
|
|
|
|
289
|
|
View Code Duplication |
if ( null === $parent_page ) { |
|
290
|
|
|
$parent_page = $page; |
|
291
|
|
|
|
|
292
|
|
|
add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' ); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
$all_title = $plural_label; |
|
296
|
|
|
$all_label = __( 'Manage', 'pods' ) . ' ' . $plural_label; |
|
297
|
|
|
|
|
298
|
|
View Code Duplication |
if ( $page == pods_var( 'page', 'get' ) ) { |
|
299
|
|
|
if ( 'edit' == pods_var( 'action', 'get', 'manage' ) ) |
|
300
|
|
|
$all_title = __( 'Edit', 'pods' ) . ' ' . $singular_label; |
|
301
|
|
|
elseif ( 'add' == pods_var( 'action', 'get', 'manage' ) ) |
|
302
|
|
|
$all_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
add_submenu_page( $parent_page, $all_title, $all_label, 'read', $page, array( $this, 'admin_content' ) ); |
|
306
|
|
|
} |
|
307
|
|
|
elseif ( current_user_can( 'pods_add_' . $item[ 'name' ] ) ) { |
|
308
|
|
|
$page = 'pods-add-new-' . $item[ 'name' ]; |
|
309
|
|
|
|
|
310
|
|
View Code Duplication |
if ( null === $parent_page ) { |
|
311
|
|
|
$parent_page = $page; |
|
312
|
|
|
|
|
313
|
|
|
add_menu_page( 'Pods', 'Pods', 'read', $parent_page, null, 'dashicons-pods', '58.5' ); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
$add_title = __( 'Add New', 'pods' ) . ' ' . $singular_label; |
|
317
|
|
|
$add_label = __( 'Manage', 'pods' ) . ' ' . $plural_label; |
|
318
|
|
|
|
|
319
|
|
|
add_submenu_page( $parent_page, $add_title, $add_label, 'read', $page, array( $this, 'admin_content' ) ); |
|
320
|
|
|
} |
|
321
|
|
|
} |
|
322
|
|
|
} |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
if ( !empty( $taxonomies ) ) { |
|
326
|
|
|
foreach ( (array) $taxonomies as $pod ) { |
|
327
|
|
View Code Duplication |
if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) ) |
|
328
|
|
|
continue; |
|
329
|
|
|
|
|
330
|
|
|
$page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); |
|
331
|
|
|
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod ); |
|
332
|
|
|
|
|
333
|
|
|
$menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true ); |
|
334
|
|
|
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod ); |
|
335
|
|
|
|
|
336
|
|
|
$menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true ); |
|
337
|
|
|
$menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true ); |
|
338
|
|
|
|
|
339
|
|
|
if ( empty( $menu_position ) ) |
|
340
|
|
|
$menu_position = null; |
|
341
|
|
|
|
|
342
|
|
|
$menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ]; |
|
343
|
|
|
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' ); |
|
344
|
|
|
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); |
|
345
|
|
|
|
|
346
|
|
|
if ( 'default' == $menu_location ) |
|
347
|
|
|
continue; |
|
348
|
|
|
|
|
349
|
|
|
$taxonomy_data = get_taxonomy( $pod[ 'name' ] ); |
|
350
|
|
|
|
|
351
|
|
|
foreach ( (array) $taxonomy_data->object_type as $post_type ) { |
|
352
|
|
|
if ( 'post' == $post_type ) |
|
353
|
|
|
remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] ); |
|
354
|
|
|
elseif ( 'attachment' == $post_type ) |
|
355
|
|
|
remove_submenu_page( 'upload.php', 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type ); |
|
356
|
|
|
else |
|
357
|
|
|
remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . $pod[ 'name' ] . '&post_type=' . $post_type ); |
|
358
|
|
|
} |
|
359
|
|
|
|
|
360
|
|
|
if ( 'settings' == $menu_location ) |
|
361
|
|
|
add_options_page( $page_title, $menu_label, 'read', $menu_slug ); |
|
362
|
|
|
elseif ( 'appearances' == $menu_location ) |
|
363
|
|
|
add_theme_page( $page_title, $menu_label, 'read', $menu_slug ); |
|
364
|
|
|
elseif ( 'objects' == $menu_location ) { |
|
365
|
|
|
if ( empty( $menu_position ) ) |
|
366
|
|
|
$menu_position = null; |
|
367
|
|
|
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position ); |
|
368
|
|
|
} |
|
369
|
|
|
elseif ( 'top' == $menu_location ) |
|
370
|
|
|
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, '', $menu_icon, $menu_position ); |
|
371
|
|
View Code Duplication |
elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) { |
|
372
|
|
|
if ( !isset( $submenu_items[ $menu_location_custom ] ) ) |
|
373
|
|
|
$submenu_items[ $menu_location_custom ] = array(); |
|
374
|
|
|
|
|
375
|
|
|
$submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, '' ); |
|
376
|
|
|
} |
|
377
|
|
|
} |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
if ( !empty( $settings ) ) { |
|
381
|
|
|
foreach ( (array) $settings as $pod ) { |
|
382
|
|
View Code Duplication |
if ( !pods_is_admin( array( 'pods', 'pods_content', 'pods_edit_' . $pod[ 'name' ] ) ) ) |
|
383
|
|
|
continue; |
|
384
|
|
|
|
|
385
|
|
|
$page_title = pods_var_raw( 'label', $pod, ucwords( str_replace( '_', ' ', $pod[ 'name' ] ) ), null, true ); |
|
386
|
|
|
$page_title = apply_filters( 'pods_admin_menu_page_title', $page_title, $pod ); |
|
387
|
|
|
|
|
388
|
|
|
$menu_label = pods_var_raw( 'menu_name', $pod[ 'options' ], $page_title, null, true ); |
|
389
|
|
|
$menu_label = apply_filters( 'pods_admin_menu_label', $menu_label, $pod ); |
|
390
|
|
|
|
|
391
|
|
|
$menu_position = pods_var_raw( 'menu_position', $pod[ 'options' ], '', null, true ); |
|
392
|
|
|
$menu_icon = pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod[ 'options' ], '', null, true ), true ); |
|
393
|
|
|
|
|
394
|
|
|
if ( empty( $menu_position ) ) |
|
395
|
|
|
$menu_position = null; |
|
396
|
|
|
|
|
397
|
|
|
$menu_slug = 'pods-settings-' . $pod[ 'name' ]; |
|
398
|
|
|
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'settings' ); |
|
399
|
|
|
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); |
|
400
|
|
|
|
|
401
|
|
|
if ( 'settings' == $menu_location ) |
|
402
|
|
|
add_options_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) ); |
|
403
|
|
|
elseif ( 'appearances' == $menu_location ) |
|
404
|
|
|
add_theme_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) ); |
|
405
|
|
View Code Duplication |
elseif ( 'objects' == $menu_location ) { |
|
406
|
|
|
if ( empty( $menu_position ) ) |
|
407
|
|
|
$menu_position = null; |
|
408
|
|
|
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position ); |
|
409
|
|
|
} |
|
410
|
|
View Code Duplication |
elseif ( 'top' == $menu_location ) |
|
411
|
|
|
add_menu_page( $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ), $menu_icon, $menu_position ); |
|
412
|
|
View Code Duplication |
elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) { |
|
413
|
|
|
if ( !isset( $submenu_items[ $menu_location_custom ] ) ) |
|
414
|
|
|
$submenu_items[ $menu_location_custom ] = array(); |
|
415
|
|
|
|
|
416
|
|
|
$submenu_items[ $menu_location_custom ][] = array( $menu_location_custom, $page_title, $menu_label, 'read', $menu_slug, array( $this, 'admin_content_settings' ) ); |
|
417
|
|
|
} |
|
418
|
|
|
} |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
foreach ( $submenu_items as $items ) { |
|
422
|
|
|
foreach ( $items as $item ) { |
|
423
|
|
|
call_user_func_array( 'add_submenu_page', $item ); |
|
424
|
|
|
} |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
$admin_menus = array( |
|
428
|
|
|
'pods' => array( |
|
429
|
|
|
'label' => __( 'Edit Pods', 'pods' ), |
|
430
|
|
|
'function' => array( $this, 'admin_setup' ), |
|
431
|
|
|
'access' => 'pods' |
|
432
|
|
|
), |
|
433
|
|
|
'pods-add-new' => array( |
|
434
|
|
|
'label' => __( 'Add New', 'pods' ), |
|
435
|
|
|
'function' => array( $this, 'admin_setup' ), |
|
436
|
|
|
'access' => 'pods' |
|
437
|
|
|
), |
|
438
|
|
|
'pods-components' => array( |
|
439
|
|
|
'label' => __( 'Components', 'pods' ), |
|
440
|
|
|
'function' => array( $this, 'admin_components' ), |
|
441
|
|
|
'access' => 'pods_components' |
|
442
|
|
|
), |
|
443
|
|
|
'pods-settings' => array( |
|
444
|
|
|
'label' => __( 'Settings', 'pods' ), |
|
445
|
|
|
'function' => array( $this, 'admin_settings' ), |
|
446
|
|
|
'access' => 'pods_settings' |
|
447
|
|
|
), |
|
448
|
|
|
'pods-help' => array( |
|
449
|
|
|
'label' => __( 'Help', 'pods' ), |
|
450
|
|
|
'function' => array( $this, 'admin_help' ) |
|
451
|
|
|
) |
|
452
|
|
|
); |
|
453
|
|
|
|
|
454
|
|
|
if ( empty( $all_pods ) ) |
|
455
|
|
|
unset( $admin_menus[ 'pods' ] ); |
|
456
|
|
|
|
|
457
|
|
|
add_filter( 'parent_file' , array( $this, 'parent_file' ) ); |
|
458
|
|
|
} |
|
459
|
|
|
else { |
|
460
|
|
|
$admin_menus = array( |
|
461
|
|
|
'pods-upgrade' => array( |
|
462
|
|
|
'label' => __( 'Upgrade', 'pods' ), |
|
463
|
|
|
'function' => array( $this, 'admin_upgrade' ), |
|
464
|
|
|
'access' => 'manage_options' |
|
465
|
|
|
), |
|
466
|
|
|
'pods-settings' => array( |
|
467
|
|
|
'label' => __( 'Settings', 'pods' ), |
|
468
|
|
|
'function' => array( $this, 'admin_settings' ), |
|
469
|
|
|
'access' => 'pods_settings' |
|
470
|
|
|
), |
|
471
|
|
|
'pods-help' => array( |
|
472
|
|
|
'label' => __( 'Help', 'pods' ), |
|
473
|
|
|
'function' => array( $this, 'admin_help' ) |
|
474
|
|
|
) |
|
475
|
|
|
); |
|
476
|
|
|
|
|
477
|
|
|
add_action( 'admin_notices', array( $this, 'upgrade_notice' ) ); |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
/** |
|
481
|
|
|
* Add or change Pods Admin menu items |
|
482
|
|
|
* |
|
483
|
|
|
* @params array $admin_menus The submenu items in Pods Admin menu. |
|
484
|
|
|
* |
|
485
|
|
|
* @since unknown |
|
486
|
|
|
*/ |
|
487
|
|
|
$admin_menus = apply_filters( 'pods_admin_menu', $admin_menus ); |
|
488
|
|
|
|
|
489
|
|
|
$parent = false; |
|
490
|
|
|
|
|
491
|
|
|
if ( !empty( $admin_menus ) && ( !defined( 'PODS_DISABLE_ADMIN_MENU' ) || !PODS_DISABLE_ADMIN_MENU ) ) { |
|
492
|
|
|
foreach ( $admin_menus as $page => $menu_item ) { |
|
493
|
|
|
if ( !pods_is_admin( pods_var_raw( 'access', $menu_item ) ) ) |
|
494
|
|
|
continue; |
|
495
|
|
|
|
|
496
|
|
|
// Don't just show the help page |
|
497
|
|
|
if ( false === $parent && 'pods-help' == $page ) |
|
498
|
|
|
continue; |
|
499
|
|
|
|
|
500
|
|
|
if ( !isset( $menu_item[ 'label' ] ) ) |
|
501
|
|
|
$menu_item[ 'label' ] = $page; |
|
502
|
|
|
|
|
503
|
|
|
if ( false === $parent ) { |
|
504
|
|
|
$parent = $page; |
|
505
|
|
|
|
|
506
|
|
|
$menu = __( 'Pods Admin', 'pods' ); |
|
507
|
|
|
|
|
508
|
|
|
if ( 'pods-upgrade' == $parent ) |
|
509
|
|
|
$menu = __( 'Pods Upgrade', 'pods' ); |
|
510
|
|
|
|
|
511
|
|
|
add_menu_page( $menu, $menu, 'read', $parent, null, 'dashicons-pods' ); |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
add_submenu_page( $parent, $menu_item[ 'label' ], $menu_item[ 'label' ], 'read', $page, $menu_item[ 'function' ] ); |
|
515
|
|
|
|
|
516
|
|
|
if ( 'pods-components' == $page ) |
|
517
|
|
|
PodsInit::$components->menu( $parent ); |
|
|
|
|
|
|
518
|
|
|
} |
|
519
|
|
|
} |
|
520
|
|
|
} |
|
521
|
|
|
|
|
522
|
|
|
/** |
|
523
|
|
|
* Set the correct parent_file to highlight the correct top level menu |
|
524
|
|
|
* |
|
525
|
|
|
* @param $parent_file The parent file |
|
526
|
|
|
* |
|
527
|
|
|
* @return mixed|string |
|
528
|
|
|
* |
|
529
|
|
|
* @since unknown |
|
530
|
|
|
*/ |
|
531
|
|
|
public function parent_file ( $parent_file ) { |
|
532
|
|
|
global $current_screen; |
|
|
|
|
|
|
533
|
|
|
|
|
534
|
|
|
if ( isset( $current_screen ) && ! empty( $current_screen->taxonomy ) ) { |
|
535
|
|
|
$taxonomies = PodsMeta::$taxonomies; |
|
536
|
|
|
if ( !empty( $taxonomies ) ) { |
|
537
|
|
|
foreach ( (array) $taxonomies as $pod ) { |
|
538
|
|
|
if ( $current_screen->taxonomy !== $pod[ 'name' ] ) |
|
539
|
|
|
continue; |
|
540
|
|
|
|
|
541
|
|
|
$menu_slug = 'edit-tags.php?taxonomy=' . $pod[ 'name' ]; |
|
542
|
|
|
$menu_location = pods_var( 'menu_location', $pod[ 'options' ], 'default' ); |
|
543
|
|
|
$menu_location_custom = pods_var( 'menu_location_custom', $pod[ 'options' ], '' ); |
|
544
|
|
|
|
|
545
|
|
|
if ( 'settings' == $menu_location ) |
|
546
|
|
|
$parent_file = 'options-general.php'; |
|
547
|
|
|
elseif ( 'appearances' == $menu_location ) |
|
548
|
|
|
$parent_file = 'themes.php'; |
|
549
|
|
|
elseif ( 'objects' == $menu_location ) |
|
550
|
|
|
$parent_file = $menu_slug; |
|
551
|
|
|
elseif ( 'top' == $menu_location ) |
|
552
|
|
|
$parent_file = $menu_slug; |
|
553
|
|
|
elseif ( 'submenu' == $menu_location && !empty( $menu_location_custom ) ) { |
|
554
|
|
|
$parent_file = $menu_location_custom; |
|
555
|
|
|
} |
|
556
|
|
|
|
|
557
|
|
|
break; |
|
558
|
|
|
} |
|
559
|
|
|
} |
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
if ( isset( $current_screen ) && ! empty( $current_screen->post_type ) ) { |
|
563
|
|
|
global $submenu_file; |
|
|
|
|
|
|
564
|
|
|
$components = PodsInit::$components->components; |
|
|
|
|
|
|
565
|
|
|
foreach ( $components as $component => $component_data ) { |
|
|
|
|
|
|
566
|
|
|
if ( ! empty( $component_data[ 'MenuPage' ] ) && $parent_file === $component_data[ 'MenuPage' ] ) { |
|
567
|
|
|
$parent_file = 'pods'; |
|
568
|
|
|
$submenu_file = $component_data[ 'MenuPage' ]; |
|
569
|
|
|
} |
|
570
|
|
|
} |
|
571
|
|
|
} |
|
572
|
|
|
|
|
573
|
|
|
return $parent_file; |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
public function upgrade_notice () { |
|
577
|
|
|
echo '<div class="error fade"><p>'; |
|
578
|
|
|
echo sprintf( |
|
579
|
|
|
__( '<strong>NOTICE:</strong> Pods %s requires your action to complete the upgrade. Please run the <a href="%s">Upgrade Wizard</a>.', 'pods' ), |
|
580
|
|
|
esc_html( PODS_VERSION ), |
|
581
|
|
|
esc_url( admin_url( 'admin.php?page=pods-upgrade' ) ) |
|
582
|
|
|
); |
|
583
|
|
|
echo '</p></div>'; |
|
584
|
|
|
} |
|
585
|
|
|
|
|
586
|
|
|
/** |
|
587
|
|
|
* Create PodsUI content for the administration pages |
|
588
|
|
|
*/ |
|
589
|
|
|
public function admin_content () { |
|
590
|
|
|
$pod_name = str_replace( array( 'pods-manage-', 'pods-add-new-' ), '', $_GET[ 'page' ] ); |
|
591
|
|
|
|
|
592
|
|
|
$pod = pods( $pod_name, pods_var( 'id', 'get', null, null, true ) ); |
|
593
|
|
|
|
|
594
|
|
|
if ( false !== strpos( $_GET[ 'page' ], 'pods-add-new-' ) ) |
|
595
|
|
|
$_GET[ 'action' ] = pods_var( 'action', 'get', 'add' ); |
|
596
|
|
|
|
|
597
|
|
|
$pod->ui(); |
|
598
|
|
|
} |
|
599
|
|
|
|
|
600
|
|
|
/** |
|
601
|
|
|
* Create PodsUI content for the settings administration pages |
|
602
|
|
|
*/ |
|
603
|
|
|
public function admin_content_settings () { |
|
604
|
|
|
$pod_name = str_replace( 'pods-settings-', '', $_GET[ 'page' ] ); |
|
605
|
|
|
|
|
606
|
|
|
$pod = pods( $pod_name ); |
|
607
|
|
|
|
|
608
|
|
|
if ( 'custom' != pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ) ) { |
|
609
|
|
|
$actions_disabled = array( |
|
610
|
|
|
'manage' => 'manage', |
|
611
|
|
|
'add' => 'add', |
|
612
|
|
|
'delete' => 'delete', |
|
613
|
|
|
'duplicate' => 'duplicate', |
|
614
|
|
|
'view' => 'view', |
|
615
|
|
|
'export' => 'export' |
|
616
|
|
|
); |
|
617
|
|
|
|
|
618
|
|
|
$_GET[ 'action' ] = 'edit'; |
|
619
|
|
|
|
|
620
|
|
|
$page_title = pods_var_raw( 'label', $pod->pod_data, ucwords( str_replace( '_', ' ', $pod->pod_data[ 'name' ] ) ), null, true ); |
|
621
|
|
|
|
|
622
|
|
|
$ui = array( |
|
623
|
|
|
'pod' => $pod, |
|
624
|
|
|
'fields' => array( |
|
625
|
|
|
'edit' => $pod->pod_data[ 'fields' ] |
|
626
|
|
|
), |
|
627
|
|
|
'header' => array( |
|
628
|
|
|
'edit' => $page_title |
|
629
|
|
|
), |
|
630
|
|
|
'label' => array( |
|
631
|
|
|
'edit' => __( 'Save Changes', 'pods' ) |
|
632
|
|
|
), |
|
633
|
|
|
'style' => pods_var( 'ui_style', $pod->pod_data[ 'options' ], 'settings', null, true ), |
|
634
|
|
|
'icon' => pods_evaluate_tags( pods_var_raw( 'menu_icon', $pod->pod_data[ 'options' ] ), true ), |
|
635
|
|
|
'actions_disabled' => $actions_disabled |
|
636
|
|
|
); |
|
637
|
|
|
|
|
638
|
|
|
$ui = apply_filters( 'pods_admin_ui_' . $pod->pod, apply_filters( 'pods_admin_ui', $ui, $pod->pod, $pod ), $pod->pod, $pod ); |
|
639
|
|
|
|
|
640
|
|
|
// Force disabled actions, do not pass go, do not collect $two_hundred |
|
641
|
|
|
$ui[ 'actions_disabled' ] = $actions_disabled; |
|
642
|
|
|
|
|
643
|
|
|
pods_ui( $ui ); |
|
644
|
|
|
} |
|
645
|
|
|
else { |
|
646
|
|
|
do_action( 'pods_admin_ui_custom', $pod ); |
|
647
|
|
|
do_action( 'pods_admin_ui_custom_' . $pod->pod, $pod ); |
|
648
|
|
|
} |
|
649
|
|
|
} |
|
650
|
|
|
|
|
651
|
|
|
/** |
|
652
|
|
|
* Add media button for Pods shortcode |
|
653
|
|
|
* |
|
654
|
|
|
* @param $context |
|
655
|
|
|
* |
|
656
|
|
|
* @return string |
|
657
|
|
|
*/ |
|
658
|
|
|
public function media_button ( $context = null ) { |
|
659
|
|
|
// If shortcodes are disabled don't show the button |
|
660
|
|
|
if ( defined( 'PODS_DISABLE_SHORTCODE' ) && PODS_DISABLE_SHORTCODE ) { |
|
661
|
|
|
return ''; |
|
662
|
|
|
} |
|
663
|
|
|
|
|
664
|
|
|
/** |
|
665
|
|
|
* Filter to remove Pods shortcode button from the post editor. |
|
666
|
|
|
* |
|
667
|
|
|
* @param bool. Set to false to block the shortcode button from appearing. |
|
668
|
|
|
* @param string $context |
|
669
|
|
|
* |
|
670
|
|
|
* @since 2.3.19 |
|
671
|
|
|
*/ |
|
672
|
|
|
if ( !apply_filters( 'pods_admin_media_button', true, $context ) ) { |
|
673
|
|
|
return ''; |
|
674
|
|
|
} |
|
675
|
|
|
|
|
676
|
|
|
$current_page = basename( $_SERVER[ 'PHP_SELF' ] ); |
|
677
|
|
|
$current_page = explode( '?', $current_page ); |
|
678
|
|
|
$current_page = explode( '#', $current_page[ 0 ] ); |
|
679
|
|
|
$current_page = $current_page[ 0 ]; |
|
680
|
|
|
|
|
681
|
|
|
// Only show the button on post type pages |
|
682
|
|
|
if ( !in_array( $current_page, array( 'post-new.php', 'post.php' ) ) ) |
|
683
|
|
|
return ''; |
|
684
|
|
|
|
|
685
|
|
|
add_action( 'admin_footer', array( $this, 'mce_popup' ) ); |
|
686
|
|
|
|
|
687
|
|
|
echo '<a href="#TB_inline?width=640&inlineId=pods_shortcode_form" class="thickbox button" id="add_pod_button" title="Pods Shortcode"><img style="padding: 0px 6px 0px 0px; margin: -3px 0px 0px;" src="' . PODS_URL . 'ui/images/icon16.png" alt="' . __('Pods Shortcode' ,'pods') . '" />' . __('Pods Shortcode' ,'pods') . '</a>'; |
|
688
|
|
|
} |
|
689
|
|
|
|
|
690
|
|
|
/** |
|
691
|
|
|
* Enqueue assets for Media Library Popup |
|
692
|
|
|
*/ |
|
693
|
|
|
public function register_media_assets () { |
|
694
|
|
|
if ( 'pods_media_attachment' == pods_var( 'inlineId', 'get' ) ) |
|
695
|
|
|
wp_enqueue_style( 'pods-attach' ); |
|
696
|
|
|
} |
|
697
|
|
|
|
|
698
|
|
|
/** |
|
699
|
|
|
* Output Pods shortcode popup window |
|
700
|
|
|
*/ |
|
701
|
|
|
public function mce_popup () { |
|
702
|
|
|
pods_view( PODS_DIR . 'ui/admin/shortcode.php', compact( array_keys( get_defined_vars() ) ) ); |
|
703
|
|
|
} |
|
704
|
|
|
|
|
705
|
|
|
/** |
|
706
|
|
|
* Handle main Pods Setup area for managing Pods and Fields |
|
707
|
|
|
*/ |
|
708
|
|
|
public function admin_setup () { |
|
709
|
|
|
$pods = pods_api()->load_pods( array( 'fields' => false ) ); |
|
710
|
|
|
|
|
711
|
|
|
$view = pods_var( 'view', 'get', 'all', null, true ); |
|
712
|
|
|
|
|
713
|
|
|
if ( empty( $pods ) && !isset( $_GET[ 'action' ] ) ) |
|
714
|
|
|
$_GET[ 'action' ] = 'add'; |
|
715
|
|
|
|
|
716
|
|
|
if ( 'pods-add-new' == $_GET[ 'page' ] ) { |
|
717
|
|
|
if ( isset( $_GET[ 'action' ] ) && 'add' != $_GET[ 'action' ] ) |
|
718
|
|
|
pods_redirect( pods_query_arg( array( 'page' => 'pods', 'action' => $_GET[ 'action' ] ) ) ); |
|
719
|
|
|
else |
|
720
|
|
|
$_GET[ 'action' ] = 'add'; |
|
721
|
|
|
} |
|
722
|
|
|
elseif ( isset( $_GET[ 'action' ] ) && 'add' == $_GET[ 'action' ] ) |
|
723
|
|
|
pods_redirect( pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '' ) ) ); |
|
724
|
|
|
|
|
725
|
|
|
$types = array( |
|
726
|
|
|
'post_type' => __( 'Post Type (extended)', 'pods' ), |
|
727
|
|
|
'taxonomy' => __( 'Taxonomy (extended)', 'pods' ), |
|
728
|
|
|
'cpt' => __( 'Custom Post Type', 'pods' ), |
|
729
|
|
|
'ct' => __( 'Custom Taxonomy', 'pods' ), |
|
730
|
|
|
'user' => __( 'User (extended)', 'pods' ), |
|
731
|
|
|
'media' => __( 'Media (extended)', 'pods' ), |
|
732
|
|
|
'comment' => __( 'Comments (extended)', 'pods' ), |
|
733
|
|
|
'pod' => __( 'Advanced Content Type', 'pods' ), |
|
734
|
|
|
'settings' => __( 'Custom Settings Page', 'pods' ) |
|
735
|
|
|
); |
|
736
|
|
|
|
|
737
|
|
|
$row = false; |
|
738
|
|
|
|
|
739
|
|
|
$pod_types_found = array(); |
|
740
|
|
|
|
|
741
|
|
|
$fields = array( |
|
742
|
|
|
'label' => array( 'label' => __( 'Label', 'pods' ) ), |
|
743
|
|
|
'name' => array( 'label' => __( 'Name', 'pods' ) ), |
|
744
|
|
|
'type' => array( 'label' => __( 'Type', 'pods' ) ), |
|
745
|
|
|
'storage' => array( |
|
746
|
|
|
'label' => __( 'Storage Type', 'pods' ), |
|
747
|
|
|
'width' => '10%' |
|
748
|
|
|
), |
|
749
|
|
|
'field_count' => array( |
|
750
|
|
|
'label' => __( 'Number of Fields', 'pods' ), |
|
751
|
|
|
'width' => '8%' |
|
752
|
|
|
) |
|
753
|
|
|
); |
|
754
|
|
|
|
|
755
|
|
|
$total_fields = 0; |
|
756
|
|
|
|
|
757
|
|
|
foreach ( $pods as $k => $pod ) { |
|
|
|
|
|
|
758
|
|
|
if ( isset( $types[ $pod[ 'type' ] ] ) ) { |
|
759
|
|
|
if ( in_array( $pod[ 'type' ], array( 'post_type', 'taxonomy' ) ) ) { |
|
760
|
|
|
if ( empty( $pod[ 'object' ] ) ) { |
|
761
|
|
|
if ( 'post_type' == $pod[ 'type' ] ) |
|
762
|
|
|
$pod[ 'type' ] = 'cpt'; |
|
763
|
|
|
else |
|
764
|
|
|
$pod[ 'type' ] = 'ct'; |
|
765
|
|
|
} |
|
766
|
|
|
} |
|
767
|
|
|
|
|
768
|
|
|
if ( !isset( $pod_types_found[ $pod[ 'type' ] ] ) ) |
|
769
|
|
|
$pod_types_found[ $pod[ 'type' ] ] = 1; |
|
770
|
|
|
else |
|
771
|
|
|
$pod_types_found[ $pod[ 'type' ] ]++; |
|
772
|
|
|
|
|
773
|
|
|
if ( 'all' != $view && $view != $pod[ 'type' ] ) { |
|
774
|
|
|
unset( $pods[ $k ] ); |
|
775
|
|
|
|
|
776
|
|
|
continue; |
|
777
|
|
|
} |
|
778
|
|
|
|
|
779
|
|
|
$pod[ 'real_type' ] = $pod[ 'type' ]; |
|
780
|
|
|
$pod[ 'type' ] = $types[ $pod[ 'type' ] ]; |
|
781
|
|
|
} |
|
782
|
|
|
elseif ( 'all' != $view ) |
|
783
|
|
|
continue; |
|
784
|
|
|
|
|
785
|
|
|
$pod[ 'storage' ] = ucwords( $pod[ 'storage' ] ); |
|
786
|
|
|
|
|
787
|
|
|
if ( $pod[ 'id' ] == pods_var( 'id' ) && 'delete' != pods_var( 'action' ) ) |
|
788
|
|
|
$row = $pod; |
|
789
|
|
|
|
|
790
|
|
|
$pod = array( |
|
791
|
|
|
'id' => $pod[ 'id' ], |
|
792
|
|
|
'label' => pods_var_raw( 'label', $pod ), |
|
793
|
|
|
'name' => pods_var_raw( 'name', $pod ), |
|
794
|
|
|
'object' => pods_var_raw( 'object', $pod ), |
|
795
|
|
|
'type' => pods_var_raw( 'type', $pod ), |
|
796
|
|
|
'real_type' => pods_var_raw( 'real_type', $pod ), |
|
797
|
|
|
'storage' => pods_var_raw( 'storage', $pod ), |
|
798
|
|
|
'field_count' => count( $pod[ 'fields' ] ) |
|
799
|
|
|
); |
|
800
|
|
|
|
|
801
|
|
|
$total_fields += $pod[ 'field_count' ]; |
|
802
|
|
|
|
|
803
|
|
|
$pods[ $k ] = $pod; |
|
804
|
|
|
} |
|
805
|
|
|
|
|
806
|
|
|
if ( false === $row && 0 < pods_var( 'id' ) && 'delete' != pods_var( 'action' ) ) { |
|
807
|
|
|
pods_message( 'Pod not found', 'error' ); |
|
808
|
|
|
|
|
809
|
|
|
unset( $_GET[ 'id' ] ); |
|
810
|
|
|
unset( $_GET[ 'action' ] ); |
|
811
|
|
|
} |
|
812
|
|
|
|
|
813
|
|
|
$ui = array( |
|
814
|
|
|
'data' => $pods, |
|
815
|
|
|
'row' => $row, |
|
816
|
|
|
'total' => count( $pods ), |
|
817
|
|
|
'total_found' => count( $pods ), |
|
818
|
|
|
'items' => 'Pods', |
|
819
|
|
|
'item' => 'Pod', |
|
820
|
|
|
'fields' => array( |
|
821
|
|
|
'manage' => $fields |
|
822
|
|
|
), |
|
823
|
|
|
'actions_disabled' => array( 'view', 'export' ), |
|
824
|
|
|
'actions_custom' => array( |
|
825
|
|
|
'add' => array( $this, 'admin_setup_add' ), |
|
826
|
|
|
'edit' => array( $this, 'admin_setup_edit' ), |
|
827
|
|
|
'duplicate' => array( |
|
828
|
|
|
'callback' => array( $this, 'admin_setup_duplicate' ), |
|
829
|
|
|
'restrict_callback' => array( $this, 'admin_setup_duplicate_restrict' ) |
|
830
|
|
|
), |
|
831
|
|
|
'reset' => array( |
|
832
|
|
|
'label' => __( 'Delete All Items', 'pods' ), |
|
833
|
|
|
'confirm' => __( 'Are you sure you want to delete all items from this Pod? If this is an extended Pod, it will remove the original items extended too.', 'pods' ), |
|
834
|
|
|
'callback' => array( $this, 'admin_setup_reset' ), |
|
835
|
|
|
'restrict_callback' => array( $this, 'admin_setup_reset_restrict' ), |
|
836
|
|
|
'nonce' => true |
|
837
|
|
|
), |
|
838
|
|
|
'delete' => array( $this, 'admin_setup_delete' ) |
|
839
|
|
|
), |
|
840
|
|
|
'action_links' => array( |
|
841
|
|
|
'add' => pods_query_arg( array( 'page' => 'pods-add-new', 'action' => '', 'id' => '', 'do' => '' ) ) |
|
842
|
|
|
), |
|
843
|
|
|
'search' => false, |
|
844
|
|
|
'searchable' => false, |
|
845
|
|
|
'sortable' => true, |
|
846
|
|
|
'pagination' => false, |
|
847
|
|
|
'extra' => array( |
|
848
|
|
|
'total' => ', ' . number_format_i18n( $total_fields ) . ' ' . _n( 'field', 'fields', $total_fields, 'pods' ) |
|
849
|
|
|
) |
|
850
|
|
|
); |
|
851
|
|
|
|
|
852
|
|
|
if ( 1 < count( $pod_types_found ) ) { |
|
853
|
|
|
$ui[ 'views' ] = array( 'all' => __( 'All', 'pods' ) ); |
|
854
|
|
|
$ui[ 'view' ] = $view; |
|
855
|
|
|
$ui[ 'heading' ] = array( 'views' => __( 'Type', 'pods' ) ); |
|
856
|
|
|
$ui[ 'filters_enhanced' ] = true; |
|
857
|
|
|
|
|
858
|
|
|
foreach ( $pod_types_found as $pod_type => $number_found ) { |
|
859
|
|
|
$ui[ 'views' ][ $pod_type ] = $types[ $pod_type ]; |
|
860
|
|
|
} |
|
861
|
|
|
} |
|
862
|
|
|
|
|
863
|
|
|
pods_ui( $ui ); |
|
864
|
|
|
} |
|
865
|
|
|
|
|
866
|
|
|
/** |
|
867
|
|
|
* Get the add page of an object |
|
868
|
|
|
* |
|
869
|
|
|
* @param $obj |
|
870
|
|
|
*/ |
|
871
|
|
|
public function admin_setup_add ( $obj ) { |
|
872
|
|
|
pods_view( PODS_DIR . 'ui/admin/setup-add.php', compact( array_keys( get_defined_vars() ) ) ); |
|
873
|
|
|
} |
|
874
|
|
|
|
|
875
|
|
|
/** |
|
876
|
|
|
* Get the edit page of an object |
|
877
|
|
|
* |
|
878
|
|
|
* @param $duplicate |
|
879
|
|
|
* @param $obj |
|
880
|
|
|
*/ |
|
881
|
|
|
public function admin_setup_edit ( $duplicate, $obj ) { |
|
882
|
|
|
pods_view( PODS_DIR . 'ui/admin/setup-edit.php', compact( array_keys( get_defined_vars() ) ) ); |
|
883
|
|
|
} |
|
884
|
|
|
|
|
885
|
|
|
/** |
|
886
|
|
|
* Get list of Pod option tabs |
|
887
|
|
|
* |
|
888
|
|
|
* @return array |
|
889
|
|
|
*/ |
|
890
|
|
|
public function admin_setup_edit_tabs ( $pod ) { |
|
891
|
|
|
$fields = true; |
|
892
|
|
|
$labels = false; |
|
893
|
|
|
$admin_ui = false; |
|
894
|
|
|
$advanced = false; |
|
895
|
|
|
|
|
896
|
|
|
if ( 'post_type' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) { |
|
897
|
|
|
$labels = true; |
|
898
|
|
|
$admin_ui = true; |
|
899
|
|
|
$advanced = true; |
|
900
|
|
|
} |
|
901
|
|
|
elseif ( 'taxonomy' == pods_var( 'type', $pod ) && strlen( pods_var( 'object', $pod ) ) < 1 ) { |
|
902
|
|
|
$labels = true; |
|
903
|
|
|
$admin_ui = true; |
|
904
|
|
|
$advanced = true; |
|
905
|
|
|
} |
|
906
|
|
|
elseif ( 'pod' == pods_var( 'type', $pod ) ) { |
|
907
|
|
|
$labels = true; |
|
908
|
|
|
$admin_ui = true; |
|
909
|
|
|
$advanced = true; |
|
910
|
|
|
} |
|
911
|
|
|
elseif ( 'settings' == pods_var( 'type', $pod ) ) { |
|
912
|
|
|
$labels = true; |
|
913
|
|
|
$admin_ui = true; |
|
914
|
|
|
} |
|
915
|
|
|
|
|
916
|
|
|
if ( 'none' == pods_var( 'storage', $pod, 'none', null, true ) && 'settings' != pods_var( 'type', $pod ) ) |
|
917
|
|
|
$fields = false; |
|
918
|
|
|
|
|
919
|
|
|
$tabs = array(); |
|
920
|
|
|
|
|
921
|
|
|
if ( $fields ) |
|
922
|
|
|
$tabs[ 'manage-fields' ] = __( 'Manage Fields', 'pods' ); |
|
923
|
|
|
|
|
924
|
|
|
if ( $labels ) |
|
925
|
|
|
$tabs[ 'labels' ] = __( 'Labels', 'pods' ); |
|
926
|
|
|
|
|
927
|
|
|
if ( $admin_ui ) |
|
928
|
|
|
$tabs[ 'admin-ui' ] = __( 'Admin UI', 'pods' ); |
|
929
|
|
|
|
|
930
|
|
|
if ( $advanced ) |
|
931
|
|
|
$tabs[ 'advanced' ] = __( 'Advanced Options', 'pods' ); |
|
932
|
|
|
|
|
933
|
|
|
if ( 'taxonomy' == pods_var( 'type', $pod ) && !$fields ) |
|
934
|
|
|
$tabs[ 'extra-fields' ] = __( 'Extra Fields', 'pods' ); |
|
935
|
|
|
|
|
936
|
|
|
$addtl_args = compact( array( 'fields', 'labels', 'admin_ui', 'advanced' ) ); |
|
937
|
|
|
|
|
938
|
|
|
/** |
|
939
|
|
|
* Add or modify tabs in Pods editor for a specific Pod |
|
940
|
|
|
* |
|
941
|
|
|
* @params array $tabs Tabs to set. |
|
942
|
|
|
* @params object $pod Current Pods object |
|
943
|
|
|
* @params array $addtl_args Additional args. |
|
944
|
|
|
* |
|
945
|
|
|
* @since unknown |
|
946
|
|
|
*/ |
|
947
|
|
|
$tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $tabs, $pod, $addtl_args ); |
|
948
|
|
|
|
|
949
|
|
|
/** |
|
950
|
|
|
* Add or modify tabs for any Pod in Pods editor of a specific post type. |
|
951
|
|
|
*/ |
|
952
|
|
|
$tabs = apply_filters( 'pods_admin_setup_edit_tabs_' . $pod[ 'type' ], $tabs, $pod, $addtl_args ); |
|
953
|
|
|
|
|
954
|
|
|
/** |
|
955
|
|
|
* Add or modify tabs in Pods editor for all pods. |
|
956
|
|
|
*/ |
|
957
|
|
|
$tabs = apply_filters( 'pods_admin_setup_edit_tabs', $tabs, $pod, $addtl_args ); |
|
958
|
|
|
|
|
959
|
|
|
return $tabs; |
|
960
|
|
|
} |
|
961
|
|
|
|
|
962
|
|
|
/** |
|
963
|
|
|
* Get list of Pod options |
|
964
|
|
|
* |
|
965
|
|
|
* @return array |
|
966
|
|
|
*/ |
|
967
|
|
|
public function admin_setup_edit_options ( $pod ) { |
|
968
|
|
|
$options = array(); |
|
969
|
|
|
|
|
970
|
|
|
// @todo fill this in |
|
971
|
|
|
$options[ 'labels' ] = array( |
|
972
|
|
|
'temporary' => 'This has the fields hardcoded' // :( |
|
973
|
|
|
); |
|
974
|
|
|
|
|
975
|
|
|
if ( 'post_type' == $pod[ 'type' ] ) { |
|
976
|
|
|
$options[ 'admin-ui' ] = array( |
|
977
|
|
|
'description' => array( |
|
978
|
|
|
'label' => __( 'Post Type Description', 'pods' ), |
|
979
|
|
|
'help' => __( 'A short descriptive summary of what the post type is.', 'pods' ), |
|
980
|
|
|
'type' => 'text', |
|
981
|
|
|
'default' => '' |
|
982
|
|
|
), |
|
983
|
|
|
'show_ui' => array( |
|
984
|
|
|
'label' => __( 'Show Admin UI', 'pods' ), |
|
985
|
|
|
'help' => __( 'help', 'pods' ), |
|
986
|
|
|
'type' => 'boolean', |
|
987
|
|
|
'default' => pods_var_raw( 'public', $pod, true ), |
|
988
|
|
|
'boolean_yes_label' => '' |
|
989
|
|
|
), |
|
990
|
|
|
'show_in_menu' => array( |
|
991
|
|
|
'label' => __( 'Show Admin Menu in Dashboard', 'pods' ), |
|
992
|
|
|
'help' => __( 'help', 'pods' ), |
|
993
|
|
|
'type' => 'boolean', |
|
994
|
|
|
'default' => pods_var_raw( 'public', $pod, true ), |
|
995
|
|
|
'dependency' => true, |
|
996
|
|
|
'boolean_yes_label' => '' |
|
997
|
|
|
), |
|
998
|
|
|
'menu_location_custom' => array( |
|
999
|
|
|
'label' => __( 'Parent Menu ID (optional)', 'pods' ), |
|
1000
|
|
|
'help' => __( 'help', 'pods' ), |
|
1001
|
|
|
'type' => 'text', |
|
1002
|
|
|
'depends-on' => array( 'show_in_menu' => true ) |
|
1003
|
|
|
), |
|
1004
|
|
|
'menu_name' => array( |
|
1005
|
|
|
'label' => __( 'Menu Name', 'pods' ), |
|
1006
|
|
|
'help' => __( 'help', 'pods' ), |
|
1007
|
|
|
'type' => 'text', |
|
1008
|
|
|
'default' => '', |
|
1009
|
|
|
'depends-on' => array( 'show_in_menu' => true ) |
|
1010
|
|
|
), |
|
1011
|
|
|
'menu_position' => array( |
|
1012
|
|
|
'label' => __( 'Menu Position', 'pods' ), |
|
1013
|
|
|
'help' => __( 'help', 'pods' ), |
|
1014
|
|
|
'type' => 'number', |
|
1015
|
|
|
'default' => 0, |
|
1016
|
|
|
'depends-on' => array( 'show_in_menu' => true ) |
|
1017
|
|
|
), |
|
1018
|
|
|
'menu_icon' => array( |
|
1019
|
|
|
'label' => __( 'Menu Icon', 'pods' ), |
|
1020
|
|
|
'help' => __( 'URL or Dashicon name for the menu icon. You may specify the path to the icon using one of the <a href="http://pods.io/docs/build/special-magic-tags/#site-tags" target="_blank">site tag</a> type <a href="http://pods.io/docs/build/special-magic-tags/" target="_blank">special magic tags</a>. For example, for a file in your theme directory, use "{@template-url}/path/to/image.png". You may also use the name of a <a href="http://melchoyce.github.io/dashicons/" target="_blank">Dashicon</a>. For example, to use the empty star icon, use "dashicons-star-empty".', 'pods' ), |
|
1021
|
|
|
'type' => 'text', |
|
1022
|
|
|
'default' => '', |
|
1023
|
|
|
'depends-on' => array( 'show_in_menu' => true ) |
|
1024
|
|
|
), |
|
1025
|
|
|
'show_in_nav_menus' => array( |
|
1026
|
|
|
'label' => __( 'Show in Navigation Menus', 'pods' ), |
|
1027
|
|
|
'help' => __( 'help', 'pods' ), |
|
1028
|
|
|
'type' => 'boolean', |
|
1029
|
|
|
'default' => true, |
|
1030
|
|
|
'boolean_yes_label' => '' |
|
1031
|
|
|
), |
|
1032
|
|
|
'show_in_admin_bar' => array( |
|
1033
|
|
|
'label' => __( 'Show in Admin Bar "New" Menu', 'pods' ), |
|
1034
|
|
|
'help' => __( 'help', 'pods' ), |
|
1035
|
|
|
'type' => 'boolean', |
|
1036
|
|
|
'default' => true, |
|
1037
|
|
|
'boolean_yes_label' => '' |
|
1038
|
|
|
) |
|
1039
|
|
|
); |
|
1040
|
|
|
|
|
1041
|
|
|
$options[ 'advanced' ] = array( |
|
1042
|
|
|
'public' => array( |
|
1043
|
|
|
'label' => __( 'Public', 'pods' ), |
|
1044
|
|
|
'help' => __( 'help', 'pods' ), |
|
1045
|
|
|
'type' => 'boolean', |
|
1046
|
|
|
'default' => true, |
|
1047
|
|
|
'boolean_yes_label' => '' |
|
1048
|
|
|
), |
|
1049
|
|
|
'publicly_queryable' => array( |
|
1050
|
|
|
'label' => __( 'Publicly Queryable', 'pods' ), |
|
1051
|
|
|
'help' => __( 'help', 'pods' ), |
|
1052
|
|
|
'type' => 'boolean', |
|
1053
|
|
|
'default' => pods_var_raw( 'public', $pod, true ), |
|
1054
|
|
|
'boolean_yes_label' => '' |
|
1055
|
|
|
), |
|
1056
|
|
|
'exclude_from_search' => array( |
|
1057
|
|
|
'label' => __( 'Exclude from Search', 'pods' ), |
|
1058
|
|
|
'help' => __( 'help', 'pods' ), |
|
1059
|
|
|
'type' => 'boolean', |
|
1060
|
|
|
'default' => !pods_var_raw( 'public', $pod, true ), |
|
1061
|
|
|
'boolean_yes_label' => '' |
|
1062
|
|
|
), |
|
1063
|
|
|
'capability_type' => array( |
|
1064
|
|
|
'label' => __( 'User Capability', 'pods' ), |
|
1065
|
|
|
'help' => __( 'Uses these capabilties for access to this post type: edit_{capability}, read_{capability}, and delete_{capability}', 'pods' ), |
|
1066
|
|
|
'type' => 'pick', |
|
1067
|
|
|
'default' => 'post', |
|
1068
|
|
|
'data' => array( |
|
1069
|
|
|
'post' => 'post', |
|
1070
|
|
|
'page' => 'page', |
|
1071
|
|
|
'custom' => __( 'Custom Capability', 'pods' ) |
|
1072
|
|
|
), |
|
1073
|
|
|
'dependency' => true |
|
1074
|
|
|
), |
|
1075
|
|
|
'capability_type_custom' => array( |
|
1076
|
|
|
'label' => __( 'Custom User Capability', 'pods' ), |
|
1077
|
|
|
'help' => __( 'help', 'pods' ), |
|
1078
|
|
|
'type' => 'text', |
|
1079
|
|
|
'default' => pods_var_raw( 'name', $pod ), |
|
1080
|
|
|
'depends-on' => array( 'capability_type' => 'custom' ) |
|
1081
|
|
|
), |
|
1082
|
|
|
'capability_type_extra' => array( |
|
1083
|
|
|
'label' => __( 'Additional User Capabilities', 'pods' ), |
|
1084
|
|
|
'help' => __( 'Enables additional capabilities for this Post Type including: delete_{capability}s, delete_private_{capability}s, delete_published_{capability}s, delete_others_{capability}s, edit_private_{capability}s, and edit_published_{capability}s', 'pods' ), |
|
1085
|
|
|
'type' => 'boolean', |
|
1086
|
|
|
'default' => true, |
|
1087
|
|
|
'boolean_yes_label' => '' |
|
1088
|
|
|
), |
|
1089
|
|
|
'has_archive' => array( |
|
1090
|
|
|
'label' => __( 'Enable Archive Page', 'pods' ), |
|
1091
|
|
|
'help' => __( 'If enabled, creates an archive page with list of of items in this custom post type. Functions like a category page for posts. Can be controlled with a template in your theme called "archive-{$post-type}.php".', 'pods' ), |
|
1092
|
|
|
'type' => 'boolean', |
|
1093
|
|
|
'default' => false, |
|
1094
|
|
|
'dependency' => true, |
|
1095
|
|
|
'boolean_yes_label' => '' |
|
1096
|
|
|
), |
|
1097
|
|
|
'has_archive_slug' => array( |
|
1098
|
|
|
'label' => __( 'Archive Page Slug Override', 'pods' ), |
|
1099
|
|
|
'help' => __( 'If archive page is enabled, you can override the slug used by WordPress, which defaults to the name of the post type.', 'pods' ), |
|
1100
|
|
|
'type' => 'text', |
|
1101
|
|
|
'default' => '', |
|
1102
|
|
|
'depends-on' => array( 'has_archive' => true ) |
|
1103
|
|
|
), |
|
1104
|
|
|
'hierarchical' => array( |
|
1105
|
|
|
'label' => __( 'Hierarchical', 'pods' ), |
|
1106
|
|
|
'help' => __( 'Allows for parent/ child relationships between items, just like with Pages. Note: To edit relationships in the post editor, you must enable "Page Attributes" in the "Supports" section below.', 'pods' ), |
|
1107
|
|
|
'type' => 'boolean', |
|
1108
|
|
|
'default' => false, |
|
1109
|
|
|
'dependency' => true, |
|
1110
|
|
|
'boolean_yes_label' => '' |
|
1111
|
|
|
), |
|
1112
|
|
|
'label_parent_item_colon' => array( |
|
1113
|
|
|
'label' => __( '<strong>Label: </strong> Parent <span class="pods-slugged" data-sluggable="label_singular">Item</span>', 'pods' ), |
|
1114
|
|
|
'help' => __( 'help', 'pods' ), |
|
1115
|
|
|
'type' => 'text', |
|
1116
|
|
|
'default' => '', |
|
1117
|
|
|
'depends-on' => array( 'hierarchical' => true ) |
|
1118
|
|
|
), |
|
1119
|
|
|
'label_parent' => array( |
|
1120
|
|
|
'label' => __( '<strong>Label: </strong> Parent', 'pods' ), |
|
1121
|
|
|
'help' => __( 'help', 'pods' ), |
|
1122
|
|
|
'type' => 'text', |
|
1123
|
|
|
'default' => '', |
|
1124
|
|
|
'depends-on' => array( 'hierarchical' => true ) |
|
1125
|
|
|
), |
|
1126
|
|
|
'rewrite' => array( |
|
1127
|
|
|
'label' => __( 'Rewrite', 'pods' ), |
|
1128
|
|
|
'help' => __( 'Allows you to use pretty permalinks, if set in WordPress Settings->Reading. If not enbabled, your links will be in the form of "example.com/?pod_name=post_slug" regardless of your permalink settings.', 'pods' ), |
|
1129
|
|
|
'type' => 'boolean', |
|
1130
|
|
|
'default' => true, |
|
1131
|
|
|
'dependency' => true, |
|
1132
|
|
|
'boolean_yes_label' => '' |
|
1133
|
|
|
), |
|
1134
|
|
|
'rewrite_custom_slug' => array( |
|
1135
|
|
|
'label' => __( 'Custom Rewrite Slug', 'pods' ), |
|
1136
|
|
|
'help' => __( 'Changes the first segment of the URL, which by default is the name of the Pod. For example, if your Pod is called "foo", if this field is left blank, your link will be "example.com/foo/post_slug", but if you were to enter "bar" your link will be "example.com/bar/post_slug".', 'pods' ), |
|
1137
|
|
|
'type' => 'text', |
|
1138
|
|
|
'default' => '', |
|
1139
|
|
|
'depends-on' => array( 'rewrite' => true ) |
|
1140
|
|
|
), |
|
1141
|
|
|
'rewrite_with_front' => array( |
|
1142
|
|
|
'label' => __( 'Rewrite with Front', 'pods' ), |
|
1143
|
|
|
'help' => __( 'Allows permalinks to be prepended with your front base (example: if your permalink structure is /blog/, then your links will be: Unchecked->/news/, Checked->/blog/news/)', 'pods' ), |
|
1144
|
|
|
'type' => 'boolean', |
|
1145
|
|
|
'default' => true, |
|
1146
|
|
|
'depends-on' => array( 'rewrite' => true ), |
|
1147
|
|
|
'boolean_yes_label' => '' |
|
1148
|
|
|
), |
|
1149
|
|
|
'rewrite_feeds' => array( |
|
1150
|
|
|
'label' => __( 'Rewrite Feeds', 'pods' ), |
|
1151
|
|
|
'help' => __( 'help', 'pods' ), |
|
1152
|
|
|
'type' => 'boolean', |
|
1153
|
|
|
'default' => false, |
|
1154
|
|
|
'depends-on' => array( 'rewrite' => true ), |
|
1155
|
|
|
'boolean_yes_label' => '' |
|
1156
|
|
|
), |
|
1157
|
|
|
'rewrite_pages' => array( |
|
1158
|
|
|
'label' => __( 'Rewrite Pages', 'pods' ), |
|
1159
|
|
|
'help' => __( 'help', 'pods' ), |
|
1160
|
|
|
'type' => 'boolean', |
|
1161
|
|
|
'default' => true, |
|
1162
|
|
|
'depends-on' => array( 'rewrite' => true ), |
|
1163
|
|
|
'boolean_yes_label' => '' |
|
1164
|
|
|
), |
|
1165
|
|
|
'query_var' => array( |
|
1166
|
|
|
'label' => __( 'Query Var', 'pods' ), |
|
1167
|
|
|
'help' => __( 'The Query Var is used in the URL and underneath the WordPress Rewrite API to tell WordPress what page or post type you are on. For a list of reserved Query Vars, read <a href="http://codex.wordpress.org/WordPress_Query_Vars">WordPress Query Vars</a> from the WordPress Codex.', 'pods' ), |
|
1168
|
|
|
'type' => 'boolean', |
|
1169
|
|
|
'default' => true, |
|
1170
|
|
|
'boolean_yes_label' => '' |
|
1171
|
|
|
), |
|
1172
|
|
|
'can_export' => array( |
|
1173
|
|
|
'label' => __( 'Exportable', 'pods' ), |
|
1174
|
|
|
'help' => __( 'help', 'pods' ), |
|
1175
|
|
|
'type' => 'boolean', |
|
1176
|
|
|
'default' => true, |
|
1177
|
|
|
'boolean_yes_label' => '' |
|
1178
|
|
|
), |
|
1179
|
|
|
'default_status' => array( |
|
1180
|
|
|
'label' => __( 'Default Status', 'pods' ), |
|
1181
|
|
|
'help' => __( 'help', 'pods' ), |
|
1182
|
|
|
'type' => 'pick', |
|
1183
|
|
|
'pick_object' => 'post-status', |
|
1184
|
|
|
'default' => apply_filters( 'pods_api_default_status_' . pods_var_raw( 'name', $pod, 'post_type', null, true ), 'draft', $pod ) |
|
1185
|
|
|
) |
|
1186
|
|
|
); |
|
1187
|
|
|
} |
|
1188
|
|
|
elseif ( 'taxonomy' == $pod[ 'type' ] ) { |
|
1189
|
|
|
$options[ 'admin-ui' ] = array( |
|
1190
|
|
|
'show_ui' => array( |
|
1191
|
|
|
'label' => __( 'Show Admin UI', 'pods' ), |
|
1192
|
|
|
'help' => __( 'help', 'pods' ), |
|
1193
|
|
|
'type' => 'boolean', |
|
1194
|
|
|
'default' => pods_var_raw( 'public', $pod, true ), |
|
1195
|
|
|
'dependency' => true, |
|
1196
|
|
|
'boolean_yes_label' => '' |
|
1197
|
|
|
), |
|
1198
|
|
|
'menu_name' => array( |
|
1199
|
|
|
'label' => __( 'Menu Name', 'pods' ), |
|
1200
|
|
|
'help' => __( 'help', 'pods' ), |
|
1201
|
|
|
'type' => 'text', |
|
1202
|
|
|
'default' => '', |
|
1203
|
|
|
'depends-on' => array( 'show_ui' => true ) |
|
1204
|
|
|
), |
|
1205
|
|
|
'menu_location' => array( |
|
1206
|
|
|
'label' => __( 'Menu Location', 'pods' ), |
|
1207
|
|
|
'help' => __( 'help', 'pods' ), |
|
1208
|
|
|
'type' => 'pick', |
|
1209
|
|
|
'default' => 'default', |
|
1210
|
|
|
'depends-on' => array( 'show_ui' => true ), |
|
1211
|
|
|
'data' => array( |
|
1212
|
|
|
'default' => __( 'Default - Add to associated Post Type(s) menus', 'pods' ), |
|
1213
|
|
|
'settings' => __( 'Add to Settings menu', 'pods' ), |
|
1214
|
|
|
'appearances' => __( 'Add to Appearances menu', 'pods' ), |
|
1215
|
|
|
'objects' => __( 'Make a top-level menu item', 'pods' ), |
|
1216
|
|
|
'top' => __( 'Make a new top-level menu item below Settings', 'pods' ), |
|
1217
|
|
|
'submenu' => __( 'Add a submenu item to another menu', 'pods' ) |
|
1218
|
|
|
), |
|
1219
|
|
|
'dependency' => true |
|
1220
|
|
|
), |
|
1221
|
|
|
'menu_location_custom' => array( |
|
1222
|
|
|
'label' => __( 'Custom Menu Location', 'pods' ), |
|
1223
|
|
|
'help' => __( 'help', 'pods' ), |
|
1224
|
|
|
'type' => 'text', |
|
1225
|
|
|
'depends-on' => array( 'menu_location' => 'submenu' ) |
|
1226
|
|
|
), |
|
1227
|
|
|
'menu_position' => array( |
|
1228
|
|
|
'label' => __( 'Menu Position', 'pods' ), |
|
1229
|
|
|
'help' => __( 'help', 'pods' ), |
|
1230
|
|
|
'type' => 'number', |
|
1231
|
|
|
'default' => 0, |
|
1232
|
|
|
'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ) |
|
1233
|
|
|
), |
|
1234
|
|
|
'menu_icon' => array( |
|
1235
|
|
|
'label' => __( 'Menu Icon URL', 'pods' ), |
|
1236
|
|
|
'help' => __( 'help', 'pods' ), |
|
1237
|
|
|
'type' => 'text', |
|
1238
|
|
|
'default' => '', |
|
1239
|
|
|
'depends-on' => array( 'menu_location' => array( 'objects', 'top' ) ) |
|
1240
|
|
|
), |
|
1241
|
|
|
'show_in_nav_menus' => array( |
|
1242
|
|
|
'label' => __( 'Show in Navigation Menus', 'pods' ), |
|
1243
|
|
|
'help' => __( 'help', 'pods' ), |
|
1244
|
|
|
'type' => 'boolean', |
|
1245
|
|
|
'default' => pods_var_raw( 'public', $pod, true ), |
|
1246
|
|
|
'boolean_yes_label' => '' |
|
1247
|
|
|
), |
|
1248
|
|
|
'show_tagcloud' => array( |
|
1249
|
|
|
'label' => __( 'Allow in Tagcloud Widget', 'pods' ), |
|
1250
|
|
|
'help' => __( 'help', 'pods' ), |
|
1251
|
|
|
'type' => 'boolean', |
|
1252
|
|
|
'default' => pods_var_raw( 'show_ui', $pod, pods_var_raw( 'public', $pod, true ) ), |
|
1253
|
|
|
'boolean_yes_label' => '' |
|
1254
|
|
|
) |
|
1255
|
|
|
); |
|
1256
|
|
|
|
|
1257
|
|
|
if ( pods_version_check( 'wp', '3.5' ) ) { |
|
1258
|
|
|
$options[ 'admin-ui' ][ 'show_admin_column' ] = array( |
|
1259
|
|
|
'label' => __( 'Show Taxonomy column on Post Types', 'pods' ), |
|
1260
|
|
|
'help' => __( 'Whether to add a column for this taxonomy on the associated post types manage screens', 'pods' ), |
|
1261
|
|
|
'type' => 'boolean', |
|
1262
|
|
|
'default' => false, |
|
1263
|
|
|
'boolean_yes_label' => '' |
|
1264
|
|
|
); |
|
1265
|
|
|
} |
|
1266
|
|
|
|
|
1267
|
|
|
// Integration for Single Value Taxonomy UI |
|
1268
|
|
|
if ( function_exists( 'tax_single_value_meta_box' ) ) { |
|
1269
|
|
|
$options[ 'admin-ui' ][ 'single_value' ] = array( |
|
1270
|
|
|
'label' => __( 'Single Value Taxonomy', 'pods' ), |
|
1271
|
|
|
'help' => __( 'Use a drop-down for the input instead of the WordPress default', 'pods' ), |
|
1272
|
|
|
'type' => 'boolean', |
|
1273
|
|
|
'default' => false, |
|
1274
|
|
|
'boolean_yes_label' => '' |
|
1275
|
|
|
); |
|
1276
|
|
|
|
|
1277
|
|
|
$options[ 'admin-ui' ][ 'single_value_required' ] = array( |
|
1278
|
|
|
'label' => __( 'Single Value Taxonomy - Required', 'pods' ), |
|
1279
|
|
|
'help' => __( 'A term will be selected by default in the Post Editor, not optional', 'pods' ), |
|
1280
|
|
|
'type' => 'boolean', |
|
1281
|
|
|
'default' => false, |
|
1282
|
|
|
'boolean_yes_label' => '' |
|
1283
|
|
|
); |
|
1284
|
|
|
} |
|
1285
|
|
|
|
|
1286
|
|
|
// @todo fill this in |
|
1287
|
|
|
$options[ 'advanced' ] = array( |
|
1288
|
|
|
'temporary' => 'This type has the fields hardcoded' // :( |
|
1289
|
|
|
); |
|
1290
|
|
|
} |
|
1291
|
|
|
elseif ( 'settings' == $pod[ 'type' ] ) { |
|
1292
|
|
|
$options[ 'admin-ui' ] = array( |
|
1293
|
|
|
'ui_style' => array( |
|
1294
|
|
|
'label' => __( 'Admin UI Style', 'pods' ), |
|
1295
|
|
|
'help' => __( 'help', 'pods' ), |
|
1296
|
|
|
'type' => 'pick', |
|
1297
|
|
|
'default' => 'settings', |
|
1298
|
|
|
'data' => array( |
|
1299
|
|
|
'settings' => __( 'Normal Settings Form', 'pods' ), |
|
1300
|
|
|
'post_type' => __( 'Post Type UI', 'pods' ), |
|
1301
|
|
|
'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ) |
|
1302
|
|
|
), |
|
1303
|
|
|
'dependency' => true |
|
1304
|
|
|
), |
|
1305
|
|
|
'menu_location' => array( |
|
1306
|
|
|
'label' => __( 'Menu Location', 'pods' ), |
|
1307
|
|
|
'help' => __( 'help', 'pods' ), |
|
1308
|
|
|
'type' => 'pick', |
|
1309
|
|
|
'default' => 'settings', |
|
1310
|
|
|
'data' => array( |
|
1311
|
|
|
'settings' => __( 'Add to Settings menu', 'pods' ), |
|
1312
|
|
|
'appearances' => __( 'Add to Appearances menu', 'pods' ), |
|
1313
|
|
|
'top' => __( 'Make a new top-level menu item below Settings', 'pods' ), |
|
1314
|
|
|
'submenu' => __( 'Add a submenu item to another menu', 'pods' ) |
|
1315
|
|
|
), |
|
1316
|
|
|
'dependency' => true |
|
1317
|
|
|
), |
|
1318
|
|
|
'menu_location_custom' => array( |
|
1319
|
|
|
'label' => __( 'Custom Menu Location', 'pods' ), |
|
1320
|
|
|
'help' => __( 'help', 'pods' ), |
|
1321
|
|
|
'type' => 'text', |
|
1322
|
|
|
'depends-on' => array( 'menu_location' => 'submenu' ) |
|
1323
|
|
|
), |
|
1324
|
|
|
'menu_position' => array( |
|
1325
|
|
|
'label' => __( 'Menu Position', 'pods' ), |
|
1326
|
|
|
'help' => __( 'help', 'pods' ), |
|
1327
|
|
|
'type' => 'number', |
|
1328
|
|
|
'default' => 0, |
|
1329
|
|
|
'depends-on' => array( 'menu_location' => 'top' ) |
|
1330
|
|
|
), |
|
1331
|
|
|
'menu_icon' => array( |
|
1332
|
|
|
'label' => __( 'Menu Icon URL', 'pods' ), |
|
1333
|
|
|
'help' => __( 'help', 'pods' ), |
|
1334
|
|
|
'type' => 'text', |
|
1335
|
|
|
'default' => '', |
|
1336
|
|
|
'depends-on' => array( 'menu_location' => 'top' ) |
|
1337
|
|
|
) |
|
1338
|
|
|
); |
|
1339
|
|
|
|
|
1340
|
|
|
// @todo fill this in |
|
1341
|
|
|
$options[ 'advanced' ] = array( |
|
1342
|
|
|
'temporary' => 'This type has the fields hardcoded' // :( |
|
1343
|
|
|
); |
|
1344
|
|
|
} |
|
1345
|
|
|
elseif ( 'pod' == $pod[ 'type' ] ) { |
|
1346
|
|
|
$options[ 'admin-ui' ] = array( |
|
1347
|
|
|
'ui_style' => array( |
|
1348
|
|
|
'label' => __( 'Admin UI Style', 'pods' ), |
|
1349
|
|
|
'help' => __( 'help', 'pods' ), |
|
1350
|
|
|
'type' => 'pick', |
|
1351
|
|
|
'default' => 'settings', |
|
1352
|
|
|
'data' => array( |
|
1353
|
|
|
'post_type' => __( 'Normal (Looks like the Post Type UI)', 'pods' ), |
|
1354
|
|
|
'custom' => __( 'Custom (hook into pods_admin_ui_custom or pods_admin_ui_custom_{podname} action)', 'pods' ) |
|
1355
|
|
|
), |
|
1356
|
|
|
'dependency' => true |
|
1357
|
|
|
), |
|
1358
|
|
|
'show_in_menu' => array( |
|
1359
|
|
|
'label' => __( 'Show Admin Menu in Dashboard', 'pods' ), |
|
1360
|
|
|
'help' => __( 'help', 'pods' ), |
|
1361
|
|
|
'type' => 'boolean', |
|
1362
|
|
|
'default' => false, |
|
1363
|
|
|
'boolean_yes_label' => '', |
|
1364
|
|
|
'dependency' => true |
|
1365
|
|
|
), |
|
1366
|
|
|
'menu_location_custom' => array( |
|
1367
|
|
|
'label' => __( 'Parent Menu ID (optional)', 'pods' ), |
|
1368
|
|
|
'help' => __( 'help', 'pods' ), |
|
1369
|
|
|
'type' => 'text', |
|
1370
|
|
|
'depends-on' => array( 'show_in_menu' => true ) |
|
1371
|
|
|
), |
|
1372
|
|
|
'menu_position' => array( |
|
1373
|
|
|
'label' => __( 'Menu Position', 'pods' ), |
|
1374
|
|
|
'help' => __( 'help', 'pods' ), |
|
1375
|
|
|
'type' => 'number', |
|
1376
|
|
|
'default' => 0, |
|
1377
|
|
|
'depends-on' => array( 'show_in_menu' => true ) |
|
1378
|
|
|
), |
|
1379
|
|
|
'menu_icon' => array( |
|
1380
|
|
|
'label' => __( 'Menu Icon URL', 'pods' ), |
|
1381
|
|
|
'help' => __( 'This is the icon shown to the left of the menu text for this content type.', 'pods' ), |
|
1382
|
|
|
'type' => 'text', |
|
1383
|
|
|
'default' => '', |
|
1384
|
|
|
'depends-on' => array( 'show_in_menu' => true ) |
|
1385
|
|
|
), |
|
1386
|
|
|
'ui_icon' => array( |
|
1387
|
|
|
'label' => __( 'Header Icon', 'pods' ), |
|
1388
|
|
|
'help' => __( 'This is the icon shown to the left of the heading text at the top of the manage pages for this content type.', 'pods' ), |
|
1389
|
|
|
'type' => 'file', |
|
1390
|
|
|
'default' => '', |
|
1391
|
|
|
'file_edit_title' => 0, |
|
1392
|
|
|
'depends-on' => array( 'show_in_menu' => true ) |
|
1393
|
|
|
), |
|
1394
|
|
|
'ui_actions_enabled' => array( |
|
1395
|
|
|
'label' => __( 'Actions Available', 'pods' ), |
|
1396
|
|
|
'help' => __( 'help', 'pods' ), |
|
1397
|
|
|
'type' => 'pick', |
|
1398
|
|
|
'default' => ( 1 == pods_var( 'ui_export', $pod ) ? array( 'add', 'edit', 'duplicate', 'delete', 'export' ) : array( 'add', 'edit', 'duplicate', 'delete' ) ), |
|
1399
|
|
|
'data' => array( |
|
1400
|
|
|
'add' => __( 'Add New', 'pods' ), |
|
1401
|
|
|
'edit' => __( 'Edit', 'pods' ), |
|
1402
|
|
|
'duplicate' => __( 'Duplicate', 'pods' ), |
|
1403
|
|
|
'delete' => __( 'Delete', 'pods' ), |
|
1404
|
|
|
'reorder' => __( 'Reorder', 'pods' ), |
|
1405
|
|
|
'export' => __( 'Export', 'pods' ) |
|
1406
|
|
|
), |
|
1407
|
|
|
'pick_format_type' => 'multi', |
|
1408
|
|
|
'dependency' => true |
|
1409
|
|
|
), |
|
1410
|
|
|
'ui_reorder_field' => array( |
|
1411
|
|
|
'label' => __( 'Reorder Field', 'pods' ), |
|
1412
|
|
|
'help' => __( 'This is the field that will be reordered on, it should be numeric.', 'pods' ), |
|
1413
|
|
|
'type' => 'text', |
|
1414
|
|
|
'default' => 'menu_order', |
|
1415
|
|
|
'depends-on' => array( 'ui_actions_enabled' => 'reorder' ) |
|
1416
|
|
|
), |
|
1417
|
|
|
'ui_fields_manage' => array( |
|
1418
|
|
|
'label' => __( 'Admin Table Columns', 'pods' ), |
|
1419
|
|
|
'help' => __( 'help', 'pods' ), |
|
1420
|
|
|
'type' => 'pick', |
|
1421
|
|
|
'default' => array(), |
|
1422
|
|
|
'data' => array(), |
|
1423
|
|
|
'pick_format_type' => 'multi' |
|
1424
|
|
|
), |
|
1425
|
|
|
'ui_filters' => array( |
|
1426
|
|
|
'label' => __( 'Search Filters', 'pods' ), |
|
1427
|
|
|
'help' => __( 'help', 'pods' ), |
|
1428
|
|
|
'type' => 'pick', |
|
1429
|
|
|
'default' => array(), |
|
1430
|
|
|
'data' => array(), |
|
1431
|
|
|
'pick_format_type' => 'multi' |
|
1432
|
|
|
) |
|
1433
|
|
|
); |
|
1434
|
|
|
|
|
1435
|
|
|
if ( !empty( $pod[ 'fields' ] ) ) { |
|
1436
|
|
|
if ( isset( $pod[ 'fields' ][ pods_var_raw( 'pod_index', $pod, 'name' ) ] ) ) |
|
1437
|
|
|
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = pods_var_raw( 'pod_index', $pod, 'name' ); |
|
1438
|
|
|
|
|
1439
|
|
|
if ( isset( $pod[ 'fields' ][ 'modified' ] ) ) |
|
1440
|
|
|
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'default' ][] = 'modified'; |
|
1441
|
|
|
|
|
1442
|
|
|
foreach ( $pod[ 'fields' ] as $field ) { |
|
1443
|
|
|
$type = ''; |
|
1444
|
|
|
|
|
1445
|
|
|
if ( isset( $field_types[ $field[ 'type' ] ] ) ) |
|
1446
|
|
|
$type = ' <small>(' . $field_types[ $field[ 'type' ] ][ 'label' ] . ')</small>'; |
|
1447
|
|
|
|
|
1448
|
|
|
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type; |
|
1449
|
|
|
$options[ 'admin-ui' ][ 'ui_filters' ][ 'data' ][ $field[ 'name' ] ] = $field[ 'label' ] . $type; |
|
1450
|
|
|
} |
|
1451
|
|
|
|
|
1452
|
|
|
$options[ 'admin-ui' ][ 'ui_fields_manage' ][ 'data' ][ 'id' ] = 'ID'; |
|
1453
|
|
|
} |
|
1454
|
|
|
else { |
|
1455
|
|
|
unset( $options[ 'admin-ui' ][ 'ui_fields_manage' ] ); |
|
1456
|
|
|
unset( $options[ 'admin-ui' ][ 'ui_filters' ] ); |
|
1457
|
|
|
} |
|
1458
|
|
|
|
|
1459
|
|
|
// @todo fill this in |
|
1460
|
|
|
$options[ 'advanced' ] = array( |
|
1461
|
|
|
'temporary' => 'This type has the fields hardcoded' // :( |
|
1462
|
|
|
); |
|
1463
|
|
|
} |
|
1464
|
|
|
|
|
1465
|
|
|
/** |
|
1466
|
|
|
* Add admin fields to the Pods editor for a specific Pod |
|
1467
|
|
|
* |
|
1468
|
|
|
* @params array $options The Options fields |
|
1469
|
|
|
* @params object $pod Current Pods object |
|
1470
|
|
|
* |
|
1471
|
|
|
* @since unkown |
|
1472
|
|
|
*/ |
|
1473
|
|
|
$options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ] . '_' . $pod[ 'name' ], $options, $pod ); |
|
1474
|
|
|
|
|
1475
|
|
|
/** |
|
1476
|
|
|
* Add admin fields to the Pods editor for any Pod of a specific content type. |
|
1477
|
|
|
*/ |
|
1478
|
|
|
$options = apply_filters( 'pods_admin_setup_edit_options_' . $pod[ 'type' ], $options, $pod ); |
|
1479
|
|
|
|
|
1480
|
|
|
/** |
|
1481
|
|
|
* Add admin fields to the Pods editor for all Pods |
|
1482
|
|
|
*/ |
|
1483
|
|
|
$options = apply_filters( 'pods_admin_setup_edit_options', $options, $pod ); |
|
1484
|
|
|
|
|
1485
|
|
|
return $options; |
|
1486
|
|
|
} |
|
1487
|
|
|
|
|
1488
|
|
|
/** |
|
1489
|
|
|
* Get list of Pod field option tabs |
|
1490
|
|
|
* |
|
1491
|
|
|
* @return array |
|
1492
|
|
|
*/ |
|
1493
|
|
|
public function admin_setup_edit_field_tabs ( $pod ) { |
|
1494
|
|
|
$core_tabs = array( |
|
1495
|
|
|
'basic' => __( 'Basic', 'pods' ), |
|
1496
|
|
|
'additional-field' => __( 'Additional Field Options', 'pods' ), |
|
1497
|
|
|
'advanced' => __( 'Advanced', 'pods' ) |
|
1498
|
|
|
); |
|
1499
|
|
|
|
|
1500
|
|
|
/** |
|
1501
|
|
|
* Field option tabs |
|
1502
|
|
|
* |
|
1503
|
|
|
* Use to add new tabs, default tabs are added after this filter (IE you can't remove/modify them with this, kthanksbye). |
|
1504
|
|
|
* |
|
1505
|
|
|
* @since unknown |
|
1506
|
|
|
* |
|
1507
|
|
|
* @param array $tabs Tabs to add, starts empty |
|
1508
|
|
|
* @param object|Pod Current Pods object |
|
1509
|
|
|
*/ |
|
1510
|
|
|
$tabs = apply_filters( 'pods_admin_setup_edit_field_tabs', array(), $pod ); |
|
1511
|
|
|
|
|
1512
|
|
|
$tabs = array_merge( $core_tabs, $tabs ); |
|
1513
|
|
|
|
|
1514
|
|
|
return $tabs; |
|
1515
|
|
|
} |
|
1516
|
|
|
|
|
1517
|
|
|
/** |
|
1518
|
|
|
* Get list of Pod field options |
|
1519
|
|
|
* |
|
1520
|
|
|
* @return array |
|
1521
|
|
|
*/ |
|
1522
|
|
|
public function admin_setup_edit_field_options ( $pod ) { |
|
1523
|
|
|
$options = array(); |
|
1524
|
|
|
|
|
1525
|
|
|
$options[ 'additional-field' ] = array(); |
|
1526
|
|
|
|
|
1527
|
|
|
$field_types = PodsForm::field_types(); |
|
1528
|
|
|
|
|
1529
|
|
|
foreach ( $field_types as $type => $field_type_data ) { |
|
1530
|
|
|
/** |
|
1531
|
|
|
* @var $field_type PodsField |
|
1532
|
|
|
*/ |
|
1533
|
|
|
$field_type = PodsForm::field_loader( $type, $field_type_data[ 'file' ] ); |
|
1534
|
|
|
|
|
1535
|
|
|
$field_type_vars = get_class_vars( get_class( $field_type ) ); |
|
1536
|
|
|
|
|
1537
|
|
|
if ( !isset( $field_type_vars[ 'pod_types' ] ) ) |
|
1538
|
|
|
$field_type_vars[ 'pod_types' ] = true; |
|
1539
|
|
|
|
|
1540
|
|
|
$options[ 'additional-field' ][ $type ] = array(); |
|
1541
|
|
|
|
|
1542
|
|
|
// Only show supported field types |
|
1543
|
|
View Code Duplication |
if ( true !== $field_type_vars[ 'pod_types' ] ) { |
|
1544
|
|
|
if ( empty( $field_type_vars[ 'pod_types' ] ) ) |
|
1545
|
|
|
continue; |
|
1546
|
|
|
elseif ( is_array( $field_type_vars[ 'pod_types' ] ) && !in_array( pods_var( 'type', $pod ), $field_type_vars[ 'pod_types' ] ) ) |
|
1547
|
|
|
continue; |
|
1548
|
|
|
elseif ( !is_array( $field_type_vars[ 'pod_types' ] ) && pods_var( 'type', $pod ) != $field_type_vars[ 'pod_types' ] ) |
|
1549
|
|
|
continue; |
|
1550
|
|
|
} |
|
1551
|
|
|
|
|
1552
|
|
|
$options[ 'additional-field' ][ $type ] = PodsForm::ui_options( $type ); |
|
1553
|
|
|
} |
|
1554
|
|
|
|
|
1555
|
|
|
$input_helpers = array( |
|
1556
|
|
|
'' => '-- Select --' |
|
1557
|
|
|
); |
|
1558
|
|
|
|
|
1559
|
|
|
if ( class_exists( 'Pods_Helpers' ) ) { |
|
1560
|
|
|
$helpers = pods_api()->load_helpers( array( 'options' => array( 'helper_type' => 'input' ) ) ); |
|
1561
|
|
|
|
|
1562
|
|
|
foreach ( $helpers as $helper ) { |
|
1563
|
|
|
$input_helpers[ $helper[ 'name' ] ] = $helper[ 'name' ]; |
|
1564
|
|
|
} |
|
1565
|
|
|
} |
|
1566
|
|
|
|
|
1567
|
|
|
$options[ 'advanced' ] = array( |
|
1568
|
|
|
__( 'Visual', 'pods' ) => array( |
|
1569
|
|
|
'class' => array( |
|
1570
|
|
|
'name' => 'class', |
|
1571
|
|
|
'label' => __( 'Additional CSS Classes', 'pods' ), |
|
1572
|
|
|
'help' => __( 'help', 'pods' ), |
|
1573
|
|
|
'type' => 'text', |
|
1574
|
|
|
'default' => '' |
|
1575
|
|
|
), |
|
1576
|
|
|
'input_helper' => array( |
|
1577
|
|
|
'name' => 'input_helper', |
|
1578
|
|
|
'label' => __( 'Input Helper', 'pods' ), |
|
1579
|
|
|
'help' => __( 'help', 'pods' ), |
|
1580
|
|
|
'type' => 'pick', |
|
1581
|
|
|
'default' => '', |
|
1582
|
|
|
'data' => $input_helpers |
|
1583
|
|
|
) |
|
1584
|
|
|
), |
|
1585
|
|
|
__( 'Values', 'pods' ) => array( |
|
1586
|
|
|
'default_value' => array( |
|
1587
|
|
|
'name' => 'default_value', |
|
1588
|
|
|
'label' => __( 'Default Value', 'pods' ), |
|
1589
|
|
|
'help' => __( 'help', 'pods' ), |
|
1590
|
|
|
'type' => 'text', |
|
1591
|
|
|
'default' => '' |
|
1592
|
|
|
), |
|
1593
|
|
|
'default_value_parameter' => array( |
|
1594
|
|
|
'name' => 'default_value_parameter', |
|
1595
|
|
|
'label' => __( 'Set Default Value via Parameter', 'pods' ), |
|
1596
|
|
|
'help' => __( 'help', 'pods' ), |
|
1597
|
|
|
'type' => 'text', |
|
1598
|
|
|
'default' => '' |
|
1599
|
|
|
) |
|
1600
|
|
|
), |
|
1601
|
|
|
__( 'Visibility', 'pods' ) => array( |
|
1602
|
|
|
'restrict_access' => array( |
|
1603
|
|
|
'name' => 'restrict_access', |
|
1604
|
|
|
'label' => __( 'Restrict Access', 'pods' ), |
|
1605
|
|
|
'group' => array( |
|
1606
|
|
|
'admin_only' => array( |
|
1607
|
|
|
'name' => 'admin_only', |
|
1608
|
|
|
'label' => __( 'Restrict access to Admins?', 'pods' ), |
|
1609
|
|
|
'default' => 0, |
|
1610
|
|
|
'type' => 'boolean', |
|
1611
|
|
|
'dependency' => true, |
|
1612
|
|
|
'help' => __( 'This field will only be able to be edited by users with the ability to manage_options or delete_users, or super admins of a WordPress Multisite network', 'pods' ) |
|
1613
|
|
|
), |
|
1614
|
|
|
'restrict_role' => array( |
|
1615
|
|
|
'name' => 'restrict_role', |
|
1616
|
|
|
'label' => __( 'Restrict access by Role?', 'pods' ), |
|
1617
|
|
|
'default' => 0, |
|
1618
|
|
|
'type' => 'boolean', |
|
1619
|
|
|
'dependency' => true |
|
1620
|
|
|
), |
|
1621
|
|
|
'restrict_capability' => array( |
|
1622
|
|
|
'name' => 'restrict_capability', |
|
1623
|
|
|
'label' => __( 'Restrict access by Capability?', 'pods' ), |
|
1624
|
|
|
'default' => 0, |
|
1625
|
|
|
'type' => 'boolean', |
|
1626
|
|
|
'dependency' => true |
|
1627
|
|
|
), |
|
1628
|
|
|
'hidden' => array( |
|
1629
|
|
|
'name' => 'hidden', |
|
1630
|
|
|
'label' => __( 'Hide field from UI', 'pods' ), |
|
1631
|
|
|
'default' => 0, |
|
1632
|
|
|
'type' => 'boolean', |
|
1633
|
|
|
'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be hidden. If no access restrictions are set, this field will always be hidden.', 'pods' ) |
|
1634
|
|
|
), |
|
1635
|
|
|
'read_only' => array( |
|
1636
|
|
|
'name' => 'read_only', |
|
1637
|
|
|
'label' => __( 'Make field "Read Only" in UI', 'pods' ), |
|
1638
|
|
|
'default' => 0, |
|
1639
|
|
|
'type' => 'boolean', |
|
1640
|
|
|
'help' => __( 'This option is overriden by access restrictions. If the user does not have access to edit this field, it will be read only. If no access restrictions are set, this field will always be read only.', 'pods' ), |
|
1641
|
|
|
'depends-on' => array( |
|
1642
|
|
|
'type' => array( |
|
1643
|
|
|
'boolean', |
|
1644
|
|
|
'color', |
|
1645
|
|
|
'currency', |
|
1646
|
|
|
'date', |
|
1647
|
|
|
'datetime', |
|
1648
|
|
|
'email', |
|
1649
|
|
|
'number', |
|
1650
|
|
|
'paragraph', |
|
1651
|
|
|
'password', |
|
1652
|
|
|
'phone', |
|
1653
|
|
|
'slug', |
|
1654
|
|
|
'text', |
|
1655
|
|
|
'time', |
|
1656
|
|
|
'website' |
|
1657
|
|
|
) |
|
1658
|
|
|
) |
|
1659
|
|
|
) |
|
1660
|
|
|
) |
|
1661
|
|
|
), |
|
1662
|
|
|
'roles_allowed' => array( |
|
1663
|
|
|
'name' => 'roles_allowed', |
|
1664
|
|
|
'label' => __( 'Role(s) Allowed', 'pods' ), |
|
1665
|
|
|
'help' => __( 'help', 'pods' ), |
|
1666
|
|
|
'type' => 'pick', |
|
1667
|
|
|
'pick_object' => 'role', |
|
1668
|
|
|
'pick_format_type' => 'multi', |
|
1669
|
|
|
'default' => 'administrator', |
|
1670
|
|
|
'depends-on' => array( |
|
1671
|
|
|
'restrict_role' => true |
|
1672
|
|
|
) |
|
1673
|
|
|
), |
|
1674
|
|
|
'capability_allowed' => array( |
|
1675
|
|
|
'name' => 'capability_allowed', |
|
1676
|
|
|
'label' => __( 'Capability Allowed', 'pods' ), |
|
1677
|
|
|
'help' => __( 'Comma-separated list of cababilities, for example add_podname_item, please see the Roles and Capabilities component for the complete list and a way to add your own.', 'pods' ), |
|
1678
|
|
|
'type' => 'text', |
|
1679
|
|
|
'default' => '', |
|
1680
|
|
|
'depends-on' => array( |
|
1681
|
|
|
'restrict_capability' => true |
|
1682
|
|
|
) |
|
1683
|
|
|
) |
|
1684
|
|
|
/*, |
|
|
|
|
|
|
1685
|
|
|
'search' => array( |
|
1686
|
|
|
'label' => __( 'Include in searches', 'pods' ), |
|
1687
|
|
|
'help' => __( 'help', 'pods' ), |
|
1688
|
|
|
'default' => 1, |
|
1689
|
|
|
'type' => 'boolean', |
|
1690
|
|
|
)*/ |
|
1691
|
|
|
) |
|
1692
|
|
|
/*, |
|
|
|
|
|
|
1693
|
|
|
__( 'Validation', 'pods' ) => array( |
|
1694
|
|
|
'regex_validation' => array( |
|
1695
|
|
|
'label' => __( 'RegEx Validation', 'pods' ), |
|
1696
|
|
|
'help' => __( 'help', 'pods' ), |
|
1697
|
|
|
'type' => 'text', |
|
1698
|
|
|
'default' => '' |
|
1699
|
|
|
), |
|
1700
|
|
|
'message_regex' => array( |
|
1701
|
|
|
'label' => __( 'Message if field does not pass RegEx', 'pods' ), |
|
1702
|
|
|
'help' => __( 'help', 'pods' ), |
|
1703
|
|
|
'type' => 'text', |
|
1704
|
|
|
'default' => '' |
|
1705
|
|
|
), |
|
1706
|
|
|
'message_required' => array( |
|
1707
|
|
|
'label' => __( 'Message if field is blank', 'pods' ), |
|
1708
|
|
|
'help' => __( 'help', 'pods' ), |
|
1709
|
|
|
'type' => 'text', |
|
1710
|
|
|
'default' => '', |
|
1711
|
|
|
'depends-on' => array( 'required' => true ) |
|
1712
|
|
|
), |
|
1713
|
|
|
'message_unique' => array( |
|
1714
|
|
|
'label' => __( 'Message if field is not unique', 'pods' ), |
|
1715
|
|
|
'help' => __( 'help', 'pods' ), |
|
1716
|
|
|
'type' => 'text', |
|
1717
|
|
|
'default' => '', |
|
1718
|
|
|
'depends-on' => array( 'unique' => true ) |
|
1719
|
|
|
) |
|
1720
|
|
|
)*/ |
|
1721
|
|
|
); |
|
1722
|
|
|
|
|
1723
|
|
|
if ( !class_exists( 'Pods_Helpers' ) ) |
|
1724
|
|
|
unset( $options[ 'advanced-options' ][ 'input_helper' ] ); |
|
1725
|
|
|
|
|
1726
|
|
|
/** |
|
1727
|
|
|
* Modify tabs and their contents for field options |
|
1728
|
|
|
* |
|
1729
|
|
|
* @since unknown |
|
1730
|
|
|
* |
|
1731
|
|
|
* @param array $options Tabs, indexed by label |
|
1732
|
|
|
* @param object|Pods Pods object for the Pod this UI is for. |
|
1733
|
|
|
*/ |
|
1734
|
|
|
$options = apply_filters( 'pods_admin_setup_edit_field_options', $options, $pod ); |
|
1735
|
|
|
|
|
1736
|
|
|
return $options; |
|
1737
|
|
|
} |
|
1738
|
|
|
|
|
1739
|
|
|
/** |
|
1740
|
|
|
* Duplicate a pod |
|
1741
|
|
|
* |
|
1742
|
|
|
* @param $id |
|
1743
|
|
|
* @param $obj |
|
1744
|
|
|
* |
|
1745
|
|
|
* @return mixed |
|
1746
|
|
|
*/ |
|
1747
|
|
|
public function admin_setup_duplicate ( $obj ) { |
|
1748
|
|
|
$new_id = pods_api()->duplicate_pod( array( 'id' => $obj->id ) ); |
|
1749
|
|
|
|
|
1750
|
|
|
if ( 0 < $new_id ) |
|
1751
|
|
|
pods_redirect( pods_query_arg( array( 'action' => 'edit', 'id' => $new_id, 'do' => 'duplicate' ) ) ); |
|
1752
|
|
|
} |
|
1753
|
|
|
|
|
1754
|
|
|
/** |
|
1755
|
|
|
* Restrict Duplicate action to custom types, not extended |
|
1756
|
|
|
* |
|
1757
|
|
|
* @param bool $restricted |
|
1758
|
|
|
* @param array $restrict |
|
1759
|
|
|
* @param string $action |
|
1760
|
|
|
* @param array $row |
|
1761
|
|
|
* @param PodsUI $obj |
|
1762
|
|
|
* |
|
1763
|
|
|
* @since 2.3.10 |
|
1764
|
|
|
* |
|
1765
|
|
|
* @return bool |
|
1766
|
|
|
*/ |
|
1767
|
|
View Code Duplication |
public function admin_setup_duplicate_restrict( $restricted, $restrict, $action, $row, $obj ) { |
|
|
|
|
|
|
1768
|
|
|
|
|
1769
|
|
|
if ( in_array( $row[ 'real_type' ], array( 'user', 'media', 'comment' ) ) ) { |
|
1770
|
|
|
$restricted = true; |
|
1771
|
|
|
} |
|
1772
|
|
|
|
|
1773
|
|
|
return $restricted; |
|
1774
|
|
|
|
|
1775
|
|
|
} |
|
1776
|
|
|
|
|
1777
|
|
|
/** |
|
1778
|
|
|
* Reset a pod |
|
1779
|
|
|
* |
|
1780
|
|
|
* @param $obj |
|
1781
|
|
|
* |
|
1782
|
|
|
* @return mixed |
|
1783
|
|
|
*/ |
|
1784
|
|
|
public function admin_setup_reset ( $obj, $id ) { |
|
1785
|
|
|
$pod = pods_api()->load_pod( array( 'id' => $id ), false ); |
|
1786
|
|
|
|
|
1787
|
|
|
if ( empty( $pod ) ) |
|
1788
|
|
|
return $obj->error( __( 'Pod not found.', 'pods' ) ); |
|
1789
|
|
|
|
|
1790
|
|
|
pods_api()->reset_pod( array( 'id' => $id ) ); |
|
1791
|
|
|
|
|
1792
|
|
|
$obj->message( __( 'Pod reset successfully.', 'pods' ) ); |
|
1793
|
|
|
|
|
1794
|
|
|
$obj->manage(); |
|
1795
|
|
|
} |
|
1796
|
|
|
|
|
1797
|
|
|
/** |
|
1798
|
|
|
* Restrict Reset action from users and media |
|
1799
|
|
|
* |
|
1800
|
|
|
* @param bool $restricted |
|
1801
|
|
|
* @param array $restrict |
|
1802
|
|
|
* @param string $action |
|
1803
|
|
|
* @param array $row |
|
1804
|
|
|
* @param PodsUI $obj |
|
1805
|
|
|
* |
|
1806
|
|
|
* @since 2.3.10 |
|
1807
|
|
|
*/ |
|
1808
|
|
View Code Duplication |
public function admin_setup_reset_restrict( $restricted, $restrict, $action, $row, $obj ) { |
|
|
|
|
|
|
1809
|
|
|
|
|
1810
|
|
|
if ( in_array( $row[ 'real_type' ], array( 'user', 'media' ) ) ) { |
|
1811
|
|
|
$restricted = true; |
|
1812
|
|
|
} |
|
1813
|
|
|
|
|
1814
|
|
|
return $restricted; |
|
1815
|
|
|
|
|
1816
|
|
|
} |
|
1817
|
|
|
|
|
1818
|
|
|
/** |
|
1819
|
|
|
* Delete a pod |
|
1820
|
|
|
* |
|
1821
|
|
|
* @param $id |
|
1822
|
|
|
* @param $obj |
|
1823
|
|
|
* |
|
1824
|
|
|
* @return mixed |
|
1825
|
|
|
*/ |
|
1826
|
|
|
public function admin_setup_delete ( $id, $obj ) { |
|
1827
|
|
|
$pod = pods_api()->load_pod( array( 'id' => $id ), false ); |
|
1828
|
|
|
|
|
1829
|
|
|
if ( empty( $pod ) ) |
|
1830
|
|
|
return $obj->error( __( 'Pod not found.', 'pods' ) ); |
|
1831
|
|
|
|
|
1832
|
|
|
pods_api()->delete_pod( array( 'id' => $id ) ); |
|
1833
|
|
|
|
|
1834
|
|
|
unset( $obj->data[ $pod[ 'id' ] ] ); |
|
1835
|
|
|
|
|
1836
|
|
|
$obj->total = count( $obj->data ); |
|
1837
|
|
|
$obj->total_found = count( $obj->data ); |
|
1838
|
|
|
|
|
1839
|
|
|
$obj->message( __( 'Pod deleted successfully.', 'pods' ) ); |
|
1840
|
|
|
} |
|
1841
|
|
|
|
|
1842
|
|
|
/** |
|
1843
|
|
|
* Get advanced administration view. |
|
1844
|
|
|
*/ |
|
1845
|
|
|
public function admin_advanced () { |
|
1846
|
|
|
pods_view( PODS_DIR . 'ui/admin/advanced.php', compact( array_keys( get_defined_vars() ) ) ); |
|
1847
|
|
|
} |
|
1848
|
|
|
|
|
1849
|
|
|
/** |
|
1850
|
|
|
* Get settings administration view |
|
1851
|
|
|
*/ |
|
1852
|
|
|
public function admin_settings () { |
|
1853
|
|
|
pods_view( PODS_DIR . 'ui/admin/settings.php', compact( array_keys( get_defined_vars() ) ) ); |
|
1854
|
|
|
} |
|
1855
|
|
|
|
|
1856
|
|
|
/** |
|
1857
|
|
|
* Get components administration UI |
|
1858
|
|
|
*/ |
|
1859
|
|
|
public function admin_components () { |
|
1860
|
|
|
$components = PodsInit::$components->components; |
|
|
|
|
|
|
1861
|
|
|
|
|
1862
|
|
|
$view = pods_var( 'view', 'get', 'all', null, true ); |
|
1863
|
|
|
|
|
1864
|
|
|
$recommended = array( |
|
1865
|
|
|
'advanced-relationships', |
|
1866
|
|
|
'advanced-content-types', |
|
1867
|
|
|
'migrate-packages', |
|
1868
|
|
|
'roles-and-capabilities', |
|
1869
|
|
|
'pages', |
|
1870
|
|
|
'table-storage', |
|
1871
|
|
|
'templates' |
|
1872
|
|
|
); |
|
1873
|
|
|
|
|
1874
|
|
|
foreach ( $components as $component => &$component_data ) { |
|
|
|
|
|
|
1875
|
|
|
if ( !in_array( $view, array( 'all', 'recommended', 'dev' ) ) && ( !isset( $component_data[ 'Category' ] ) || $view != sanitize_title( $component_data[ 'Category' ] ) ) ) { |
|
1876
|
|
|
unset( $components[ $component ] ); |
|
1877
|
|
|
|
|
1878
|
|
|
continue; |
|
1879
|
|
|
} |
|
1880
|
|
|
elseif ( 'recommended' == $view && !in_array( $component_data[ 'ID' ], $recommended ) ) { |
|
1881
|
|
|
unset( $components[ $component ] ); |
|
1882
|
|
|
|
|
1883
|
|
|
continue; |
|
1884
|
|
|
} |
|
1885
|
|
View Code Duplication |
elseif ( 'dev' == $view && pods_developer() && !pods_var_raw( 'DeveloperMode', $component_data, false ) ) { |
|
1886
|
|
|
unset( $components[ $component ] ); |
|
1887
|
|
|
|
|
1888
|
|
|
continue; |
|
1889
|
|
|
} |
|
1890
|
|
View Code Duplication |
elseif ( pods_var_raw( 'DeveloperMode', $component_data, false ) && !pods_developer() ) { |
|
1891
|
|
|
unset( $components[ $component ] ); |
|
1892
|
|
|
|
|
1893
|
|
|
continue; |
|
1894
|
|
|
} |
|
1895
|
|
|
elseif ( !pods_var_raw( 'TablelessMode', $component_data, false ) && pods_tableless() ) { |
|
1896
|
|
|
unset( $components[ $component ] ); |
|
1897
|
|
|
|
|
1898
|
|
|
continue; |
|
1899
|
|
|
} |
|
1900
|
|
|
|
|
1901
|
|
|
$component_data[ 'Name' ] = strip_tags( $component_data[ 'Name' ] ); |
|
1902
|
|
|
|
|
1903
|
|
|
if ( pods_var_raw( 'DeveloperMode', $component_data, false ) ) |
|
1904
|
|
|
$component_data[ 'Name' ] .= ' <em style="font-weight: normal; color:#333;">(Developer Preview)</em>'; |
|
1905
|
|
|
|
|
1906
|
|
|
$meta = array(); |
|
1907
|
|
|
|
|
1908
|
|
|
if ( !empty( $component_data[ 'Version' ] ) ) |
|
1909
|
|
|
$meta[] = 'Version ' . $component_data[ 'Version' ]; |
|
1910
|
|
|
|
|
1911
|
|
|
if ( empty( $component_data[ 'Author' ] ) ) { |
|
1912
|
|
|
$component_data[ 'Author' ] = 'Pods Framework Team'; |
|
1913
|
|
|
$component_data[ 'AuthorURI' ] = 'http://pods.io/'; |
|
1914
|
|
|
} |
|
1915
|
|
|
|
|
1916
|
|
|
if ( !empty( $component_data[ 'AuthorURI' ] ) ) |
|
1917
|
|
|
$component_data[ 'Author' ] = '<a href="' . $component_data[ 'AuthorURI' ] . '">' . $component_data[ 'Author' ] . '</a>'; |
|
1918
|
|
|
|
|
1919
|
|
|
$meta[] = sprintf( __( 'by %s', 'pods' ), $component_data[ 'Author' ] ); |
|
1920
|
|
|
|
|
1921
|
|
View Code Duplication |
if ( !empty( $component_data[ 'URI' ] ) ) |
|
1922
|
|
|
$meta[] = '<a href="' . $component_data[ 'URI' ] . '">' . __( 'Visit component site', 'pods' ) . '</a>'; |
|
1923
|
|
|
|
|
1924
|
|
|
$component_data[ 'Description' ] = wpautop( trim( make_clickable( strip_tags( $component_data[ 'Description' ], 'em,strong' ) ) ) ); |
|
1925
|
|
|
|
|
1926
|
|
View Code Duplication |
if ( !empty( $meta ) ) |
|
1927
|
|
|
$component_data[ 'Description' ] .= '<div class="pods-component-meta" ' . ( !empty( $component_data[ 'Description' ] ) ? ' style="padding:8px 0 4px;"' : '' ) . '>' . implode( ' | ', $meta ) . '</div>'; |
|
1928
|
|
|
|
|
1929
|
|
|
$component_data = array( |
|
1930
|
|
|
'id' => $component_data[ 'ID' ], |
|
1931
|
|
|
'name' => $component_data[ 'Name' ], |
|
1932
|
|
|
'category' => $component_data[ 'Category' ], |
|
1933
|
|
|
'version' => '', |
|
1934
|
|
|
'description' => $component_data[ 'Description' ], |
|
1935
|
|
|
'mustuse' => pods_var_raw( 'MustUse', $component_data, false ), |
|
1936
|
|
|
'toggle' => 0 |
|
1937
|
|
|
); |
|
1938
|
|
|
|
|
1939
|
|
|
if ( !empty( $component_data[ 'category' ] ) ) { |
|
1940
|
|
|
$category_url = pods_query_arg( array( 'view' => sanitize_title( $component_data[ 'category' ] ), 'pg' => '', 'page' => $_GET[ 'page' ] ) ); |
|
1941
|
|
|
|
|
1942
|
|
|
$component_data[ 'category' ] = '<a href="' . esc_url( $category_url ) . '">' . $component_data[ 'category' ] . '</a>'; |
|
1943
|
|
|
} |
|
1944
|
|
|
|
|
1945
|
|
|
if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] ) && 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'id' ] ] ) |
|
|
|
|
|
|
1946
|
|
|
$component_data[ 'toggle' ] = 1; |
|
1947
|
|
|
elseif ( $component_data[ 'mustuse' ] ) |
|
1948
|
|
|
$component_data[ 'toggle' ] = 1; |
|
1949
|
|
|
} |
|
1950
|
|
|
|
|
1951
|
|
|
$ui = array( |
|
1952
|
|
|
'data' => $components, |
|
1953
|
|
|
'total' => count( $components ), |
|
1954
|
|
|
'total_found' => count( $components ), |
|
1955
|
|
|
'items' => 'Components', |
|
1956
|
|
|
'item' => 'Component', |
|
1957
|
|
|
'fields' => array( |
|
1958
|
|
|
'manage' => array( |
|
1959
|
|
|
'name' => array( |
|
1960
|
|
|
'label' => __( 'Name', 'pods' ), |
|
1961
|
|
|
'width' => '30%', |
|
1962
|
|
|
'type' => 'text', |
|
1963
|
|
|
'options' => array( |
|
1964
|
|
|
'text_allow_html' => true |
|
1965
|
|
|
) |
|
1966
|
|
|
), |
|
1967
|
|
|
'category' => array( |
|
1968
|
|
|
'label' => __( 'Category', 'pods' ), |
|
1969
|
|
|
'width' => '10%', |
|
1970
|
|
|
'type' => 'text', |
|
1971
|
|
|
'options' => array( |
|
1972
|
|
|
'text_allow_html' => true |
|
1973
|
|
|
) |
|
1974
|
|
|
), |
|
1975
|
|
|
'description' => array( |
|
1976
|
|
|
'label' => __( 'Description', 'pods' ), |
|
1977
|
|
|
'width' => '60%', |
|
1978
|
|
|
'type' => 'text', |
|
1979
|
|
|
'options' => array( |
|
1980
|
|
|
'text_allow_html' => true, |
|
1981
|
|
|
'text_allowed_html_tags' => 'strong em a ul ol li b i br div' |
|
1982
|
|
|
) |
|
1983
|
|
|
) |
|
1984
|
|
|
) |
|
1985
|
|
|
), |
|
1986
|
|
|
'actions_disabled' => array( 'duplicate', 'view', 'export', 'add', 'edit', 'delete' ), |
|
1987
|
|
|
'actions_custom' => array( |
|
1988
|
|
|
'toggle' => array( |
|
1989
|
|
|
'callback' => array( $this, 'admin_components_toggle' ), |
|
1990
|
|
|
'nonce' => true |
|
1991
|
|
|
) |
|
1992
|
|
|
), |
|
1993
|
|
|
'filters_enhanced' => true, |
|
1994
|
|
|
'views' => array( |
|
1995
|
|
|
'all' => __( 'All', 'pods' ), |
|
1996
|
|
|
//'recommended' => __( 'Recommended', 'pods' ), |
|
|
|
|
|
|
1997
|
|
|
'field-types' => __( 'Field Types', 'pods' ), |
|
1998
|
|
|
'tools' => __( 'Tools', 'pods' ), |
|
1999
|
|
|
'integration' => __( 'Integration', 'pods' ), |
|
2000
|
|
|
'migration' => __( 'Migration', 'pods' ), |
|
2001
|
|
|
'advanced' => __( 'Advanced', 'pods' ) |
|
2002
|
|
|
), |
|
2003
|
|
|
'view' => $view, |
|
2004
|
|
|
'heading' => array( |
|
2005
|
|
|
'views' => __( 'Category', 'pods' ) |
|
2006
|
|
|
), |
|
2007
|
|
|
'search' => false, |
|
2008
|
|
|
'searchable' => false, |
|
2009
|
|
|
'sortable' => false, |
|
2010
|
|
|
'pagination' => false |
|
2011
|
|
|
); |
|
2012
|
|
|
|
|
2013
|
|
|
if ( pods_developer() ) |
|
2014
|
|
|
$ui[ 'views' ][ 'dev' ] = __( 'Developer Preview', 'pods' ); |
|
2015
|
|
|
|
|
2016
|
|
|
pods_ui( $ui ); |
|
2017
|
|
|
} |
|
2018
|
|
|
|
|
2019
|
|
|
/** |
|
2020
|
|
|
* Toggle a component on or off |
|
2021
|
|
|
* |
|
2022
|
|
|
* @param PodsUI $ui |
|
2023
|
|
|
* |
|
2024
|
|
|
* @return bool |
|
2025
|
|
|
*/ |
|
2026
|
|
|
public function admin_components_toggle ( PodsUI $ui ) { |
|
2027
|
|
|
$component = $_GET[ 'id' ]; |
|
2028
|
|
|
|
|
2029
|
|
|
if ( !empty( PodsInit::$components->components[ $component ][ 'PluginDependency' ] ) ) { |
|
|
|
|
|
|
2030
|
|
|
$dependency = explode( '|', PodsInit::$components->components[ $component ][ 'PluginDependency' ] ); |
|
|
|
|
|
|
2031
|
|
|
|
|
2032
|
|
|
if ( !pods_is_plugin_active( $dependency[ 1 ] ) ) { |
|
2033
|
|
|
$website = 'http://wordpress.org/extend/plugins/' . dirname( $dependency[ 1 ] ) . '/'; |
|
2034
|
|
|
|
|
2035
|
|
|
if ( isset( $dependency[ 2 ] ) ) |
|
2036
|
|
|
$website = $dependency[ 2 ]; |
|
2037
|
|
|
|
|
2038
|
|
|
if ( !empty( $website ) ) |
|
2039
|
|
|
$website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $website . '" target="_blank">' . $website . '</a>' ); |
|
2040
|
|
|
|
|
2041
|
|
|
$message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> plugin installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website; |
|
|
|
|
|
|
2042
|
|
|
|
|
2043
|
|
|
$ui->error( $message ); |
|
2044
|
|
|
|
|
2045
|
|
|
$ui->manage(); |
|
2046
|
|
|
|
|
2047
|
|
|
return; |
|
2048
|
|
|
} |
|
2049
|
|
|
} |
|
2050
|
|
|
|
|
2051
|
|
|
if ( !empty( PodsInit::$components->components[ $component ][ 'ThemeDependency' ] ) ) { |
|
|
|
|
|
|
2052
|
|
|
$dependency = explode( '|', PodsInit::$components->components[ $component ][ 'ThemeDependency' ] ); |
|
|
|
|
|
|
2053
|
|
|
|
|
2054
|
|
|
if ( strtolower( $dependency[ 1 ] ) != strtolower( get_template() ) && strtolower( $dependency[ 1 ] ) != strtolower( get_stylesheet() ) ) { |
|
2055
|
|
|
$website = ''; |
|
2056
|
|
|
|
|
2057
|
|
|
if ( isset( $dependency[ 2 ] ) ) |
|
2058
|
|
|
$website = ' ' . sprintf( __( 'You can find it at %s', 'pods' ), '<a href="' . $dependency[ 2 ] . '" target="_blank">' . $dependency[ 2 ] . '</a>' ); |
|
2059
|
|
|
|
|
2060
|
|
|
$message = sprintf( __( 'The %s component requires that you have the <strong>%s</strong> theme installed and activated.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ], $dependency[ 0 ] ) . $website; |
|
|
|
|
|
|
2061
|
|
|
|
|
2062
|
|
|
$ui->error( $message ); |
|
2063
|
|
|
|
|
2064
|
|
|
$ui->manage(); |
|
2065
|
|
|
|
|
2066
|
|
|
return; |
|
2067
|
|
|
} |
|
2068
|
|
|
} |
|
2069
|
|
|
|
|
2070
|
|
|
if ( !empty( PodsInit::$components->components[ $component ][ 'MustUse' ] ) ) { |
|
|
|
|
|
|
2071
|
|
|
$message = sprintf( __( 'The %s component can not be disabled from here. You must deactivate the plugin or theme that added it.', 'pods' ), PodsInit::$components->components[ $component ][ 'Name' ] ); |
|
|
|
|
|
|
2072
|
|
|
|
|
2073
|
|
|
$ui->error( $message ); |
|
2074
|
|
|
|
|
2075
|
|
|
$ui->manage(); |
|
2076
|
|
|
|
|
2077
|
|
|
return; |
|
2078
|
|
|
} |
|
2079
|
|
|
|
|
2080
|
|
|
if ( '1' == pods_v( 'toggled' ) ) { |
|
2081
|
|
|
$toggle = PodsInit::$components->toggle( $component ); |
|
|
|
|
|
|
2082
|
|
|
|
|
2083
|
|
|
if ( true === $toggle ) |
|
2084
|
|
|
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) ); |
|
|
|
|
|
|
2085
|
|
View Code Duplication |
elseif ( false === $toggle ) |
|
2086
|
|
|
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) ); |
|
|
|
|
|
|
2087
|
|
|
|
|
2088
|
|
|
$components = PodsInit::$components->components; |
|
|
|
|
|
|
2089
|
|
|
|
|
2090
|
|
|
foreach ( $components as $component => &$component_data ) { |
|
|
|
|
|
|
2091
|
|
|
$toggle = 0; |
|
2092
|
|
|
|
|
2093
|
|
|
if ( isset( PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] ) ) { |
|
|
|
|
|
|
2094
|
|
|
if ( 0 != PodsInit::$components->settings[ 'components' ][ $component_data[ 'ID' ] ] ) |
|
|
|
|
|
|
2095
|
|
|
$toggle = 1; |
|
2096
|
|
|
} |
|
2097
|
|
|
if ( true === $component_data[ 'DeveloperMode' ] ) { |
|
2098
|
|
|
if ( !pods_developer() ) { |
|
2099
|
|
|
unset( $components[ $component ] ); |
|
2100
|
|
|
continue; |
|
2101
|
|
|
} |
|
2102
|
|
|
} |
|
2103
|
|
|
|
|
2104
|
|
|
$component_data = array( |
|
2105
|
|
|
'id' => $component_data[ 'ID' ], |
|
2106
|
|
|
'name' => $component_data[ 'Name' ], |
|
2107
|
|
|
'description' => make_clickable( $component_data[ 'Description' ] ), |
|
2108
|
|
|
'version' => $component_data[ 'Version' ], |
|
2109
|
|
|
'author' => $component_data[ 'Author' ], |
|
2110
|
|
|
'toggle' => $toggle |
|
2111
|
|
|
); |
|
2112
|
|
|
} |
|
2113
|
|
|
|
|
2114
|
|
|
$ui->data = $components; |
|
2115
|
|
|
|
|
2116
|
|
|
pods_transient_clear( 'pods_components' ); |
|
2117
|
|
|
|
|
2118
|
|
|
$url = pods_query_arg( array( 'toggled' => null ) ); |
|
2119
|
|
|
|
|
2120
|
|
|
pods_redirect( $url ); |
|
2121
|
|
|
} |
|
2122
|
|
View Code Duplication |
elseif ( 1 == pods_var( 'toggle' ) ) |
|
2123
|
|
|
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component enabled', 'pods' ) ); |
|
|
|
|
|
|
2124
|
|
View Code Duplication |
else |
|
2125
|
|
|
$ui->message( PodsInit::$components->components[ $component ][ 'Name' ] . ' ' . __( 'Component disabled', 'pods' ) ); |
|
|
|
|
|
|
2126
|
|
|
|
|
2127
|
|
|
$ui->manage(); |
|
2128
|
|
|
} |
|
2129
|
|
|
|
|
2130
|
|
|
/** |
|
2131
|
|
|
* Get the admin upgrade page |
|
2132
|
|
|
*/ |
|
2133
|
|
|
public function admin_upgrade () { |
|
2134
|
|
|
foreach ( PodsInit::$upgrades as $old_version => $new_version ) { |
|
|
|
|
|
|
2135
|
|
|
if ( version_compare( $old_version, PodsInit::$version_last, '<=' ) && version_compare( PodsInit::$version_last, $new_version, '<' ) ) { |
|
|
|
|
|
|
2136
|
|
|
$new_version = str_replace( '.', '_', $new_version ); |
|
2137
|
|
|
|
|
2138
|
|
|
pods_view( PODS_DIR . 'ui/admin/upgrade/upgrade_' . $new_version . '.php', compact( array_keys( get_defined_vars() ) ) ); |
|
2139
|
|
|
|
|
2140
|
|
|
break; |
|
2141
|
|
|
} |
|
2142
|
|
|
} |
|
2143
|
|
|
} |
|
2144
|
|
|
|
|
2145
|
|
|
/** |
|
2146
|
|
|
* Get the admin help page |
|
2147
|
|
|
*/ |
|
2148
|
|
|
public function admin_help () { |
|
2149
|
|
|
pods_view( PODS_DIR . 'ui/admin/help.php', compact( array_keys( get_defined_vars() ) ) ); |
|
2150
|
|
|
} |
|
2151
|
|
|
|
|
2152
|
|
|
/** |
|
2153
|
|
|
* Add pods specific capabilities. |
|
2154
|
|
|
* |
|
2155
|
|
|
* @param $capabilities List of extra capabilities to add |
|
2156
|
|
|
* |
|
2157
|
|
|
* @return array |
|
2158
|
|
|
*/ |
|
2159
|
|
|
public function admin_capabilities ( $capabilities ) { |
|
2160
|
|
|
$pods = pods_api()->load_pods( array( 'type' => array( 'pod', 'table', 'post_type', 'taxonomy', 'settings' ) ) ); |
|
2161
|
|
|
|
|
2162
|
|
|
$capabilities[] = 'pods'; |
|
2163
|
|
|
$capabilities[] = 'pods_content'; |
|
2164
|
|
|
$capabilities[] = 'pods_settings'; |
|
2165
|
|
|
$capabilities[] = 'pods_components'; |
|
2166
|
|
|
|
|
2167
|
|
|
foreach ( $pods as $pod ) { |
|
|
|
|
|
|
2168
|
|
|
if ( 'settings' == $pod[ 'type' ] ) { |
|
2169
|
|
|
$capabilities[] = 'pods_edit_' . $pod[ 'name' ]; |
|
2170
|
|
|
} |
|
2171
|
|
|
elseif ( 'post_type' == $pod[ 'type' ] ) { |
|
2172
|
|
|
$capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) ); |
|
2173
|
|
|
|
|
2174
|
|
|
if ( 'custom' == pods_var( 'capability_type', $pod[ 'options' ] ) && 0 < strlen( $capability_type ) ) { |
|
2175
|
|
|
$capabilities[] = 'read_' . $capability_type; |
|
2176
|
|
|
$capabilities[] = 'edit_' . $capability_type; |
|
2177
|
|
|
$capabilities[] = 'delete_' . $capability_type; |
|
2178
|
|
|
|
|
2179
|
|
|
if ( 1 == pods_var( 'capability_type_extra', $pod[ 'options' ], 1 ) ) { |
|
2180
|
|
|
$capabilities[] = 'read_private_' . $capability_type . 's'; |
|
2181
|
|
|
$capabilities[] = 'edit_' . $capability_type . 's'; |
|
2182
|
|
|
$capabilities[] = 'edit_others_' . $capability_type . 's'; |
|
2183
|
|
|
$capabilities[] = 'edit_private_' . $capability_type . 's'; |
|
2184
|
|
|
$capabilities[] = 'edit_published_' . $capability_type . 's'; |
|
2185
|
|
|
$capabilities[] = 'publish_' . $capability_type . 's'; |
|
2186
|
|
|
$capabilities[] = 'delete_' . $capability_type . 's'; |
|
2187
|
|
|
$capabilities[] = 'delete_private_' . $capability_type . 's'; |
|
2188
|
|
|
$capabilities[] = 'delete_published_' . $capability_type . 's'; |
|
2189
|
|
|
$capabilities[] = 'delete_others_' . $capability_type . 's'; |
|
2190
|
|
|
} |
|
2191
|
|
|
} |
|
2192
|
|
|
} |
|
2193
|
|
|
elseif ( 'taxonomy' == $pod[ 'type' ] ) { |
|
2194
|
|
|
if ( 1 == pods_var( 'capabilities', $pod[ 'options' ], 0 ) ) { |
|
2195
|
|
|
$capability_type = pods_var( 'capability_type_custom', $pod[ 'options' ], pods_var_raw( 'name', $pod ) . 's' ); |
|
2196
|
|
|
|
|
2197
|
|
|
$capabilities[] = 'manage_' . $capability_type; |
|
2198
|
|
|
$capabilities[] = 'edit_' . $capability_type; |
|
2199
|
|
|
$capabilities[] = 'delete_' . $capability_type; |
|
2200
|
|
|
$capabilities[] = 'assign_' . $capability_type; |
|
2201
|
|
|
} |
|
2202
|
|
|
} |
|
2203
|
|
|
else { |
|
2204
|
|
|
$capabilities[] = 'pods_add_' . $pod[ 'name' ]; |
|
2205
|
|
|
$capabilities[] = 'pods_edit_' . $pod[ 'name' ]; |
|
2206
|
|
|
|
|
2207
|
|
View Code Duplication |
if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] ) |
|
2208
|
|
|
$capabilities[] = 'pods_edit_others_' . $pod[ 'name' ]; |
|
2209
|
|
|
|
|
2210
|
|
|
$capabilities[] = 'pods_delete_' . $pod[ 'name' ]; |
|
2211
|
|
|
|
|
2212
|
|
View Code Duplication |
if ( isset( $pod[ 'fields' ][ 'author' ] ) && 'pick' == $pod[ 'fields' ][ 'author' ][ 'type' ] && 'user' == $pod[ 'fields' ][ 'author' ][ 'pick_object' ] ) |
|
2213
|
|
|
$capabilities[] = 'pods_delete_others_' . $pod[ 'name' ]; |
|
2214
|
|
|
|
|
2215
|
|
|
$actions_enabled = pods_var_raw( 'ui_actions_enabled', $pod[ 'options' ] ); |
|
2216
|
|
|
|
|
2217
|
|
|
if ( !empty( $actions_enabled ) ) |
|
2218
|
|
|
$actions_enabled = (array) $actions_enabled; |
|
2219
|
|
|
else |
|
2220
|
|
|
$actions_enabled = array(); |
|
2221
|
|
|
|
|
2222
|
|
|
$available_actions = array( |
|
2223
|
|
|
'add', |
|
2224
|
|
|
'edit', |
|
2225
|
|
|
'duplicate', |
|
2226
|
|
|
'delete', |
|
2227
|
|
|
'reorder', |
|
2228
|
|
|
'export' |
|
2229
|
|
|
); |
|
2230
|
|
|
|
|
2231
|
|
|
if ( !empty( $actions_enabled ) ) { |
|
2232
|
|
|
$actions_disabled = array( |
|
2233
|
|
|
'view' => 'view' |
|
2234
|
|
|
); |
|
2235
|
|
|
|
|
2236
|
|
|
foreach ( $available_actions as $action ) { |
|
2237
|
|
|
if ( !in_array( $action, $actions_enabled ) ) |
|
2238
|
|
|
$actions_disabled[ $action ] = $action; |
|
2239
|
|
|
} |
|
2240
|
|
|
|
|
2241
|
|
|
if ( !in_array( 'export', $actions_disabled ) ) |
|
2242
|
|
|
$capabilities[] = 'pods_export_' . $pod[ 'name' ]; |
|
2243
|
|
|
|
|
2244
|
|
|
if ( !in_array( 'reorder', $actions_disabled ) ) |
|
2245
|
|
|
$capabilities[] = 'pods_reorder_' . $pod[ 'name' ]; |
|
2246
|
|
|
} |
|
2247
|
|
|
elseif ( 1 == pods_var( 'ui_export', $pod[ 'options' ], 0 ) ) |
|
2248
|
|
|
$capabilities[] = 'pods_export_' . $pod[ 'name' ]; |
|
2249
|
|
|
} |
|
2250
|
|
|
} |
|
2251
|
|
|
|
|
2252
|
|
|
return $capabilities; |
|
2253
|
|
|
} |
|
2254
|
|
|
|
|
2255
|
|
|
/** |
|
2256
|
|
|
* Handle ajax calls for the administration |
|
2257
|
|
|
*/ |
|
2258
|
|
|
public function admin_ajax () { |
|
2259
|
|
|
if ( false === headers_sent() ) { |
|
2260
|
|
|
pods_session_start(); |
|
2261
|
|
|
|
|
2262
|
|
|
header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) ); |
|
2263
|
|
|
} |
|
2264
|
|
|
|
|
2265
|
|
|
// Sanitize input |
|
2266
|
|
|
$params = pods_unslash( (array) $_POST ); |
|
2267
|
|
|
|
|
2268
|
|
|
foreach ( $params as $key => $value ) { |
|
2269
|
|
|
if ( 'action' == $key ) |
|
2270
|
|
|
continue; |
|
2271
|
|
|
|
|
2272
|
|
|
// Fixup $_POST data |
|
2273
|
|
|
$_POST[ str_replace( '_podsfix_', '', $key ) ] = $_POST[ $key ]; |
|
2274
|
|
|
|
|
2275
|
|
|
// Fixup $params with unslashed data |
|
2276
|
|
|
$params[ str_replace( '_podsfix_', '', $key ) ] = $value; |
|
2277
|
|
|
|
|
2278
|
|
|
// Unset the _podsfix_* keys |
|
2279
|
|
|
unset( $params[ $key ] ); |
|
2280
|
|
|
} |
|
2281
|
|
|
|
|
2282
|
|
|
$params = (object) $params; |
|
2283
|
|
|
|
|
2284
|
|
|
$methods = array( |
|
2285
|
|
|
'add_pod' => array( 'priv' => true ), |
|
2286
|
|
|
'save_pod' => array( 'priv' => true ), |
|
2287
|
|
|
'load_sister_fields' => array( 'priv' => true ), |
|
2288
|
|
|
'process_form' => array( 'custom_nonce' => true ), // priv handled through nonce |
|
2289
|
|
|
'upgrade' => array( 'priv' => true ), |
|
2290
|
|
|
'migrate' => array( 'priv' => true ) |
|
2291
|
|
|
); |
|
2292
|
|
|
|
|
2293
|
|
|
/** |
|
2294
|
|
|
* AJAX Callbacks in field editor |
|
2295
|
|
|
* |
|
2296
|
|
|
* @since unknown |
|
2297
|
|
|
* |
|
2298
|
|
|
* @param array $method Callback method map |
|
2299
|
|
|
* @param object|PodsAdmin Class object |
|
2300
|
|
|
*/ |
|
2301
|
|
|
$methods = apply_filters( 'pods_admin_ajax_methods', $methods, $this ); |
|
2302
|
|
|
|
|
2303
|
|
|
if ( !isset( $params->method ) || !isset( $methods[ $params->method ] ) ) |
|
2304
|
|
|
pods_error( 'Invalid AJAX request', $this ); |
|
2305
|
|
|
|
|
2306
|
|
|
$defaults = array( |
|
2307
|
|
|
'priv' => null, |
|
2308
|
|
|
'name' => $params->method, |
|
2309
|
|
|
'custom_nonce' => null |
|
2310
|
|
|
); |
|
2311
|
|
|
|
|
2312
|
|
|
$method = (object) array_merge( $defaults, (array) $methods[ $params->method ] ); |
|
2313
|
|
|
|
|
2314
|
|
|
if ( true !== $method->custom_nonce && ( !isset( $params->_wpnonce ) || false === wp_verify_nonce( $params->_wpnonce, 'pods-' . $params->method ) ) ) |
|
2315
|
|
|
pods_error( __( 'Unauthorized request', 'pods' ), $this ); |
|
2316
|
|
|
|
|
2317
|
|
|
// Cleaning up $params |
|
2318
|
|
|
unset( $params->action ); |
|
2319
|
|
|
unset( $params->method ); |
|
2320
|
|
|
|
|
2321
|
|
|
if ( true !== $method->custom_nonce ) |
|
2322
|
|
|
unset( $params->_wpnonce ); |
|
2323
|
|
|
|
|
2324
|
|
|
// Check permissions (convert to array to support multiple) |
|
2325
|
|
|
if ( !empty( $method->priv ) && !pods_is_admin( array( 'pods' ) ) && true !== $method->priv && !pods_is_admin( $method->priv ) ) |
|
2326
|
|
|
pods_error( __( 'Access denied', 'pods' ), $this ); |
|
2327
|
|
|
|
|
2328
|
|
|
$params->method = $method->name; |
|
2329
|
|
|
|
|
2330
|
|
|
$params = apply_filters( 'pods_api_' . $method->name, $params, $method ); |
|
2331
|
|
|
|
|
2332
|
|
|
$api = pods_api(); |
|
2333
|
|
|
|
|
2334
|
|
|
$api->display_errors = false; |
|
2335
|
|
|
|
|
2336
|
|
|
if ( 'upgrade' == $method->name ) |
|
2337
|
|
|
$output = (string) pods_upgrade( $params->version )->ajax( $params ); |
|
2338
|
|
|
elseif ( 'migrate' == $method->name ) |
|
2339
|
|
|
$output = (string) apply_filters( 'pods_api_migrate_run', $params ); |
|
2340
|
|
|
else { |
|
2341
|
|
|
if ( !method_exists( $api, $method->name ) ) |
|
2342
|
|
|
pods_error( 'API method does not exist', $this ); |
|
2343
|
|
|
elseif ( 'save_pod' == $method->name ) { |
|
2344
|
|
|
if ( isset( $params->field_data_json ) && is_array( $params->field_data_json ) ) { |
|
2345
|
|
|
$params->fields = $params->field_data_json; |
|
2346
|
|
|
|
|
2347
|
|
|
unset( $params->field_data_json ); |
|
2348
|
|
|
|
|
2349
|
|
|
foreach ( $params->fields as $k => $v ) { |
|
2350
|
|
|
if ( empty( $v ) ) |
|
2351
|
|
|
unset( $params->fields[ $k ] ); |
|
2352
|
|
|
elseif ( !is_array( $v ) ) |
|
2353
|
|
|
$params->fields[ $k ] = (array) @json_decode( $v, true ); |
|
2354
|
|
|
} |
|
2355
|
|
|
} |
|
2356
|
|
|
} |
|
2357
|
|
|
|
|
2358
|
|
|
// Dynamically call the API method |
|
2359
|
|
|
$params = (array) $params; |
|
2360
|
|
|
|
|
2361
|
|
|
$output = call_user_func( array( $api, $method->name ), $params ); |
|
2362
|
|
|
} |
|
2363
|
|
|
|
|
2364
|
|
|
// Output in json format |
|
2365
|
|
|
if ( false !== $output ) { |
|
2366
|
|
|
if ( is_array( $output ) || is_object( $output ) ) |
|
2367
|
|
|
wp_send_json( $output ); |
|
2368
|
|
|
else |
|
2369
|
|
|
echo $output; |
|
2370
|
|
|
} |
|
2371
|
|
|
else |
|
2372
|
|
|
pods_error( 'There was a problem with your request.' ); |
|
2373
|
|
|
|
|
2374
|
|
|
die(); // KBAI! |
|
|
|
|
|
|
2375
|
|
|
} |
|
2376
|
|
|
|
|
2377
|
|
|
/** |
|
2378
|
|
|
* Profiles the Pods configuration |
|
2379
|
|
|
* |
|
2380
|
|
|
* @param null|string|array $pod. Optional. Which Pod(s) to get configuration for. Can be a the name of one Pod, or an array of names of Pods, or null, which is the default, to profile all Pods. |
|
|
|
|
|
|
2381
|
|
|
* @param bool $full_field_info Optional. If true all info about each field is returned. If false, which is the default only name and type, will be returned. |
|
2382
|
|
|
* |
|
2383
|
|
|
* @return array |
|
2384
|
|
|
* |
|
2385
|
|
|
* @since 3.0.0 |
|
2386
|
|
|
*/ |
|
2387
|
|
|
function configuration( $pod = null, $full_field_info = false ){ |
|
|
|
|
|
|
2388
|
|
|
$api = pods_api(); |
|
2389
|
|
|
|
|
2390
|
|
|
if ( is_null( $pod ) ) { |
|
|
|
|
|
|
2391
|
|
|
$the_pods = $api->load_pods(); |
|
2392
|
|
|
} |
|
2393
|
|
|
elseif( is_array( $pod ) ) { |
|
2394
|
|
|
foreach ( $pod as $p ) { |
|
2395
|
|
|
$the_pods[] = $api->load_pod( $p ); |
|
|
|
|
|
|
2396
|
|
|
} |
|
2397
|
|
|
} |
|
2398
|
|
|
else { |
|
2399
|
|
|
$the_pods[] = $api->load_pod( $pod ); |
|
|
|
|
|
|
2400
|
|
|
} |
|
2401
|
|
|
|
|
2402
|
|
|
foreach( $the_pods as $pod ) { |
|
|
|
|
|
|
2403
|
|
|
$configuration[ $pod[ 'name' ] ] = array( |
|
|
|
|
|
|
2404
|
|
|
'name' => $pod['name'], |
|
2405
|
|
|
'ID' => $pod[ 'id' ], |
|
2406
|
|
|
'storage' => $pod[ 'storage' ], |
|
2407
|
|
|
'fields' => $pod[ 'fields' ], |
|
2408
|
|
|
); |
|
2409
|
|
|
} |
|
2410
|
|
|
|
|
2411
|
|
|
if ( ! $full_field_info ) { |
|
2412
|
|
|
foreach ( $the_pods as $pod ) { |
|
|
|
|
|
|
2413
|
|
|
$fields = $configuration[ $pod['name'] ][ 'fields' ]; |
|
|
|
|
|
|
2414
|
|
|
unset( $configuration[ $pod['name'] ][ 'fields' ] ); |
|
2415
|
|
|
foreach ( $fields as $field ) { |
|
2416
|
|
|
$info = array ( |
|
2417
|
|
|
'name' => $field[ 'name' ], |
|
2418
|
|
|
'type' => $field[ 'type' ], |
|
2419
|
|
|
); |
|
2420
|
|
|
|
|
2421
|
|
|
if ( $info[ 'type' ] === 'pick' ) { |
|
2422
|
|
|
$info[ 'pick_object' ] = $field[ 'pick_object' ]; |
|
2423
|
|
|
if ( isset ( $field[ 'pick_val' ] ) && $field[ 'pick_val' ] !== '' ) { |
|
2424
|
|
|
$info[ 'pick_val' ] = $field[ 'pick_val' ]; |
|
2425
|
|
|
} |
|
2426
|
|
|
} |
|
2427
|
|
|
|
|
2428
|
|
|
if ( is_array( $info ) ) { |
|
2429
|
|
|
$configuration[ $pod[ 'name' ] ][ 'fields' ][ $field[ 'name' ] ] = $info; |
|
2430
|
|
|
} |
|
2431
|
|
|
|
|
2432
|
|
|
unset( $info ); |
|
2433
|
|
|
|
|
2434
|
|
|
} |
|
2435
|
|
|
|
|
2436
|
|
|
} |
|
2437
|
|
|
|
|
2438
|
|
|
} |
|
2439
|
|
|
|
|
2440
|
|
|
if ( is_array ( $configuration ) ) { |
|
2441
|
|
|
return $configuration; |
|
2442
|
|
|
|
|
2443
|
|
|
} |
|
2444
|
|
|
|
|
2445
|
|
|
} |
|
2446
|
|
|
|
|
2447
|
|
|
/** |
|
2448
|
|
|
* Build UI for extending REST API, if makes sense to do so. |
|
2449
|
|
|
* |
|
2450
|
|
|
* @todo maybe disable if default routes don't exist since WP < 4.5 and plugin isn't installed? |
|
2451
|
|
|
* |
|
2452
|
|
|
* @since 2.5.6 |
|
2453
|
|
|
* |
|
2454
|
|
|
* @access protected |
|
2455
|
|
|
*/ |
|
2456
|
|
|
protected function rest_admin() { |
|
2457
|
|
|
if( function_exists( 'register_api_field' ) ) { |
|
2458
|
|
|
add_filter( 'pods_admin_setup_edit_field_options', array( $this, 'add_rest_fields_to_field_editor' ), 12, 2 ); |
|
2459
|
|
|
add_filter( 'pods_admin_setup_edit_options', array( $this, 'add_rest_settings_tab_fields' ), 12, 2 ); |
|
2460
|
|
|
add_filter( 'pods_admin_setup_edit_tabs', array( $this, 'add_rest_settings_tab' ), 12, 2 ); |
|
2461
|
|
|
add_filter( 'pods_admin_setup_edit_field_tabs', array( $this, 'add_rest_field_tab' ), 12 ); |
|
2462
|
|
|
} |
|
2463
|
|
|
|
|
2464
|
|
|
} |
|
2465
|
|
|
|
|
2466
|
|
|
/** |
|
2467
|
|
|
* Check if Pod type <em>could</em> extend core REST API response |
|
2468
|
|
|
* |
|
2469
|
|
|
* @since 2.5.6 |
|
2470
|
|
|
* |
|
2471
|
|
|
* @access protected |
|
2472
|
|
|
* |
|
2473
|
|
|
* @param array $pod |
|
2474
|
|
|
* |
|
2475
|
|
|
* @return bool |
|
2476
|
|
|
*/ |
|
2477
|
|
|
protected function restable_pod( $pod ) { |
|
2478
|
|
|
$type = $pod[ 'type' ]; |
|
2479
|
|
|
if( in_array( $type, array( |
|
2480
|
|
|
'post_type', |
|
2481
|
|
|
'user', |
|
2482
|
|
|
'taxonomy' |
|
2483
|
|
|
) |
|
2484
|
|
|
) |
|
2485
|
|
|
) { |
|
2486
|
|
|
return true; |
|
2487
|
|
|
|
|
2488
|
|
|
} |
|
2489
|
|
|
|
|
2490
|
|
|
} |
|
2491
|
|
|
|
|
2492
|
|
|
|
|
2493
|
|
|
/** |
|
2494
|
|
|
* Add a rest api tab. |
|
2495
|
|
|
* |
|
2496
|
|
|
* @since 0.1.0 |
|
2497
|
|
|
* |
|
2498
|
|
|
* @param array $tabs |
|
2499
|
|
|
* @param array $pod |
|
2500
|
|
|
* |
|
2501
|
|
|
* @return array |
|
2502
|
|
|
*/ |
|
2503
|
|
|
public function add_rest_settings_tab( $tabs, $pod ) { |
|
2504
|
|
|
if ( $this->restable_pod( $pod ) ) { |
|
2505
|
|
|
$tabs[ 'rest-api' ] = __( 'REST API', 'pods' ); |
|
2506
|
|
|
} |
|
2507
|
|
|
|
|
2508
|
|
|
return $tabs; |
|
2509
|
|
|
|
|
2510
|
|
|
} |
|
2511
|
|
|
|
|
2512
|
|
|
/** |
|
2513
|
|
|
* Populate REST API tab. |
|
2514
|
|
|
* |
|
2515
|
|
|
* @since 0.1.0 |
|
2516
|
|
|
* |
|
2517
|
|
|
* @param array $options |
|
2518
|
|
|
* @param array $pod |
|
2519
|
|
|
* |
|
2520
|
|
|
* @return array |
|
2521
|
|
|
*/ |
|
2522
|
|
|
public function add_rest_settings_tab_fields( $options, $pod ) { |
|
2523
|
|
|
if( $this->restable_pod( $pod ) ) { |
|
2524
|
|
|
$options[ 'rest-api' ] = array( |
|
2525
|
|
|
'rest_enable' => array( |
|
2526
|
|
|
'label' => __( 'Enable', 'pods' ), |
|
2527
|
|
|
'help' => __( 'Add REST API support for this Pod.', 'pods' ), |
|
2528
|
|
|
'type' => 'boolean', |
|
2529
|
|
|
'default' => '', |
|
2530
|
|
|
'dependency' => true, |
|
2531
|
|
|
), |
|
2532
|
|
|
'rest_base' => array( |
|
2533
|
|
|
'label' => __( 'Rest Base', 'pods' ), |
|
2534
|
|
|
'help' => __( 'This will form the url for the route.', 'pods' ), |
|
2535
|
|
|
'type' => 'text', |
|
2536
|
|
|
'default' => pods_v( 'name', $pod ), |
|
2537
|
|
|
'boolean_yes_label' => '', |
|
2538
|
|
|
'depends-on' => array( 'rest_enable' => true ), |
|
2539
|
|
|
), |
|
2540
|
|
|
'read_all' => array( |
|
2541
|
|
|
'label' => __( 'Show All Fields?', 'pods' ), |
|
2542
|
|
|
'help' => __( 'Show all fields in REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ), |
|
2543
|
|
|
'type' => 'boolean', |
|
2544
|
|
|
'default' => '', |
|
2545
|
|
|
'boolean_yes_label' => '', |
|
2546
|
|
|
'depends-on' => array( 'rest_enable' => true ), |
|
2547
|
|
|
), |
|
2548
|
|
|
'write_all' => array( |
|
2549
|
|
|
'label' => __( 'Allow All Fields To Be Update?', 'pods' ), |
|
2550
|
|
|
'help' => __( 'Allow all fields to be updated via the REST API. If unchecked fields must be enabled on a field by field basis.', 'pods' ), |
|
2551
|
|
|
'type' => 'boolean', |
|
2552
|
|
|
'default' => pods_v( 'name', $pod ), |
|
2553
|
|
|
'boolean_yes_label' => '', |
|
2554
|
|
|
'depends-on' => array( 'rest_enable' => true ), |
|
2555
|
|
|
) |
|
2556
|
|
|
|
|
2557
|
|
|
); |
|
2558
|
|
|
|
|
2559
|
|
|
} |
|
2560
|
|
|
|
|
2561
|
|
|
return $options; |
|
2562
|
|
|
|
|
2563
|
|
|
} |
|
2564
|
|
|
|
|
2565
|
|
|
/** |
|
2566
|
|
|
* Add a REST API section to advanced tab of field editor. |
|
2567
|
|
|
* |
|
2568
|
|
|
* @since 2.5.6 |
|
2569
|
|
|
* |
|
2570
|
|
|
* @param array $options |
|
2571
|
|
|
* @param array $pod |
|
2572
|
|
|
* |
|
2573
|
|
|
* @return array |
|
2574
|
|
|
*/ |
|
2575
|
|
|
public function add_rest_fields_to_field_editor( $options, $pod ) { |
|
2576
|
|
|
|
|
2577
|
|
|
if( $this->restable_pod( $pod ) ) { |
|
2578
|
|
|
$options[ 'rest' ][ __( 'Read/ Write', 'pods' ) ] = |
|
2579
|
|
|
array( |
|
2580
|
|
|
'rest_read' => array( |
|
2581
|
|
|
'label' => __( 'Read via REST API?', 'pods' ), |
|
2582
|
|
|
'help' => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ), |
|
2583
|
|
|
'type' => 'boolean', |
|
2584
|
|
|
'default' => '', |
|
2585
|
|
|
), |
|
2586
|
|
|
'rest_write' => array( |
|
2587
|
|
|
'label' => __( 'Write via REST API?', 'pods' ), |
|
2588
|
|
|
'help' => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ), |
|
2589
|
|
|
'type' => 'boolean', |
|
2590
|
|
|
'default' => '', |
|
2591
|
|
|
), |
|
2592
|
|
|
); |
|
2593
|
|
|
$options[ 'rest' ][ __( 'Relationship Field Options', 'pods' ) ] = |
|
2594
|
|
|
array( |
|
2595
|
|
|
'rest_pick_response' => array( |
|
2596
|
|
|
'label' => __( 'Response Type', 'pods' ), |
|
2597
|
|
|
'help' => __( 'Should this field be readable via the REST API? You must enable REST API support for this Pod.', 'pods' ), |
|
2598
|
|
|
'type' => 'pick', |
|
2599
|
|
|
'default' => 'array', |
|
2600
|
|
|
'depends-on' => array( 'type' => 'pick' ), |
|
2601
|
|
|
'data' => array( |
|
2602
|
|
|
'array' => __( 'Full', 'pods' ), |
|
2603
|
|
|
'id' => __( 'ID only', 'pods' ), |
|
2604
|
|
|
'name' => __( 'Name', 'pods' ) |
|
2605
|
|
|
|
|
2606
|
|
|
), |
|
2607
|
|
|
), |
|
2608
|
|
|
'rest_pick_depth' => array( |
|
2609
|
|
|
'label' => __( 'Depth', 'pods' ), |
|
2610
|
|
|
'help' => __( 'How far to traverse relationships in response', 'pods' ), |
|
2611
|
|
|
'type' => 'number', |
|
2612
|
|
|
'default' => '2', |
|
2613
|
|
|
'depends-on' => array( 'type' => 'pick' ), |
|
2614
|
|
|
|
|
2615
|
|
|
) |
|
2616
|
|
|
|
|
2617
|
|
|
); |
|
2618
|
|
|
|
|
2619
|
|
|
|
|
2620
|
|
|
} |
|
2621
|
|
|
|
|
2622
|
|
|
return $options; |
|
2623
|
|
|
|
|
2624
|
|
|
} |
|
2625
|
|
|
|
|
2626
|
|
|
/** |
|
2627
|
|
|
* Add REST field tab |
|
2628
|
|
|
* |
|
2629
|
|
|
* @since 2.5.6 |
|
2630
|
|
|
* |
|
2631
|
|
|
* @param array $tabs |
|
2632
|
|
|
* |
|
2633
|
|
|
* @return array |
|
2634
|
|
|
*/ |
|
2635
|
|
|
public function add_rest_field_tab( $tabs ) { |
|
2636
|
|
|
$tabs[ 'rest' ] = __( 'REST API', 'pods' ); |
|
2637
|
|
|
return $tabs; |
|
2638
|
|
|
} |
|
2639
|
|
|
|
|
2640
|
|
|
} |
|
2641
|
|
|
|