-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.php
101 lines (95 loc) · 2.44 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
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
<?php
# Check Exist WP-CLI
if (! class_exists('WP_CLI')) {
return;
}
/**
* Wordpress Code Reference.
*
* ## OPTIONS
*
* [<search>]
* : Search Keyword.
*
* [--function=<name>]
* : Search Function name in WordPress Code Reference.
*
* [--class=<name>]
* : Search Class name in WordPress Code Reference.
*
* [--hook=<name>]
* : Search Hook name in WordPress Code Reference.
*
* [--method=<name>]
* : Search Method name in WordPress Code Reference.
*
* [--clear]
* : clear WordPress Reference Cache.
*
* [--browser]
* : Show WordPress Code Reference in browser.
*
* ## EXAMPLES
*
* # Search between WordPress function or class and show document.
* $ wp reference absint
*
* # Search in WordPress Code.
* $ wp reference get_userdata
*
* # Search only in WordPress functions.
* $ wp reference --function=wp_insert_user
*
* # Search only in WordPress class.
* $ wp reference --class=wp_user
*
* # Search only in WordPress hook.
* $ wp reference --hook=admin_footer
*
* # search only in WordPress method.
* $ wp reference --method=get_row
*
* # Remove All WordPress Reference Cache.
* $ wp reference --clear
* Success: Cache cleared.
*
* # Show code reference in web browser
* $ wp reference --browser
*
* @when before_wp_load
*/
\WP_CLI::add_command('reference', function ($args, $assoc_args) {
# init Reference Class
$reference = new Reference_Command();
# Clear Cache
if (isset($assoc_args['clear'])) {
$reference->runClearCache();
# Show in browser
} elseif (isset($assoc_args['browser'])) {
$reference->runBrowser();
# Search
} else {
//Prepare Word
$word = '';
if (isset($args[0])) {
$word = $args[0];
}
//Show Loading
WP_CLI_Helper::pl_wait_start();
//Custom Search
$list = array('function', 'class', 'hook', 'method');
$custom_search = false;
foreach ($list as $action) {
if (isset($assoc_args[$action])) {
$word = $assoc_args[$action];
$reference->runSearch($word, array('source' => true, 'allowed_filter' => $action));
$custom_search = true;
break;
}
}
//Common Search
if (! $custom_search) {
$reference->runSearch($word, array('source' => true));
}
}
});