-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpcli.php
62 lines (55 loc) · 1.33 KB
/
wpcli.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
<?php
class BetterExport_WPCLI_Command extends WP_CLI_Command {
/**
* Export data.
*
* ## OPTIONS
*
* --overwrite - Will overwrite export file, if it exists already.
* --stdout
*
* ## EXAMPLES
*
* wp betterexport export
* wp betterexport export --overwrite
* wp betterexport export --stdout
*
* @synopsis
*/
function export( $args, $assoc_args ) {
if ( isset( $assoc_args['stdout'] ) ) {
echo( betterExport() . "\n");
exit();
}
$filename = apply_filters( 'betterexport_export_filename', 'betterexport-' . time() . '.json' );
if ( !isset( $assoc_args['overwrite'] ) && file_exists( $filename ) ) {
WP_CLI::error( "File exists: " . $filename );
}
if (file_put_contents( $filename, betterExport() ) === false) {
WP_CLI::error( "Error writing to file: " . $filename );
}
WP_CLI::success( "Exported to file: " . $filename );
}
/**
* Import data.
*
* ## OPTIONS
*
* --stdin
*
* ## EXAMPLES
*
* wp betterexport import --stdin
*
* @synopsis
*/
function import( $args, $assoc_args ) {
if ( isset( $assoc_args[ 'stdin' ] ) ) {
betterImport(file_get_contents( "php://stdin" ));
WP_CLI::success( "Imported." );
} else {
WP_CLI::error( "No input." );
}
}
}
WP_CLI::add_command( 'betterexport', 'BetterExport_WPCLI_Command' );