-
Notifications
You must be signed in to change notification settings - Fork 1
/
command.php
57 lines (48 loc) · 1.08 KB
/
command.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
<?php
/**
* Option Import for WP-CLI: Command script.
*
* @package wp-cli-option-import
*/
declare( strict_types=1 );
namespace Option_Import;
use \WP_CLI;
if ( ! class_exists( 'WP_CLI' ) ) {
return;
}
/**
* Imports a .yml file containing values to update to WordPress options.
*
* ## OPTIONS
*
* <file>
*
* The .yml file to import.
*
* ## EXAMPLES
*
* # Import a .yml file containing values to update to WordPress options.
* $ wp option import ~/config/.options.yml
* Success: Updated 2 of 4 options (2 skipped).
*
* @when after_wp_load
*/
WP_CLI::add_command( 'option import', function( array $args ) {
if ( ! isset( $args[0] ) ) {
WP_CLI::error( sprintf( 'Filename missing.' ) );
}
$file = realpath( $args[0] );
$updates = parse_yaml_file( $file );
if ( is_null( $updates ) ) {
WP_CLI::error( sprintf( 'Could not parse file %s', $args[0] ) );
}
list( $total, $passed, $failed, $skipped ) = bulk_update_options( $updates );
WP_CLI\Utils\report_batch_operation_results(
'option',
'updated',
$total,
$passed,
$failed,
$skipped
);
} );