本文整理汇总了PHP中WP_CLI::addCommand方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::addCommand方法的具体用法?PHP WP_CLI::addCommand怎么用?PHP WP_CLI::addCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::addCommand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connect_string
<?php
WP_CLI::addCommand('sql', 'SqlCommand');
/**
* Implement sql command
*
* @package wp-cli
* @subpackage commands/internals
**/
class SqlCommand extends WP_CLI_Command
{
protected $default_subcommand = 'cli';
/**
* return a string to connecting to the DB.
*
* @param void
* @return string $connect
*/
protected function connect_string()
{
$connect = sprintf('mysql --database=%s --user=%s --password=%s', DB_NAME, DB_USER, DB_PASSWORD);
return $connect;
}
/**
* A string for connecting to the DB.
*
* @param string $args
* @return void
*/
function connect($args = array())
{
示例2: help
}
/**
* Help function for this command
*/
public static function help()
{
WP_CLI::line(<<<EOB
usage: wp w3-total-cache flush [post|database|minify|object] [--post_id=<post-id>] [--permalink=<post-permalink>]
or : wp w3-total-cache querystring
or : wp w3-total-cache cdn_purge <file> [<file2>]...
or : wp w3-total-cache pgcache_cleanup
\t\t\t flush \t\t\t flushes whole cache or specific items based on provided arguments
\t\t\t querystring\t\t\t update query string for all static files
\t\t\t cdn_purge Purges command line provided files from Varnish and the CDN
\t\t\t pgcache_cleanup Generally triggered from a cronjob, allows for manual Garbage collection of page cache to be triggered
apc_reload_files SNS/local file.php file2.php file3.php Tells apc to compile files
apc_delete_based_on_regex SNS/local expression Tells apc to delete files that match a RegEx mask
Available flush sub-commands:
\t\t\t --post_id=<id> flush a specific post ID
\t\t\t --permalink=<post-permalink> flush a specific permalink
\t\t\t database flush the database cache
\t\t\t object flush the object cache
\t\t\t minify flush the minify cache
EOB
);
}
}
WP_CLI::addCommand('w3-total-cache', 'W3TotalCache_Command');
WP_CLI::addCommand('total-cache', 'W3TotalCache_Command');
示例3: flush
<?php
if (function_exists('wp_super_cache_enable')) {
WP_CLI::addCommand('super-cache', 'WPSuperCacheCommand');
}
/**
* The WP Super Cache plugin
*
* @package wp-cli
* @subpackage commands/community
* @maintainer Andreas Creten
*/
class WPSuperCacheCommand extends WP_CLI_Command
{
/**
* Clear something from the cache
*
* @param array $args
* @param array $vars
*/
function flush($args = array(), $vars = array())
{
if (function_exists('wp_cache_clear_cache')) {
if (isset($vars['post_id'])) {
if (is_numeric($vars['post_id'])) {
wp_cache_post_change($vars['post_id']);
} else {
WP_CLI::error('This is not a valid post id.');
}
wp_cache_post_change($vars['post_id']);
} elseif (isset($vars['permalink'])) {
示例4: __construct
<?php
WP_CLI::addCommand('eval', 'EvalCommand');
/**
* Implement eval command
*
* @package wp-cli
* @subpackage commands/internals
*/
class EvalCommand extends WP_CLI_Command
{
/**
* Overwrite the constructor to have a command without sub-commands.
*
* @param array $args
* @param array $assoc_args
*/
public function __construct($args, $assoc_args)
{
if (empty($args)) {
WP_CLI::line("usage: wp eval <php-code>");
exit;
}
eval($args[0]);
}
/**
* Help function for this command
*/
public static function help()
{
WP_CLI::line(<<<EOB
示例5: help
<?php
if (class_exists('GoogleSitemapGeneratorLoader')) {
WP_CLI::addCommand('google-sitemap', 'GoogleSitemapGeneratorCommand');
}
/**
* Manage the Google XML Sitemap plugin
*
* @package wp-cli
* @subpackage commands/community
* @maintainer Andreas Creten
*/
class GoogleSitemapGeneratorCommand extends WP_CLI_Command
{
/**
* Re-generate the sitemap
*
* @param array $args
* @param array $vars
*/
function rebuild($args = array(), $vars = array())
{
do_action('sm_rebuild');
}
/**
* Help function for this command
*/
public static function help()
{
WP_CLI::line(<<<EOB
usage: wp google-sitemap [rebuild]
示例6: array_filter
if (!empty($assoc_args['excludes'])) {
$hm_backup->excludes = $valid_rules = array_filter(array_map('trim', explode(',', $assoc_args['excludes'])));
}
$hm_backup->backup();
WP_CLI::line('Backup: Deleting old backups...');
// Delete any old backup files
hmbkp_delete_old_backups();
if (file_exists(HM_Backup::get_instance()->archive_filepath())) {
WP_CLI::success('Backup Complete: ' . HM_Backup::get_instance()->archive_filepath());
} else {
WP_CLI::error('Backup Failed');
}
}
static function help()
{
WP_CLI::line(<<<EOB
usage: wp backup [--files_only] [--database_only] [--path<dir>] [--root<dir>] [--zip_command_path=<path>] [--mysqldump_command_path=<path>]
\t --files_only Backup files only, default to off
\t --database_only Backup database only, defaults to off
\t --path dir that the backup should be save in, defaults to wp-content/backups/
\t --root dir that should be backed up, defaults to ABSPATH
\t --zip_command_path path to your zip binary, standard locations are automatically used
\t --mysqldump_command_path path to your mysqldump binary, standard locations are automatically used
EOB
);
}
}
WP_CLI::addCommand('backup', 'BackUpCommand');
示例7: status
<?php
WP_CLI::addCommand('plugin', 'PluginCommand');
require_once ABSPATH . 'wp-admin/includes/plugin.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
/**
* Implement plugin command
*
* @package wp-cli
* @subpackage commands/internals
*/
class PluginCommand extends WP_CLI_Command
{
protected $default_subcommand = 'status';
private $mu_plugins;
/**
* Get the status of one or all plugins
*
* @param array $args
*/
function status($args = array(), $vars = array())
{
$this->mu_plugins = get_mu_plugins();
if (empty($args)) {
$this->list_plugins();
return;
}
list($file, $name) = $this->parse_name($args, __FUNCTION__);
$details = $this->get_details($file);
$status = $this->get_status($file, true);
$version = $details['Version'];
示例8: __construct
<?php
WP_CLI::addCommand('help', 'HelpCommand');
/**
* Implement help command
*
* @package wp-cli
* @subpackage commands/internals
*/
class HelpCommand extends WP_CLI_Command
{
/**
* Overwrite the constructor to have a command without sub-commands.
*
* @param array $args
*/
public function __construct($args)
{
if (empty($args)) {
$this->general_help();
} else {
$command = $args[0];
if ('help' == $command || !isset(WP_CLI::$commands[$command])) {
$this->generalHelp();
} else {
$class = WP_CLI::$commands[$command];
if (method_exists($class, 'help')) {
$class::help();
} else {
WP_CLI::line('Example usage:');
$this->single_command_help($command, $class);
示例9: help
<?php
WP_CLI::addCommand('export', 'ExportCommand');
/**
* Implement export command
*
* @package wp-cli
* @subpackage commands/internals
*/
class ExportCommand extends WP_CLI_Command
{
protected $default_subcommand = 'validate_arguments';
public $export_args = array();
public static function help()
{
WP_CLI::line(<<<EOB
usage: wp export --path=<export-path> --user=<username/id>
or: wp export --path=/tmp/ --user=admin --post_type=post --start_date=2011-01-01 --end_date=2011-12-31
Required parameters:
\t--path\t\t\tFull Path to directory where WXR export files should be stored
\t--user\t\t\tUsername/ID the import should run as
Optional filters:
\t--start_date Export only posts new than this date in format YYYY-MM-DD
\t--end_date Export only posts older than this date in format YYYY-MM-DD
\t--post_type Export only posts with this post_type
\t--author Export only posts by this author
\t--category Export only posts in this category
\t--post_status Export only posts with this post_status
\t--skip_comments Don't export comments
示例10: _list
<?php
WP_CLI::addCommand('user', 'UserCommand');
/**
* Implement user command
*
* @package wp-cli
* @subpackage commands/internals
*/
class UserCommand extends WP_CLI_Command
{
/**
* List users
*
* @param array $args
* @param array $assoc_args
**/
public function _list($args, $assoc_args)
{
global $blog_id;
$params = array('blog_id' => $blog_id, 'fields' => 'all_with_meta');
if (array_key_exists('role', $assoc_args)) {
$params['role'] = $assoc_args['role'];
}
$table = new \cli\Table();
$users = get_users($params);
$fields = array('ID', 'user_login', 'display_name', 'user_email', 'user_registered');
$table->setHeaders(array_merge($fields, array('roles')));
foreach ($users as $user) {
$line = array();
foreach ($fields as $field) {
示例11: stopword_candidates
WP_CLI::error('Could not add the term ' . $term . ' to the list of stopwords.');
}
}
public function stopword_candidates($args = array(), $assoc_args = array())
{
if (array_key_exists('limit', $assoc_args)) {
$word_limit = $assoc_args['limit'];
} else {
$word_limit = 25;
}
global $relevanssi_table;
global $wpdb;
$words = $wpdb->get_results("SELECT COUNT(DISTINCT(doc)) as cnt, term\n\t\t FROM {$relevanssi_table} GROUP BY term ORDER BY cnt DESC LIMIT {$word_limit}");
foreach ($words as $word) {
WP_CLI::line("{$word->term} ({$word->cnt})");
}
}
public function help()
{
WP_CLI::line(<<<EOB
wp relevanssi index --limit=100 Index the unindexed posts, 100 at a time.
wp relevanssi reindex --limit=100 Index all posts, discarding any old index, 100 at a time.
wp relevanssi add_stopword <term> Add a new term to the list of stopwords and remove it from the index.
wp relevanssi stopword_candidates --limit=200 Show a list of the <limit> most common words in the index.
EOB
);
}
}
// Register the class as the 'relevanssi' command handler
WP_CLI::addCommand('relevanssi', 'RelevanssiCommand');
}
示例12: status
<?php
WP_CLI::addCommand('theme', 'ThemeCommand');
/**
* Implement theme command
*
* @package wp-cli
* @subpackage commands/internals
*/
class ThemeCommand extends WP_CLI_Command_With_Upgrade
{
protected $item_type = 'theme';
protected $upgrader = 'Theme_Upgrader';
protected $upgrade_refresh = 'wp_update_themes';
protected $upgrade_transient = 'update_themes';
/**
* Get the status of one or all themes
*
* @param array $args
**/
public function status($args = array())
{
if (empty($args)) {
$this->list_themes();
return;
}
$name = $args[0];
$details = get_theme_data($this->get_stylesheet_path($name));
$status = $this->get_status($details['Name'], true);
$version = $details['Version'];
if ($this->get_update_status($details['Stylesheet'])) {
示例13: __construct
/**
* Set needed filters and actions and load
*/
private function __construct()
{
// Nothing else matters if we're not on the main site
if (!is_main_site()) {
return;
}
//auto loader
spl_autoload_register(array($this, 'autoloader'));
//Options
new BackWPup_Option();
//start upgrade if needed
if (get_site_option('backwpup_version') != self::get_plugin_data('Version')) {
BackWPup_Install::activate();
}
//load pro features
if (class_exists('BackWPup_Pro')) {
BackWPup_Pro::get_instance();
}
//WP-Cron
if (defined('DOING_CRON') && DOING_CRON) {
//early disable caches
if (!empty($_GET['backwpup_run']) && class_exists('BackWPup_Job')) {
BackWPup_Job::disable_caches();
}
// add normal cron actions
add_action('backwpup_cron', array('BackWPup_Cron', 'run'));
add_action('backwpup_check_cleanup', array('BackWPup_Cron', 'check_cleanup'));
// add action for doing thinks if cron active
// must done in int before wp-cron control
add_action('init', array('BackWPup_Cron', 'cron_active'), 1);
// if in cron the rest must not needed
return;
}
//deactivation hook
register_deactivation_hook(__FILE__, array('BackWPup_Install', 'deactivate'));
//Things that must do in plugin init
add_action('init', array($this, 'plugin_init'));
//only in backend
if (is_admin() && class_exists('BackWPup_Admin')) {
BackWPup_Admin::get_instance();
}
//work with wp-cli
if (defined('WP_CLI') && WP_CLI && class_exists('WP_CLI') && class_exists('BackWPup_WP_CLI')) {
WP_CLI::addCommand('backwpup', 'BackWPup_WP_CLI');
}
}
示例14: posts
<?php
WP_CLI::addCommand('generate', 'GenerateCommand');
/**
* Implement generate command
*
* @package wp-cli
* @subpackage commands/internals
*/
class GenerateCommand extends WP_CLI_Command
{
/**
* Generate posts
*
* @param array $args
* @param array $assoc_args
**/
public function posts($args, $assoc_args)
{
global $wpdb;
$defaults = array('count' => 100, 'type' => 'post', 'status' => 'publish');
extract(wp_parse_args($assoc_args, $defaults), EXTR_SKIP);
if (!post_type_exists($type)) {
WP_CLI::warning('invalid post type.');
exit;
}
// Get the total number of posts
$total = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s", $type));
$label = get_post_type_object($type)->labels->singular_name;
$limit = $count + $total;
for ($i = $total; $i < $limit; $i++) {
示例15: version
<?php
WP_CLI::addCommand('core', 'CoreCommand');
/**
* Implement core command
*
* @package wp-cli
* @subpackage commands/internals
*/
class CoreCommand extends WP_CLI_Command
{
/**
* Display the WordPress version.
*/
public function version($args = array(), $assoc_args = array())
{
global $wp_version, $wp_db_version, $tinymce_version, $manifest_version;
$color = '%G';
$version_text = $wp_version;
$version_types = array('-RC' => array('release candidate', '%y'), '-beta' => array('beta', '%B'), '-' => array('in development', '%R'));
foreach ($version_types as $needle => $type) {
if (stristr($wp_version, $needle)) {
list($version_text, $color) = $type;
$version_text = "{$color}{$wp_version}%n (stability: {$version_text})";
break;
}
}
WP_CLI::line("WordPress version:\t{$version_text}");
if (isset($assoc_args['extra'])) {
WP_CLI::line();
WP_CLI::line("Database revision:\t{$wp_db_version}");