-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolid-data-summary.php
More file actions
119 lines (103 loc) · 3.79 KB
/
solid-data-summary.php
File metadata and controls
119 lines (103 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Plugin Name: Solid Data Summary
* Description: Small plugin that displays a summary of your post types and taxonomies.
* Version: 1.0.0
* Author: Solid Digital
* Author URI: https://www.soliddigital.com
* License: GPLv2
* Text Domain: solid-data-summary
* Domain Path: /languages
*/
namespace solid_data_summary;
add_action('admin_menu', 'solid_data_summary\admin_menu');
function admin_menu() {
add_options_page( 'Solid Data Summary', 'Solid Data Summary', 'manage_options', 'solid-data-summary', 'solid_data_summary\admin_page' );
}
function admin_page() {
?>
<h1><?php _e('Solid Data Summary', 'solid-data-summary') ?></h1>
<?php
the_post_types_table();
the_taxonomies_table();
}
function the_post_types_table() {
$post_type_objects = get_post_types(array(), 'objects');
$post_types = array();
foreach($post_type_objects as $post_type_object) {
$counts = wp_count_posts($post_type_object->name);
$post_types[] = array(
'name' => $post_type_object->name,
'label' => $post_type_object->label,
'publish' => $counts->publish,
'draft' => $counts->draft
);
}
usort($post_types, function ($a, $b) {
if ($a['publish'] === $b['publish']) return 0;
return $a['publish'] > $b['publish'] ? -1 : 1;
});
?>
<h2><?php _e('Post Types', 'solid-data-summary') ?></h2>
<table>
<thead>
<tr>
<th><?php _e('Name', 'solid-data-summary') ?></th>
<th><?php _e('Label', 'solid-data-summary') ?></th>
<th><?php _e('Publish', 'solid-data-summary') ?></th>
<th><?php _e('Draft', 'solid-data-summary') ?></th>
</tr>
</thead>
<tbody>
<?php foreach($post_types as $post_type): ?>
<tr>
<td><?php echo esc_html($post_type['name']); ?></td>
<td><?php echo esc_html($post_type['label']); ?></td>
<td><?php echo esc_html($post_type['publish']); ?></td>
<td><?php echo esc_html($post_type['draft']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}
function the_taxonomies_table() {
$taxonomy_objects = get_taxonomies(array(), 'objects');
$taxonomies = array();
foreach($taxonomy_objects as $taxonomy_object) {
$count = wp_count_terms($taxonomy_object->name);
$taxonomies[] = array(
'name' => $taxonomy_object->name,
'label' => $taxonomy_object->label,
'object_type' => $taxonomy_object->object_type,
'count' => $count
);
}
usort($taxonomies, function ($a, $b) {
if ($a['count'] === $b['count']) return 0;
return $a['count'] > $b['count'] ? -1 : 1;
});
?>
<h2><?php _e('Taxonomies', 'solid-data-summary') ?></h2>
<table>
<thead>
<tr>
<th><?php _e('Name', 'solid-data-summary') ?></th>
<th><?php _e('Label', 'solid-data-summary') ?></th>
<th><?php _e('Object Type', 'solid-data-summary') ?></th>
<th><?php _e('Count', 'solid-data-summary') ?></th>
</tr>
</thead>
<tbody>
<?php foreach($taxonomies as $taxonomy): ?>
<tr>
<td><?php echo esc_html($taxonomy['name']); ?></td>
<td><?php echo esc_html($taxonomy['label']); ?></td>
<td><?php echo esc_html(join(', ', $taxonomy['object_type'])); ?></td>
<td><?php echo esc_html($taxonomy['count']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}