admin管理员组文章数量:1122832
I'm toying around with writing custom wp-cli commands. I have successfully created a simple command, wp-cli theme save
which runs a script to backup the site's theme files:
<?php
class Save_Command extends WP_CLI_Command {
/**
* Create a tarball of current active theme and save it to wp_themes directory in the user's config directory.
*
* @synopsis
*/
public function __invoke($args = array(), $assoc_args = array())
{
exec ( 'wpst' );
}
}
WP_CLI::add_command( 'theme save', 'Save_Command' );
This code exists in ~/.wp-cli/commands/custom/save/theme-save.php
and works.
Now I want to extend this feature with a new command:
wp theme save colors <scheme_name>
This feature spits out the customized colors to a file. I used the following code to try to get this to work:
<?php
class Save_Theme_Colors_Command extends WP_CLI_Command {
/**
* Save color scheme.
*
* @synopsis <name of color scheme>
*/
public function __invoke($args = array(), $assoc_args = array())
{
exec ( "go save_theme_colors " . implode(" ", $args));
}
}
WP_CLI::add_command( 'theme save colors', 'Save_Theme_Colors_Command' );
However, when I try to execute the command I get an error:
Warning: Failed to load autoloader 'phar://wp-cli.phar/vendor/autoload.php'. Reason: 'wp theme save' can't have subcommands.
I've tried various ways to get the subcommand working including using the @subcommand directive but that just seems to get ignored.
I'm toying around with writing custom wp-cli commands. I have successfully created a simple command, wp-cli theme save
which runs a script to backup the site's theme files:
<?php
class Save_Command extends WP_CLI_Command {
/**
* Create a tarball of current active theme and save it to wp_themes directory in the user's config directory.
*
* @synopsis
*/
public function __invoke($args = array(), $assoc_args = array())
{
exec ( 'wpst' );
}
}
WP_CLI::add_command( 'theme save', 'Save_Command' );
This code exists in ~/.wp-cli/commands/custom/save/theme-save.php
and works.
Now I want to extend this feature with a new command:
wp theme save colors <scheme_name>
This feature spits out the customized colors to a file. I used the following code to try to get this to work:
<?php
class Save_Theme_Colors_Command extends WP_CLI_Command {
/**
* Save color scheme.
*
* @synopsis <name of color scheme>
*/
public function __invoke($args = array(), $assoc_args = array())
{
exec ( "go save_theme_colors " . implode(" ", $args));
}
}
WP_CLI::add_command( 'theme save colors', 'Save_Theme_Colors_Command' );
However, when I try to execute the command I get an error:
Warning: Failed to load autoloader 'phar://wp-cli.phar/vendor/autoload.php'. Reason: 'wp theme save' can't have subcommands.
I've tried various ways to get the subcommand working including using the @subcommand directive but that just seems to get ignored.
Share Improve this question asked Mar 17, 2019 at 12:55 StevieDStevieD 2112 silver badges10 bronze badges1 Answer
Reset to default 0OK, looks like I need to change the commands so I have:
wp theme save theme
and
wp theme save colors
This works.
本文标签: wp cliCreating a subcommand for custom wpcli command
版权声明:本文标题:wp cli - Creating a subcommand for custom wp-cli command 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293217a1929099.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论