本文整理汇总了PHP中WP_CLI::load_all_commands方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::load_all_commands方法的具体用法?PHP WP_CLI::load_all_commands怎么用?PHP WP_CLI::load_all_commands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::load_all_commands方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: general_help
private function general_help()
{
WP_CLI::line('Available commands:');
foreach (WP_CLI::load_all_commands() as $command => $class) {
if ('help' == $command) {
continue;
}
$out = " wp {$command}";
$methods = WP_CLI_Command::get_subcommands($class);
if (!empty($methods)) {
$out .= ' [' . implode('|', $methods) . ']';
}
WP_CLI::line($out);
}
WP_CLI::line(<<<EOB
See 'wp help <command>' for more information on a specific command.
Global parameters:
--user=<id|login> set the current user
--url=<url> set the current URL
--path=<path> set the current path to the WP install
--require=<path> load a certain file before running the command
--quiet suppress informational messages
--version print wp-cli version
EOB
);
}
示例2: username_exists
if (isset($GLOBALS['wp_query']) && isset($GLOBALS['wp'])) {
$GLOBALS['wp']->parse_request();
$GLOBALS['wp_query']->query($GLOBALS['wp']->query_vars);
}
}
// Set the user
if (isset($assoc_args['user'])) {
$user = $assoc_args['user'];
if (is_numeric($user)) {
$user_id = (int) $user;
} else {
$user_id = (int) username_exists($user);
}
if (!$user_id || !wp_set_current_user($user_id)) {
WP_CLI::error(sprintf('Could not get a user_id for this user: %s', var_export($user, true)));
}
unset($user);
}
// Set filesystem method
add_filter('filesystem_method', function () {
return 'direct';
}, 99);
// Handle --completions parameter
if (isset($assoc_args['completions'])) {
WP_CLI::load_all_commands();
foreach (WP_CLI::$commands as $name => $command) {
WP_CLI::line($name . ' ' . implode(' ', WP_CLI_Command::get_subcommands($command)));
}
exit;
}
WP_CLI::run_command($arguments, $assoc_args);
示例3: get_subcommands
function get_subcommands()
{
return \WP_CLI::load_all_commands();
}
示例4: add_filter
// Set filesystem method
add_filter('filesystem_method', function () {
return 'direct';
}, 99);
// Handle --user parameter
if (isset($assoc_args['user'])) {
$user = $assoc_args['user'];
if (is_numeric($user)) {
$user_id = (int) $user;
} else {
$user_id = (int) username_exists($user);
}
if (!$user_id || !wp_set_current_user($user_id)) {
WP_CLI::error(sprintf('Could not get a user_id for this user: %s', var_export($user, true)));
}
unset($assoc_args['user'], $user);
}
// Handle --require parameter
if (isset($assoc_args['require'])) {
require $assoc_args['require'];
unset($assoc_args['require']);
}
// Generate strings for autocomplete
if (WP_CLI_AUTOCOMPLETE) {
foreach (WP_CLI::load_all_commands() as $name => $command) {
$subcommands = implode(' ', WP_CLI_Command::get_subcommands($command));
WP_CLI::line($name . ' ' . $subcommands);
}
exit;
}
WP_CLI::run_command($arguments, $assoc_args);