-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathwpcli.php
More file actions
85 lines (70 loc) · 1.87 KB
/
wpcli.php
File metadata and controls
85 lines (70 loc) · 1.87 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
82
83
84
85
<?php
/**
* PHPCompat_Command class
*
* @package WPEngine\PHPCompat
* @since 1.0.0
*/
require_once dirname( dirname( __FILE__ ) ) . '/load-files.php';
/**
* PHPCompat WP-CLI command.
*
* Test compatibility with different PHP versions.
*
* @since 1.0.0
*/
class PHPCompat_Command extends WP_CLI_Command {
/**
* Test compatibility with different PHP versions.
*
* ## EXAMPLES
*
* wp phpcompat 5.5 --scan=active
*/
function __invoke( $args, $assoc_args ) {
// Get the PHP test version.
$test_version = $args[0];
WP_CLI::log( 'Testing compatibility with PHP ' . $test_version . '.' );
// Add empty line.
WP_CLI::log( '' );
$root_dir = realpath( dirname( dirname( __FILE__ ) ) . '/' );
$wpephpc = new WPEPHPCompat( $root_dir );
$wpephpc->clean_after_scan();
$wpephpc->test_version = $test_version;
// Set scan type if 'scan' was passed in.
if ( isset( $assoc_args['scan'] ) && 'active' === $assoc_args['scan'] ) {
$wpephpc->only_active = 'yes';
}
$results = $wpephpc->start_test();
WP_CLI::log( $results );
$wpephpc->clean_after_scan();
delete_option( 'wpephpcompat.scan_results' );
if ( preg_match( '/([1-9][0-9]*) ERRORS?/i', $results ) ) {
WP_CLI::error( 'Your WordPress install is not compatible.' );
} else {
WP_CLI::success( 'Your WordPress install is compatible.' );
}
}
}
/**
* Using this for now since there are issues with the PHPDoc syntax.
* TODO: Use PHPDoc syntax.
*/
WP_CLI::add_command( 'phpcompat', 'PHPCompat_Command', array(
'shortdesc' => 'Test compatibility with different PHP versions.',
'synopsis' => array(
array(
'type' => 'positional',
'name' => 'version',
'optional' => false,
'multiple' => false,
),
array(
'type' => 'assoc',
'name' => 'scan',
'optional' => true,
'default' => 'active',
'options' => array( 'active', 'all' ),
),
),
));