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

494 lines 11.5 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 $columns = (array) jltwp_adminify_admin_columns_data( $post_type );
242 update_option( '_adminify_admin_columns_' . $post_type, $columns );
243 return $columns;
244 }
245
246 /*
247 * Get saved version of both visible & non visible columns of a specific taxonomy
248 */
249 function adminify__get_taxonomy_all_columns( $taxonomy ) {
250 return (array) get_option( '_adminify_admin_taxonomy_columns_' . $taxonomy, [] );
251 }
252
253 /*
254 * Get both visible & non visible columns of a specific taxonomy
255 */
256 function _adminify__get_taxonomy_all_columns( $taxonomy ) {
257 $columns = (array) jltwp_adminify_admin_columns_data( 'edit-' . $taxonomy );
258 update_option( '_adminify_admin_taxonomy_columns_' . $taxonomy, $columns );
259 return $columns;
260 }
261
262 /*
263 * Get visible columns of all post_types
264 */
265 function adminify__get_post_types_columns() {
266
267 $post_types = adminify__get_post_types();
268
269 $post_types_columns = [];
270
271 foreach ( $post_types as $post_type => $post_type_title ) {
272
273 $column_data = [
274 'name' => $post_type,
275 'title' => $post_type_title,
276 'columns' => _adminify__get_post_type_all_columns( $post_type ),
277 'display_columns' => adminify_prepare_post_type_column_meta( $post_type ),
278 'fields' => adminify_get_post_type_fields( $post_type ),
279 ];
280
281 if ( ! in_array($post_type, ['post', 'page']) ) {
282 $column_data['is_pro'] = true;
283 }
284
285 $post_types_columns[] = $column_data;
286
287 }
288
289 return $post_types_columns;
290
291 }
292
293 function _adminify__get_taxonomy_post_type( $taxonomy ) {
294
295 $tax = get_taxonomy( $taxonomy );
296
297 if ( $tax && !empty($tax->object_type) ) {
298 return $tax->object_type[0];
299 }
300
301 return '';
302
303 }
304
305 /*
306 * Get visible columns of all taxonomies
307 */
308 function adminify__get_taxonomies_columns() {
309
310 $taxonomies = adminify__get_taxonomies();
311
312 $taxonomies_columns = [];
313
314 foreach ( $taxonomies as $taxonomy => $taxonomy_title ) {
315
316 $column_data = [
317 'name' => $taxonomy,
318 'title' => $taxonomy_title,
319 'object_type' => _adminify__get_taxonomy_post_type( $taxonomy ),
320 'columns' => _adminify__get_taxonomy_all_columns( $taxonomy ),
321 'display_columns' => adminify_prepare_taxonomy_column_meta( $taxonomy ),
322 'fields' => adminify_get_taxonomy_fields( $taxonomy )
323 ];
324
325 if ( ! in_array($taxonomy, ['category', 'post_tag']) ) {
326 $column_data['is_pro'] = true;
327 }
328
329 $taxonomies_columns[] = $column_data;
330
331 }
332
333 return $taxonomies_columns;
334
335 }
336
337 /*
338 * Get specific column meta data
339 */
340 function adminify_get_column_meta( $post_type, $column, $column_label ) {
341
342 $column_default_meta = [
343 'label' => $column_label,
344 'width' => [
345 'value' => 'auto',
346 'unit' => '%'
347 ],
348 'fields' => ['type', 'label', 'width']
349 ];
350
351 /*
352 * You can extend the fields based on post type and column
353 * Make sure you have added the new field type in this function: adminify_get_post_type_fields
354 */
355
356 // if ( $post_type == 'page' && $column == 'taxonomy-folder' ) {
357 // $column_default_meta['fields'][] = 'new';
358 // }
359
360 $data = (array) get_option( '_adminify_admin_columns_meta_data', [] );
361
362 $column_meta = [];
363
364 if ( !empty($data) && !empty($data[$post_type]) && !empty($data[$post_type][$column]) ) {
365 $column_meta = $data[$post_type][$column];
366 }
367
368 return array_merge_recursive( $column_default_meta, $column_meta );
369
370 }
371
372 /*
373 * Get post_type columns meta
374 */
375 function adminify_prepare_post_type_column_meta( $post_type ) {
376
377 $columns_meta = get_option( '_adminify_admin_columns_meta_' . $post_type, null );
378
379 if ( ! is_null($columns_meta) ) return (array) $columns_meta;
380
381 $columns = adminify__get_post_type_all_columns( $post_type );
382
383 $_columns = [];
384
385 foreach ( $columns as $column => $column_label ) {
386 $_columns[] = [ 'name' => $column ] + (array) adminify_get_column_meta( $post_type, $column, $column_label );
387 }
388
389 return $_columns;
390
391 }
392
393 /*
394 * Get taxonomy columns meta
395 */
396 function adminify_prepare_taxonomy_column_meta( $taxonomy ) {
397
398 $columns_meta = get_option( '_adminify_admin_taxonomy_columns_meta_' . $taxonomy, null );
399
400 if ( ! is_null($columns_meta) ) return (array) $columns_meta;
401
402 $columns = adminify__get_taxonomy_all_columns( $taxonomy );
403
404 $_columns = [];
405
406 foreach ( $columns as $column => $column_label ) {
407 $_columns[] = [ 'name' => $column ] + (array) adminify_get_column_meta( $taxonomy, $column, $column_label );
408 }
409
410 return $_columns;
411
412 }
413
414 /*
415 * Get post_type fields
416 */
417 function adminify_get_post_type_fields( $post_type ) {
418
419 $columns = array_map( 'sanitize_text_field', _adminify__get_post_type_all_columns($post_type) );
420
421 return [
422 [
423 'id' => 'type',
424 'type' => 'select',
425 'title' => 'Column Type',
426 'chosen' => true,
427 'placeholder' => 'Select Column Type',
428 'options' => $columns,
429 ],
430 [
431 'id' => 'label',
432 'type' => 'text',
433 'title' => 'Label',
434 ],
435 [
436 'id' => 'width',
437 'type' => 'slider',
438 'title' => 'Width',
439 'unit' => '%'
440 ],
441
442 /*
443 * Register additional fields
444 */
445 // [
446 // 'id' => 'new',
447 // 'type' => 'text',
448 // 'title' => 'New'
449 // ]
450
451 ];
452
453 }
454
455 /*
456 * Get taxonomy fields
457 */
458 function adminify_get_taxonomy_fields( $taxonomy ) {
459
460 $columns = array_map( 'sanitize_text_field', _adminify__get_taxonomy_all_columns( $taxonomy ) );
461
462 return [
463 [
464 'id' => 'type',
465 'type' => 'select',
466 'title' => 'Column Type',
467 'chosen' => true,
468 'placeholder' => 'Select Column Type',
469 'options' => $columns,
470 ],
471 [
472 'id' => 'label',
473 'type' => 'text',
474 'title' => 'Label',
475 ],
476 [
477 'id' => 'width',
478 'type' => 'slider',
479 'title' => 'Width',
480 'unit' => '%'
481 ],
482
483 /*
484 * Register additional fields
485 */
486 // [
487 // 'id' => 'new',
488 // 'type' => 'text',
489 // 'title' => 'New'
490 // ]
491
492 ];
493
494 }