-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaster-report.php
More file actions
81 lines (74 loc) · 2.2 KB
/
faster-report.php
File metadata and controls
81 lines (74 loc) · 2.2 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
<?php
namespace wpcampus\wpcli\commands;
use WP_CLI;
use function WP_CLI\Utils\format_items;
/**
* Plugin Name: site-report2
* Plugin URI: https://gilzow.com/site-report2
* Description: Generates a custom multisite report
* Author: Paul Gilzow
* Author URI: https://gilzow.com/
* Text Domain: site-report2
* Domain Path: /languages
* Version: 0.1.0
*
* @package SITE_REPORT_2
*/
if (! defined('WP_CLI')) {
return;
}
class SiteReporter
{
/**
* Generates a custom multiste report with selected metadata
*
* ## OPTIONS
* [--metadata=<value>]
* : a comma seperated list of meta_keys that we want included in the report
*
* [--format=<format>]
* : format to use for output
* ---
* default: table
* options
* - table
* - json
* - csv
* - yaml
* ---
*
* ## EXAMPLES
* # Generate a report
* $ wp site report --metadata=owner,division
*
* @param array $args
* @param array $assoc_args
* @return void
*/
public function __invoke(array $args, array $assoc_args): void
{
$defaultKeys = array_fill_keys(['blog_id','domain','registered','last_updated'],'');
$arySites = get_sites();
$sites = [];
foreach ($arySites as $siteid=>$site) {
$site = array_intersect_key((array)$site,$defaultKeys);
if (isset($assoc_args['metadata']) && !empty($assoc_args['metadata'])) {
$baseKeys = array_fill_keys(explode(',',$assoc_args['metadata']),'');
$siteMeta = array_merge($baseKeys,array_intersect_key(array_map(static function ($item){
return reset($item);
},get_site_meta($site['blog_id'])),$baseKeys));
$site += $siteMeta;
}
$sites[$siteid] = $site;
}
format_items($assoc_args['format'],$sites,array_keys($sites[0]));
WP_CLI::success("Report Generated.");
}
}
WP_CLI::add_command("site report2",SiteReporter::class, [
'before_invoke' => function() {
if (!is_multisite()) {
WP_CLI::error("This is not a multisite!");
}
}
]);