-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsalt-command.php
More file actions
40 lines (32 loc) · 919 Bytes
/
salt-command.php
File metadata and controls
40 lines (32 loc) · 919 Bytes
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
<?php
/**
* Manage salts.
*
* @author Sebastiaan de Geus
*/
class Salts_Command extends WP_CLI_Command {
/**
* Generates salts to STDOUT or to a file
*
* @when before_wp_load
*
* @synopsis [--file=<foo>]
*
*/
function generate( $args, $assoc_args ) {
$api = 'https://api.wordpress.org/secret-key/1.1/salt/';
$data = file_get_contents( $api );
if ( isset( $assoc_args['file'] ) ) {
$file = $assoc_args['file'];
$output = '<?php' . PHP_EOL . PHP_EOL . $data . PHP_EOL;
if ( ! is_writable( $file ) )
WP_CLI::error('File is not writable or path is not correct: ' . $file );
if ( ! file_put_contents( $file, $output ) )
WP_CLI::error('could not write salts to: ' . $file );
WP_CLI::success('Added salts to: ' . $file );
return;
}
fwrite( STDOUT, $data );
}
}
WP_CLI::add_command( 'salts', 'Salts_Command' );