PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.2.4.5
Adminify – White Label, Admin Menu Editor, Login Customizer v3.2.4.5
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Modules / AdminColumns / AdminColumnsData.php

AdminColumnsData.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.2.4.5, at Inc/Modules/AdminColumns/AdminColumnsData.php

619 lines 15.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // define all helper functions to create list table
4 function jltwp_adminify_admin_columns_create_post_table($screen_id)
5 {
6 require_once ABSPATH . 'wp-admin/includes/class-wp-posts-list-table.php';
7
8 return new WP_Posts_List_Table(['screen' => $screen_id]);
9 }
10
11 function jltwp_adminify_admin_columns_create_user_table($screen_id)
12 {
13 require_once ABSPATH . 'wp-admin/includes/class-wp-users-list-table.php';
14
15 return new WP_Users_List_Table(['screen' => $screen_id]);
16 }
17
18 function jltwp_adminify_admin_columns_create_comment_table($screen_id)
19 {
20 require_once ABSPATH . 'wp-admin/includes/class-wp-comments-list-table.php';
21
22 $table = new WP_Comments_List_Table(['screen' => $screen_id]);
23
24 // Since 4.4 the `floated_admin_avatar` filter is added in the constructor of the `\WP_Comments_List_Table` class.
25 remove_filter('comment_author', [$table, 'floated_admin_avatar']);
26
27 return $table;
28 }
29
30 function jltwp_adminify_admin_columns_create_media_table($screen_id)
31 {
32 require_once ABSPATH . 'wp-admin/includes/class-wp-media-list-table.php';
33
34 return new WP_Media_List_Table(['screen' => $screen_id]);
35 }
36
37 function jltwp_adminify_admin_columns_create_taxonomy_table($screen_id)
38 {
39 require_once ABSPATH . 'wp-admin/includes/class-wp-terms-list-table.php';
40
41 return new WP_Terms_List_Table(['screen' => $screen_id]);
42 }
43 function jltwp_adminify_admin_columns_create_network_user_table($screen_id)
44 {
45 require_once ABSPATH . 'wp-admin/includes/class-wp-ms-users-list-table.php';
46
47 return new WP_MS_Users_List_Table(['screen' => $screen_id]);
48 }
49
50
51
52 // get the columns list of any post or users, comments etc.
53 function jltwp_adminify_admin_columns_data($type)
54 {
55 // $type can be post, page, product, user, shop_order, shop_coupon, 'edit-comments', 'users', 'upload'
56
57 $builtin_non_posttype_data = ['users', 'edit-comments', 'upload'];
58 $table = '';
59
60 if (in_array($type, $builtin_non_posttype_data)) {
61 switch ($type) {
62 case 'users':
63 $table = jltwp_adminify_admin_columns_create_user_table($type);
64 break;
65 case 'edit-comments':
66 $table = jltwp_adminify_admin_columns_create_comment_table($type);
67 break;
68 case 'upload':
69 $table = jltwp_adminify_admin_columns_create_media_table($type);
70 break;
71 }
72 } else {
73 $type_post = post_type_exists($type);
74 $type_tax = taxonomy_exists(str_replace('edit-', '', $type));
75
76 if ($type_post) {
77 $table = jltwp_adminify_admin_columns_create_post_table($type); // for all kind of post_type
78 }
79 if ($type_tax) {
80 $table = jltwp_adminify_admin_columns_create_taxonomy_table($type); // for all kind of taxonomy
81 }
82 }
83
84 // handle woocommerce
85 if (function_exists('WC')) {
86 switch ($type) {
87 case 'product':
88 include_once dirname(WC_PLUGIN_FILE) . '/includes/admin/list-tables/class-wc-admin-list-table-products.php';
89 new WC_Admin_List_Table_Products();
90 break;
91 case 'shop_order':
92 include_once dirname(WC_PLUGIN_FILE) . '/includes/admin/list-tables/class-wc-admin-list-table-orders.php';
93 new WC_Admin_List_Table_Orders();
94 break;
95 case 'shop_coupon':
96 include_once dirname(WC_PLUGIN_FILE) . '/includes/admin/list-tables/class-wc-admin-list-table-coupons.php';
97 new WC_Admin_List_Table_Coupons();
98 break;
99 }
100 }
101
102 $col_names = [];
103
104 if ($table instanceof WP_List_Table) {
105 $col_names = $table->get_columns();
106 if (!empty($col_names) && array_key_exists('cb', $col_names)) {
107 unset($col_names['cb']);
108 }
109 }
110
111 return (array) $col_names;
112 }
113
114 // add_action('current_screen', 'jltwp_adminify_admin_columns_data', 99);
115
116
117 function adminify_post_types()
118 {
119 $sections = [];
120
121 $update_column_settings = get_option('_wpadminify_admin_columns_settings');
122
123 foreach ($update_column_settings as $p => $post_type) {
124 if ($post_type == 'attachment') {
125 continue;
126 }
127
128 $defaults = [];
129
130 foreach ($post_type as $column => $column_label) {
131 $column_meta = adminify_get_column_meta($post_type, $column, $column_label);
132
133 $defaults[] = [
134 'type' => $column,
135 'label' => $column_label,
136 'width' => $column_meta['width'],
137 ];
138 }
139
140 $sections[] = [
141 'title' => WPAdminify\Inc\Utils::id_to_string($p),
142 'fields' => [
143 [
144 'id' => 'admin-columns-group-' . $p,
145 'type' => 'group',
146 'title' => '',
147 'fields' => [
148
149 'field_type' => [
150 'id' => 'field_type',
151 'type' => 'select',
152 'title' => 'Column Type',
153 'chosen' => true,
154 'placeholder' => 'Select Column Type',
155 'options' => [
156 'title' => esc_html__('Title', 'adminify'),
157 'author' => esc_html__('Author', 'adminify'),
158 'categories' => esc_html__('Categories', 'adminify'),
159 'tags' => esc_html__('Tags', 'adminify'),
160 'comments' => esc_html__('Comments', 'adminify'),
161 'date' => esc_html__('Date', 'adminify'),
162 'id' => esc_html__('ID', 'adminify'),
163 ],
164 ],
165
166 'label' => [
167 'id' => 'label',
168 'type' => 'text',
169 'title' => esc_html__('Label', 'adminify'),
170 ],
171
172 'width' => [
173 'id' => 'width',
174 'type' => 'slider',
175 'title' => esc_html__('Width', 'adminify'),
176 'unit' => '%',
177 ],
178
179 ],
180
181 'default' => $defaults,
182
183 ],
184 ],
185 ];
186 }
187
188 return $sections;
189 }
190
191
192
193 /*
194 * Get registered post_types
195 */
196 function adminify__get_post_types()
197 {
198 $post_types = [];
199
200 foreach (WPAdminify\Inc\Utils::get_post_types() as $post_type) {
201 if ($post_type->name == 'attachment') {
202 continue;
203 }
204
205 $post_types[$post_type->name] = $post_type->labels->singular_name;
206 }
207
208 return $post_types;
209 }
210
211 /*
212 * Get registered post_types
213 */
214 function adminify__get_taxonomies()
215 {
216 $taxonomies = [];
217
218 foreach (WPAdminify\Inc\Utils::get_taxonomies() as $taxonomy) {
219 $taxonomies[$taxonomy->name] = $taxonomy->labels->singular_name;
220 }
221
222 return $taxonomies;
223 }
224
225 /*
226 * Get saved version of both visible & non visible columns of a specific post_type
227 */
228 function adminify__get_post_type_all_columns($post_type)
229 {
230 return (array) get_option('_adminify_admin_columns_' . $post_type, []);
231 }
232
233 /*
234 * Get both visible & non visible columns of a specific post_type
235 */
236 function _adminify__get_post_type_all_columns($post_type)
237 {
238 $column_groups = [
239 [
240 'group' => esc_html__('Default', 'adminify'),
241 'options' => (array) jltwp_adminify_admin_columns_data($post_type),
242 ],
243 ];
244
245 // Set Default Columns for First Installation
246 update_option('_adminify_admin_columns_' . $post_type, $column_groups);
247
248 // Added custom taxonomy support
249 $taxonomies = get_taxonomies(['object_type' => [$post_type]], 'objects');
250 $taxonomies = wp_list_pluck($taxonomies, 'label', 'name');
251 $taxonomy_columns = [];
252 if (!empty($taxonomies)) {
253 foreach ($taxonomies as $tax_name => $tax_label) {
254
255 // Skip the default category & tag for post
256 if ($post_type == 'post' && ($tax_name == 'category' || $tax_name == 'post_tag')) {
257 continue;
258 }
259
260 $_tax_name = 'taxonomy-' . $tax_name;
261 if (!in_array($_tax_name, $taxonomy_columns)) {
262 $taxonomy_columns[$_tax_name] = $tax_label;
263 }
264 }
265 }
266
267 $column_groups[] = [
268 'group' => esc_html__('Taxonomy', 'adminify'),
269 'options' => $taxonomy_columns,
270 ];
271
272 $custom_admin_columns = adminify_get_custom_admin_columns();
273 $_custom_admin_columns = [];
274
275 foreach ($custom_admin_columns as $column) {
276 $_custom_admin_columns[$column['name']] = $column['label'];
277 }
278
279 $column_groups[] = [
280 'group' => esc_html__('Custom', 'adminify'),
281 'options' => $_custom_admin_columns,
282 ];
283
284 $acf_fields = WPAdminify\Inc\Modules\AdminColumns\AdminColumns::get_acf_fields($post_type);
285 if (!empty($acf_fields)) {
286 $column_groups[] = [
287 'group' => esc_html__('ACF', 'adminify'),
288 'options' => $acf_fields,
289 ];
290 }
291
292 $pods_fields = WPAdminify\Inc\Modules\AdminColumns\AdminColumns::get_pods_fields($post_type);
293 if (!empty($pods_fields)) {
294 $column_groups[] = [
295 'group' => esc_html__('Pods', 'adminify'),
296 'options' => $pods_fields,
297 ];
298 }
299
300 $column_groups[] = [
301 'title' => esc_html__('Function', 'adminify'),
302 'name' => 'function',
303 ];
304
305 $column_groups[] = [
306 'title' => esc_html__('Shortcode', 'adminify'),
307 'name' => 'shortcode',
308 ];
309
310 return $column_groups;
311 }
312
313 /*
314 * Get saved version of both visible & non visible columns of a specific taxonomy
315 */
316 function adminify__get_taxonomy_all_columns($taxonomy)
317 {
318 return (array) get_option('_adminify_admin_taxonomy_columns_' . $taxonomy, []);
319 }
320
321 /*
322 * Get both visible & non visible columns of a specific taxonomy
323 */
324 function _adminify__get_taxonomy_all_columns($taxonomy)
325 {
326 $columns = (array) jltwp_adminify_admin_columns_data('edit-' . $taxonomy);
327 update_option('_adminify_admin_taxonomy_columns_' . esc_attr($taxonomy), $columns);
328 return $columns;
329 }
330
331 /*
332 * Get visible columns of all post_types
333 */
334 function adminify__get_post_types_columns()
335 {
336 $post_types = adminify__get_post_types();
337
338 $post_types_columns = [];
339
340 foreach ($post_types as $post_type => $post_type_title) {
341 $column_data = [
342 'name' => $post_type,
343 'title' => $post_type_title,
344 'columns' => adminify_columns_group_to_options(_adminify__get_post_type_all_columns($post_type)),
345 'display_columns' => adminify_prepare_post_type_column_meta($post_type),
346 'fields' => adminify_get_post_type_fields($post_type),
347 ];
348
349 if (!in_array($post_type, ['post', 'page'])) {
350 $column_data['is_pro'] = true;
351 }
352
353 $post_types_columns[] = $column_data;
354 }
355
356 return $post_types_columns;
357 }
358
359 function _adminify__get_taxonomy_post_type($taxonomy)
360 {
361 $tax = get_taxonomy($taxonomy);
362
363 if ($tax && !empty($tax->object_type)) {
364 return $tax->object_type[0];
365 }
366
367 return '';
368 }
369
370 /*
371 * Get visible columns of all taxonomies
372 */
373 function adminify__get_taxonomies_columns()
374 {
375 $taxonomies = adminify__get_taxonomies();
376
377 $taxonomies_columns = [];
378
379 foreach ($taxonomies as $taxonomy => $taxonomy_title) {
380 $column_data = [
381 'name' => $taxonomy,
382 'title' => $taxonomy_title,
383 'object_type' => _adminify__get_taxonomy_post_type($taxonomy),
384 'columns' => _adminify__get_taxonomy_all_columns($taxonomy),
385 'display_columns' => adminify_prepare_taxonomy_column_meta($taxonomy),
386 'fields' => adminify_get_taxonomy_fields($taxonomy),
387 ];
388
389 if (!in_array($taxonomy, ['category', 'post_tag'])) {
390 $column_data['is_pro'] = true;
391 }
392
393 $taxonomies_columns[] = $column_data;
394 }
395
396 return $taxonomies_columns;
397 }
398
399 /*
400 * Get specific column meta data
401 */
402 function adminify_get_column_meta($post_type, $column, $column_label)
403 {
404 $column_default_meta = [
405 'label' => $column_label,
406 'width' => [
407 'value' => 'auto',
408 'unit' => '%',
409 ],
410 'fields' => ['type', 'label', 'width'],
411 ];
412
413 /*
414 * You can extend the fields based on post type and column
415 * Make sure you have added the new field type in this function: adminify_get_post_type_fields
416 */
417
418 // if ( $post_type == 'page' && $column == 'taxonomy-folder' ) {
419 // $column_default_meta['fields'][] = 'new';
420 // }
421
422 $data = (array) get_option('_adminify_admin_columns_meta_data', []);
423
424 $column_meta = [];
425
426 if (!empty($data) && !empty($data[$post_type]) && !empty($data[$post_type][$column])) {
427 $column_meta = $data[$post_type][$column];
428 }
429
430 return array_merge_recursive($column_default_meta, $column_meta);
431 }
432
433 function adminify_columns_validation($columns_meta)
434 {
435 foreach ($columns_meta as &$column_meta) {
436 $column_meta['label'] = wp_kses_post($column_meta['label']);
437 $column_meta['name'] = sanitize_key($column_meta['name']);
438 if (!empty($column_meta['width'])) {
439 $column_meta['width'] = array_map('sanitize_text_field', $column_meta['width']);
440 }
441 }
442 return $columns_meta;
443 }
444
445 /*
446 * Get post_type columns meta
447 */
448 function adminify_prepare_post_type_column_meta($post_type)
449 {
450 $columns_meta = get_option('_adminify_admin_columns_meta_' . $post_type, null);
451
452 if (!is_null($columns_meta)) {
453 $columns_meta = adminify_columns_validation($columns_meta);
454 return $columns_meta;
455 }
456
457 $columns = adminify_columns_group_to_options(adminify__get_post_type_all_columns($post_type));
458
459 $_columns = [];
460
461 foreach ($columns as $column => $column_label) {
462 $_columns[] = ['name' => $column] + (array) adminify_get_column_meta($post_type, $column, $column_label);
463 }
464
465 return $_columns;
466 }
467
468 /*
469 * Get taxonomy columns meta
470 */
471 function adminify_prepare_taxonomy_column_meta($taxonomy)
472 {
473 $columns_meta = get_option('_adminify_admin_taxonomy_columns_meta_' . $taxonomy, null);
474
475 if (!is_null($columns_meta)) {
476 $columns_meta = adminify_columns_validation($columns_meta);
477 return (array) $columns_meta;
478 }
479
480 $columns = adminify__get_taxonomy_all_columns($taxonomy);
481
482 $_columns = [];
483
484 foreach ($columns as $column => $column_label) {
485 $_columns[] = ['name' => $column] + (array) adminify_get_column_meta($taxonomy, $column, $column_label);
486 }
487
488 return $_columns;
489 }
490
491 /*
492 * Get post_type fields
493 */
494 function adminify_get_post_type_fields($post_type)
495 {
496 $columns = _adminify__get_post_type_all_columns($post_type);
497
498 return [
499 [
500 'id' => 'type',
501 'title' => esc_html__('Column Type', 'adminify'),
502 'chosen' => true,
503 'placeholder' => 'Select Column Type',
504 'options' => $columns,
505 ],
506 [
507 'id' => 'field_name',
508 'title' => esc_html__('Field Name', 'adminify'),
509 ],
510 [
511 'id' => 'function_name',
512 'title' => esc_html__('Function Name', 'adminify'),
513 ],
514 [
515 'id' => 'shortcode_name',
516 'title' => esc_html__('Shortcode Name', 'adminify'),
517 ],
518 [
519 'id' => 'label',
520 'title' => esc_html__('Label', 'adminify'),
521 ],
522 [
523 'id' => 'width',
524 'title' => esc_html__('Width', 'adminify'),
525 'unit' => '%',
526 ],
527
528 ];
529 }
530
531 /*
532 * Get taxonomy fields
533 */
534 function adminify_get_taxonomy_fields($taxonomy)
535 {
536 $columns = array_map('sanitize_text_field', _adminify__get_taxonomy_all_columns($taxonomy));
537
538 return [
539 [
540 'id' => 'type',
541 'type' => 'select',
542 'title' => esc_html__('Column Type', 'adminify'),
543 'chosen' => true,
544 'placeholder' => esc_html__('Select Column Type', 'adminify'),
545 'options' => $columns,
546 ],
547 [
548 'id' => 'label',
549 'type' => 'text',
550 'title' => esc_html__('Label', 'adminify'),
551 ],
552 [
553 'id' => 'width',
554 'type' => 'slider',
555 'title' => esc_html__('Width', 'adminify'),
556 'unit' => '%',
557 ],
558
559 /*
560 * Register additional fields
561 */
562 // [
563 // 'id' => 'new',
564 // 'type' => 'text',
565 // 'title' => 'New'
566 // ]
567
568 ];
569 }
570
571 function adminify_columns_group_to_options(array $data)
572 {
573 $_data = [];
574 foreach ($data as $group) {
575 if (!empty($group['group'])) {
576 $_data = array_merge($_data, $group['options']);
577 } else {
578 $_data[$group['name']] = $group['title'];
579 }
580 }
581 return $_data;
582 }
583
584 function adminify_get_custom_admin_columns()
585 {
586 return [
587 [
588 'name' => 'word_cound',
589 'label' => esc_html__('Word Count', 'adminify'),
590 'callback' => 'adminify_admin_column__word_count',
591 ],
592 [
593 'name' => 'permalink',
594 'label' => esc_html__('Permalink', 'adminify'),
595 'callback' => 'adminify_admin_column__permalink',
596 ],
597 [
598 'name' => 'status',
599 'label' => esc_html__('Status', 'adminify'),
600 'callback' => 'adminify_admin_column__status',
601 ],
602 ];
603 }
604
605 function adminify_admin_column__word_count($object_id)
606 {
607 return str_word_count(get_the_content($object_id));
608 }
609
610 function adminify_admin_column__permalink($object_id)
611 {
612 return get_the_permalink($object_id);
613 }
614
615 function adminify_admin_column__status($object_id)
616 {
617 return get_post_status($object_id);
618 }
619