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

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