PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.0.4
Adminify – White Label, Admin Menu Editor, Login Customizer v3.0.4
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.0.4, at Inc/Modules/AdminColumns/AdminColumnsData.php

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