-
Notifications
You must be signed in to change notification settings - Fork 0
/
site-report-inc.php
80 lines (70 loc) · 2.12 KB
/
site-report-inc.php
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
<?php
namespace gilzow\wpcli\commands;
use \WP_CLI, \JsonException;
use function WP_CLI\Utils\make_progress_bar;
use function WP_CLI\Utils\format_items;
if ( ! defined('WP_CLI') ) {
return;
}
/**
* Plugin Name: site-report
* Plugin URI: https://gilzow.com/site-report
* Description:
* Author: Paul Gilzow
* Author URI: https://gilzow.com/
* Text Domain: site-report
* Domain Path: /languages
* Version: 0.1.0
*
* @package SITE_REPORT
*/
class SiteReport
{
/**
* Returns a multisite report with extended data via metadata
* ## OPTIONS
*
* [--metadata=<values>]
* : Comma-separated list of metadata values to include in the report
*
* [--format=<format>]
* : format to use for output
* ---
* default: table
* options
* - table
* - json
* - csv
* - yaml
* ---
*
* ## EXAMPLES
*
* # Display a multisite report
* $ wp site report --metadata=owner,ticketnumber,division
*
* @param array $args
* @param array $assoc_args
* @return void
*/
public function __invoke(array $args, array $assoc_args) : void {
if(isset($assoc_args['metadata']) && !empty($assoc_args['metadata'])) {
$baseKeys = array_fill_keys(explode(',',$assoc_args['metadata']),'');
// foreach ($sites as $key=>$site) {
// # wp site meta list 4 --keys=owner,division --fields=meta_key,meta_value
// $command = sprintf('site meta list %d --keys=%s --fields=meta_key,meta_value --format=json',$site['blog_id'],$assoc_args['metadata']);
//
//
// //now we need to merge the returned metadata with the base set to make sure all sites have an entry
// $reformatted = array_merge($baseKeys,array_column($siteMeta,'meta_value','meta_key'));
// }
}
}
}
WP_CLI::add_command('site report',SiteReport::class,array(
'before_invoke' => static function(){
if ( ! is_multisite() ) {
WP_CLI::error( 'This is not a multisite installation.' );
}
},
));