-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.php
More file actions
105 lines (85 loc) · 3.33 KB
/
cli.php
File metadata and controls
105 lines (85 loc) · 3.33 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
if ( ! defined( 'PLUGINS_PATH_TC_CLI' ) )
define( 'PLUGINS_PATH_TC_CLI', ABSPATH . 'wp-content/plugins/' );
function theme_check_active() {
return in_array( 'theme-check/theme-check.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
}
function themeforest_check_active() {
return in_array( 'themeforest-check/themeforest-check.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
}
// TODO: Themeforest flag support
if ( theme_check_active() ) {
include PLUGINS_PATH_TC_CLI . 'theme-check/main.php';
include PLUGINS_PATH_TC_CLI . 'theme-check/checkbase.php';
}
/**
* Implements example command.
*/
class ThemeCheckCli extends WP_CLI_Command {
function __construct() {
parent::__construct();
$this->fetcher = new \WP_CLI\Fetchers\Theme;
}
/**
* Prints a greeting.
*
* ## OPTIONS
*
* <name>
* : The name of the person to greet.
*
* ## EXAMPLES
*
* wp theme-check check twentyfifteen
*
* @synopsis <name> [--disable-themeforest]
*/
function check( $args, $assoc_args ) {
global $checkcount, $themechecks;
$theme = $this->fetcher->get_check( $args[0] );
$files = $theme->get_files( null, -1 );
$css = $php = $other = array();
if ( $files ) {
foreach( $files as $key => $filename ) {
if ( substr( $filename, -4 ) == '.php' ) {
$php[$filename] = php_strip_whitespace( $filename );
}
else if ( substr( $filename, -4 ) == '.css' ) {
$css[$filename] = file_get_contents( $filename );
}
else {
$other[$filename] = ( ! is_dir($filename) ) ? file_get_contents( $filename ) : '';
}
}
// run the checks
$success = run_themechecks($php, $css, $other);
foreach ( $themechecks as $check ) {
if ( $check instanceof themecheck ) {
$errors = $check->getError();
if ( ! empty( $error ) ) {
$errors = array_merge( $error, $errors );
}
$errors = array_map( 'strip_tags', $errors );
foreach ( $errors as $key => $value ) {
list( $type, $message ) = explode( ':', $value, 2 );
switch ( trim( $type ) ) {
case 'WARNING':
WP_CLI::line( WP_CLI::colorize( '%rWARNING:%n ' . trim( $message ) ) );
break;
case 'INFO':
WP_CLI::line( WP_CLI::colorize( '%bINFO:%n ' . trim( $message ) ) );
break;
case 'RECOMMENDED':
WP_CLI::line( WP_CLI::colorize( '%gRECOMMENDED:%n ' . trim( $message ) ) );
break;
case 'REQUIRED':
WP_CLI::line( WP_CLI::colorize( '%rREQUIRED:%n ' . trim( $message ) ) );
break;
}
}
}
}
}
}
}
WP_CLI::add_command( 'theme test', 'ThemeCheckCli' );