<?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()) {
} /** * 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');
<?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'])) {
<?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
<?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]
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');
<?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'];
<?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);
<?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
<?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) {
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'); }
<?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'])) {
/** * 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'); } }
<?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++) {
<?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}");
<?php WP_CLI::addCommand('option', 'OptionCommand'); /** * Implement option command * * @package wp-cli * @subpackage commands/internals */ class OptionCommand extends WP_CLI_Command { /** * Add an option * * @param array $args **/ public function add($args) { if (count($args) < 2) { WP_CLI::line("usage: wp option add <option-name> <option-value>"); exit; } list($key, $value) = $args; if (!add_option($key, $value)) { WP_CLI::error("Could not add option '{$key}'. Does it already exist?"); } } /** * Update an option * * @param array $args
<?php WP_CLI::addCommand('home', 'HomeCommand'); /** * Implement home command * * @package wp-cli * @subpackage commands/internals */ class HomeCommand 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) { // The url for the wp-cli repository $repository_url = 'http://github.com/andreascreten/wp-cli'; // Open the wp-cli page in the browser if (exec('which x-www-browser')) { system('x-www-browser ' . $repository_url); } elseif (exec('which open')) { system('open ' . $repository_url); } else { WP_CLI::error('No command found to open the homepage in the browser. Please open it manually: ' . $repository_url); return; } WP_CLI::success('The wp-cli homepage should be opening in your browser.');
if (!(strrpos($file, $imageName) === false)) { $thumbnail = explode($imageName, $file); if ($thumbnail[0] == "") { $thumbnailFormat = substr($thumbnail[1], -4); $thumbnail = substr($thumbnail[1], 0, strlen($thumbnail[1]) - 4); $thumbnail = explode('x', $thumbnail); if (count($thumbnail) == 2) { if (is_numeric($thumbnail[0]) && is_numeric($thumbnail[1])) { WP_CLI::line("Thumbnail: {$thumbnail[0]} x {$thumbnail[1]} was deleted."); @unlink($dirPath . $imageName . $thumbnail[0] . 'x' . $thumbnail[1] . $thumbnailFormat); } } } } } $metadata = wp_generate_attachment_metadata($image->ID, $fullsizepath); if (is_wp_error($metadata)) { WP_CLI::line($metadata->get_error_message()); return; } if (empty($metadata)) { $this->errors = true; WP_CLI::line('Unknown failure reason.'); return; } wp_update_attachment_metadata($image->ID, $metadata); WP_CLI::line(esc_html(get_the_title($image->ID)) . " (ID {$image->ID}): All thumbnails were successfully regenerated in " . timer_stop() . " seconds "); } } WP_CLI::addCommand('regen_thumbs', 'RegenThumbs'); }
<?php WP_CLI::addCommand('tiff-converter', 'Tiff_Converter_Command'); /** * Ability to convert all images throught CLI * * @package tiff-converter */ class Tiff_Converter_Command extends WP_CLI_Command { /** * Run the converter now * * @since 1.0 * * @param array $args can be extension * @param array $vars */ function update_attachments($args = array(), $vars = array()) { $images = Tiff_Converter::get_images(); $mime_type = 'image/jpg'; // Maybe $args[0] for changing it if ($images) { $succeed = $failed = 0; foreach ($images as $image) { $file = get_attached_file($image->ID); $result = Tiff_Converter_Handle::convert_image($file, $mime_type); if (!is_wp_error($result)) { $update_args = array('ID' => $image->ID, 'post_mime_type' => $result['mime-type']); $result2 = wp_update_post($update_args, true);
<?php WP_CLI::addCommand('db', 'DBCommand'); /** * Implement db command * * @package wp-cli * @subpackage commands/internals **/ class DBCommand extends WP_CLI_Command { protected $default_subcommand = 'cli'; protected $aliases = array('dump' => 'export'); /** * Return a string for connecting to the DB. */ protected function connect_string() { return sprintf('mysql --host=%s --database=%s --user=%s --password=%s', DB_HOST, DB_NAME, DB_USER, DB_PASSWORD); } /** * Print a string for connecting to the DB. */ function connect() { WP_CLI::line($this->connect_string()); } /** * Open a SQL command-line interface using WordPress's credentials. */ function cli()
<?php WP_CLI::addCommand('eval-file', 'EvalFileCommand'); /** * Implement eval-file command * * @package wp-cli * @subpackage commands/internals */ class EvalFileCommand 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-file <path>"); exit; } foreach ($args as $file) { if (!file_exists($file)) { WP_CLI::error("'{$file}' does not exist."); } else { include $file; } } }