Feature #16797 » theme-usage-report.php
1 |
<?php
|
---|---|
2 |
|
3 |
global $wpdb; |
4 |
|
5 |
$themes = wp_get_themes(); |
6 |
|
7 |
$data = []; |
8 |
|
9 |
$allowed_themes = (array) get_site_option( 'allowedthemes' ); |
10 |
|
11 |
foreach ( $themes as $theme_slug => $theme_data ) { |
12 |
$count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM wp_network_themes WHERE stylesheet = %s", $theme_slug ) ); |
13 |
|
14 |
$is_allowed = isset( $allowed_themes[ $theme_slug ] ); |
15 |
|
16 |
$data[] = [ |
17 |
0 => $theme_slug, |
18 |
1 => $theme_data->name, |
19 |
2 => $count, |
20 |
3 => (int) $is_allowed, |
21 |
];
|
22 |
}
|
23 |
|
24 |
$now = date( 'Y-m-d' ); |
25 |
$csv = ABSPATH . '/theme-usage-' . $now . '.csv'; |
26 |
|
27 |
$h = fopen( $csv, 'w' ); |
28 |
|
29 |
fputcsv( |
30 |
$h, |
31 |
array( |
32 |
'Slug', |
33 |
'Name', |
34 |
'Site Count', |
35 |
'Enabled?', |
36 |
)
|
37 |
);
|
38 |
|
39 |
foreach ( $data as $theme_stats ) { |
40 |
fputcsv( $h, $theme_stats ); |
41 |
}
|
42 |
|
43 |
fclose( $h ); |
44 |
|
45 |
print_r( $data ); |