add_command() public static method

WP-CLI supports using any callable class, function, or closure as a command. WP_CLI::add_command() is used for both internal and third-party command registration. Command arguments are parsed from PHPDoc by default, but also can be supplied as an optional third argument during registration. # Register a custom 'foo' command to output a supplied positional param. # # $ wp foo bar # Success: bar ** * My awesome closure command * * * : An awesome message to display * * @when before_wp_load *\/ $foo = function( $args ) { WP_CLI::success( $args[0] ); }; WP_CLI::add_command( 'foo', $foo );
public static add_command ( string $name, string $callable, array $args = [] ) : true
$name string Name for the command (e.g. "post list" or "site empty").
$callable string Command implementation as a class, function or closure.
$args array { Optional An associative array with additional registration parameters. 'before_invoke' => callback to execute before invoking the command, 'after_invoke' => callback to execute after invoking the command, 'shortdesc' => short description (80 char or less) for the command, 'synopsis' => the synopsis for the command (string or array), 'when' => execute callback on a named WP-CLI hook (e.g. before_wp_load), }
return true True on success, hard error if registration failed.
Example #1
0
 public function init()
 {
     add_action('init', array($this, 'maybe_init_integrations'));
     if (class_exists('WP_CLI_Command')) {
         \WP_CLI::add_command('timber', 'Timber\\Integrations\\Timber_WP_CLI_Command');
     }
 }
 public static function init()
 {
     add_action('init', array(__CLASS__, 'maybe_init_acftimber'));
     if (class_exists('WP_CLI_Command')) {
         WP_CLI::add_command('timber', 'Timber_WP_CLI_Command');
     }
 }
/**
 * Module Name: Custom CSS
 * Module Description: Tweak your site’s CSS without modifying your theme.
 * Sort Order: 2
 * First Introduced: 1.7
 * Requires Connection: No
 * Auto Activate: Yes
 * Module Tags: Appearance
 * Feature: Appearance
 * Additional Search Queries: css, customize, custom, style, editor, less, sass, preprocessor, font, mobile, appearance, theme, stylesheet
 */
function jetpack_load_custom_css()
{
    // If WordPress has the core version of Custom CSS, load our new version.
    // @see https://core.trac.wordpress.org/changeset/38829
    if (function_exists('wp_get_custom_css')) {
        if (!function_exists('wp_update_custom_css_post')) {
            wp_die('Please run a SVN up to get the latest version of trunk, or update to at least 4.7 RC1');
        }
        if (!Jetpack_Options::get_option('custom_css_4.7_migration')) {
            include_once dirname(__FILE__) . '/custom-css/migrate-to-core.php';
        } else {
            if (defined('WP_CLI') && WP_CLI) {
                function jetpack_custom_css_undo_data_migration_cli()
                {
                    Jetpack_Options::delete_option('custom_css_4.7_migration');
                    WP_CLI::success(__('Option deleted, re-migrate via `wp jetpack custom-css migrate`.', 'jetpack'));
                }
                WP_CLI::add_command('jetpack custom-css undo-migrate', 'jetpack_custom_css_undo_data_migration_cli');
            }
        }
        // TODO: END DELETE THIS
        include_once dirname(__FILE__) . '/custom-css/custom-css/preprocessors.php';
        include_once dirname(__FILE__) . '/custom-css/custom-css-4.7.php';
        return;
    }
    include_once dirname(__FILE__) . "/custom-css/custom-css.php";
    add_action('init', array('Jetpack_Custom_CSS', 'init'));
}
 /**
  * Registers just a 'list' and 'run' command to the WC CLI
  * since we only want to enable certain actions on the system status
  * tools endpoints.
  */
 public static function register_commands()
 {
     global $wp_rest_server;
     $request = new WP_REST_Request('OPTIONS', '/wc/v1/system_status/tools');
     $response = $wp_rest_server->dispatch($request);
     $response_data = $response->get_data();
     $parent = "wc tool";
     $supported_commands = array('list', 'run');
     foreach ($supported_commands as $command) {
         $synopsis = array();
         if ('run' === $command) {
             $synopsis[] = array('name' => 'id', 'type' => 'positional', 'description' => __('The id for the resource.', 'woocommerce'), 'optional' => false);
             $method = 'update_item';
             $route = '/wc/v1/system_status/tools/(?P<id>[\\w-]+)';
         } elseif ('list' === $command) {
             $synopsis[] = array('name' => 'fields', 'type' => 'assoc', 'description' => __('Limit response to specific fields. Defaults to all fields.', 'woocommerce'), 'optional' => true);
             $synopsis[] = array('name' => 'field', 'type' => 'assoc', 'description' => __('Get the value of an individual field.', 'woocommerce'), 'optional' => true);
             $synopsis[] = array('name' => 'format', 'type' => 'assoc', 'description' => __('Render response in a particular format.', 'woocommerce'), 'optional' => true, 'default' => 'table', 'options' => array('table', 'json', 'csv', 'ids', 'yaml', 'count', 'headers', 'body', 'envelope'));
             $method = 'list_items';
             $route = '/wc/v1/system_status/tools';
         }
         $before_invoke = null;
         if (empty($command_args['when']) && WP_CLI::get_config('debug')) {
             $before_invoke = function () {
                 if (!defined('SAVEQUERIES')) {
                     define('SAVEQUERIES', true);
                 }
             };
         }
         $rest_command = new WC_CLI_REST_Command('system_status_tool', $route, $response_data['schema']);
         WP_CLI::add_command("{$parent} {$command}", array($rest_command, $method), array('synopsis' => $synopsis, 'when' => !empty($command_args['when']) ? $command_args['when'] : '', 'before_invoke' => $before_invoke));
     }
 }
Example #5
0
 protected function __construct()
 {
     if (false !== get_transient('_my-wp-backup-activated')) {
         delete_transient('_my-wp-backup-activated');
         wp_redirect(Admin::get_page_url(''));
     }
     self::$info = get_file_data(__FILE__, array('name' => 'Plugin Name', 'pluginUri' => 'Plugin URI', 'supportUri' => 'Support URI', 'version' => 'Version', 'description' => 'Description', 'author' => 'Author', 'authorUri' => 'Author URI', 'textDomain' => 'Text Domain', 'domainPath' => 'Domain Path', 'slug' => 'Slug', 'license' => 'License', 'licenseUri' => 'License URI'));
     Admin::get_instance();
     $options = get_site_option('my-wp-backup-options', Admin::$options);
     self::$info['baseDir'] = plugin_dir_path(__FILE__);
     self::$info['baseDirUrl'] = plugin_dir_url(__FILE__);
     self::$info['backup_dir'] = trailingslashit(ABSPATH) . trailingslashit(ltrim($options['backup_dir'], '/'));
     self::$info['root_dir'] = trailingslashit(ABSPATH);
     if (defined('WP_CLI') && WP_CLI) {
         \WP_CLI::add_command('job', new Cli\Job());
         \WP_CLI::add_command('backup', new Cli\Backup());
     }
     add_action('wp_backup_run_job', array(Job::get_instance(), 'cron_run'));
     add_action('wp_backup_restore_backup', array(Backup::get_instance(), 'cron_run'));
     $version = get_site_option(self::KEY_VERSION);
     if (!$version || self::$info['version'] !== $version) {
         if ($this->update_options()) {
             update_site_option(self::KEY_VERSION, self::$info['version']);
         }
     }
 }
Example #6
0
 /**
  * Class constructor
  */
 public function __construct()
 {
     $locate = $this->locate_plugin();
     $this->locations = array('plugin' => $locate['plugin_basename'], 'dir' => $locate['dir_path'], 'url' => $locate['dir_url'], 'inc_dir' => $locate['dir_path'] . 'includes/', 'class_dir' => $locate['dir_path'] . 'classes/');
     spl_autoload_register(array($this, 'autoload'));
     // Load helper functions
     require_once $this->locations['inc_dir'] . 'functions.php';
     // Load DB helper interface/class
     $driver = '\\WP_Stream\\DB';
     if (class_exists($driver)) {
         $this->db = new DB($this);
     }
     if (!$this->db) {
         wp_die(esc_html__('Stream: Could not load chosen DB driver.', 'stream'), esc_html__('Stream DB Error', 'stream'));
     }
     // Load languages
     add_action('plugins_loaded', array($this, 'i18n'));
     // Load logger class
     $this->log = apply_filters('wp_stream_log_handler', new Log($this));
     // Load settings and connectors after widgets_init and before the default init priority
     add_action('init', array($this, 'init'), 9);
     // Add frontend indicator
     add_action('wp_head', array($this, 'frontend_indicator'));
     // Load admin area classes
     if (is_admin() || defined('WP_STREAM_DEV_DEBUG') && WP_STREAM_DEV_DEBUG) {
         $this->admin = new Admin($this);
         $this->install = new Install($this);
     }
     // Load WP-CLI command
     if (defined('WP_CLI') && WP_CLI) {
         \WP_CLI::add_command(self::WP_CLI_COMMAND, 'WP_Stream\\CLI');
     }
 }
 /**
  * @throws Exception
  */
 private function initialize_modules()
 {
     new Hello_Kushimoto_Dashboard_Widget($this->speaker);
     new Hello_Kushimoto_Admin_Notices($this->speaker);
     new Hello_Kushimoto_Shortcode($this->speaker);
     if (defined('WP_CLI') and WP_CLI) {
         Hello_Kushimoto_CLI::set_speaker($this->speaker);
         WP_CLI::add_command('hello-kushimoto', 'Hello_Kushimoto_CLI');
     }
 }
 /**
  * A loader for the WP:CLI class
  */
 public function wpcli()
 {
     if ($this->wpcli) {
         return TRUE;
     }
     require_once __DIR__ . '/class-go-newrelic-wpcli.php';
     // declare the class to WP:CLI
     WP_CLI::add_command('go-newrelic', 'SMC_NewRelic_Wpcli');
     $this->wpcli = TRUE;
 }
Example #9
0
 function run()
 {
     if (class_exists('WP_CLI_Command')) {
         //make sure wp-cli is present
         //Load temporary whitelist command
         if (!class_exists('ITSEC_WP_CLI_Command_ITSEC')) {
             require dirname(__FILE__) . '/class-itsec-wp-cli-command-itsec.php';
             WP_CLI::add_command('itsec', 'ITSEC_WP_CLI_Command_ITSEC');
         }
     }
 }
 /**
  * @param Hello_Kushimoto_Speaker $speaker
  */
 public function __construct(Hello_Kushimoto_Speaker $speaker)
 {
     $this->speaker = $speaker;
     load_plugin_textdomain('hello-kushimoto', false, plugin_basename(HELLO_KUSHIMOTO_DIR) . '/languages');
     new Hello_Kushimoto_Dashboard_Widget($speaker);
     new Hello_Kushimoto_Admin_Notices($speaker);
     new Hello_Kushimoto_Shortcode($speaker);
     if (defined('WP_CLI') and WP_CLI) {
         Hello_Kushimoto_CLI::set_speaker($speaker);
         WP_CLI::add_command('hello-kushimoto', 'Hello_Kushimoto_CLI');
     }
 }
Example #11
0
 public function on_load()
 {
     if (defined('WP_CLI') && WP_CLI) {
         \WP_CLI::add_command('parser', __NAMESPACE__ . '\\Command');
     }
     $this->relationships = new Relationships();
     add_action('init', array($this, 'register_post_types'), 11);
     add_action('init', array($this, 'register_taxonomies'), 11);
     add_filter('wp_parser_get_arguments', array($this, 'make_args_safe'));
     add_filter('wp_parser_return_type', array($this, 'humanize_separator'));
     add_filter('post_type_link', array($this, 'method_permalink'), 10, 2);
 }
Example #12
0
 public function init()
 {
     $meta = new Option(self::META_KEY);
     $queue = new Option(self::QUEUE_KEY);
     $generator = new Sri_Generator(self::CRON_HOOK, $meta, $queue);
     $injector = new Sri_Injector($meta, $queue);
     $registrar = new Registrar(['jquery' => ['footer' => true], 'jquery-core' => ['footer' => true, 'src' => 'https://code.jquery.com/jquery-%%VERSION%%.min.js'], 'jquery-migrate' => ['footer' => true, 'src' => 'https://code.jquery.com/jquery-migrate-%%VERSION%%.min.js']]);
     $features = [$meta, $queue, $generator, $injector, $registrar];
     foreach ($features as $feature) {
         $feature->init();
     }
     if (defined('WP_CLI') && WP_CLI) {
         \WP_CLI::add_command('sri', new Sri_Command($meta, $queue));
     }
 }
Example #13
0
 /**
  * Class constructor
  */
 private function __construct()
 {
     $this->version = '2.0.2';
     $this->basename = plugin_basename(__FILE__);
     $this->base_dir = plugin_dir_path(__FILE__);
     $this->assets_url = plugin_dir_url(__FILE__) . 'assets/';
     $this->page_slug = 'wpem';
     $this->api_url = 'http://demo.wpeasymode.com/';
     if (defined('WP_CLI') && WP_CLI) {
         $composer_autoloader = __DIR__ . '/vendor/autoload.php';
         if (file_exists($composer_autoloader)) {
             // This is for enabling codeception
             require_once $composer_autoloader;
         }
         \WP_CLI::add_command('easy-mode', sprintf('\\%s\\CLI', __NAMESPACE__));
         return;
     }
     if (!is_admin()) {
         return;
     }
     if (!$this->is_fresh_wp()) {
         if (!$this->is_done()) {
             add_filter('wpem_deactivate_plugins_on_quit', '__return_false');
             wpem_quit();
         }
         return;
     }
     add_action('plugins_loaded', [$this, 'i18n']);
     // Always allow external HTTP requests to our API
     add_filter('http_request_host_is_external', function ($allow, $host, $url) {
         $api_url = parse_url($this->api_url);
         return $api_url['host'] === $host ? true : $allow;
     }, 10, 3);
     // Enqueue customizer if we are on this screen
     add_action('load-customize.php', function () {
         if (filter_input(INPUT_GET, static::SCREEN_ID)) {
             new Customizer();
         }
     });
     if ($this->is_done()) {
         $this->self_destruct();
         $this->deactivate();
         add_action('init', [$this, 'maybe_redirect']);
         return;
     }
     define('WPEM_DOING_STEPS', true);
     $this->admin = new Admin();
 }
Example #14
0
 /**
  * Constructor
  */
 public function __construct()
 {
     require_once 'say-what-settings.php';
     $this->settings_instance = new SayWhatSettings();
     if (is_admin()) {
         require_once 'say-what-admin.php';
         $this->admin_instance = new SayWhatAdmin($this->settings_instance);
     }
     require_once 'say-what-frontend.php';
     $this->frontend_instance = new SayWhatFrontend($this->settings_instance);
     if (defined('WP_CLI') && WP_CLI) {
         require_once 'say-what-cli.class.php';
         WP_CLI::add_command('say-what', 'SayWhatCli');
     }
     add_action('init', array($this, 'init'));
     add_action('admin_init', array($this, 'admin_init'));
 }
 /**
  * Called at load time, hooks into WP core
  */
 public function __construct()
 {
     self::$instance =& $this;
     if (is_admin()) {
         $this->admin = new WordPress_GitHub_Sync_Admin();
     }
     $this->controller = new WordPress_GitHub_Sync_Controller();
     register_activation_hook(__FILE__, array($this, 'activate'));
     add_action('admin_notices', array($this, 'activation_notice'));
     add_action('init', array(&$this, 'l10n'));
     add_action('save_post', array(&$this, 'save_post_callback'));
     add_action('delete_post', array(&$this, 'delete_post_callback'));
     add_action('wp_ajax_nopriv_wpghs_sync_request', array(&$this, 'pull_posts'));
     add_action('wpghs_export', array(&$this->controller, 'export_all'));
     add_action('wpghs_import', array(&$this->controller, 'import_master'));
     if (defined('WP_CLI') && WP_CLI) {
         WP_CLI::add_command('wpghs', 'WordPress_GitHub_Sync_CLI');
     }
 }
Example #16
0
function gp_cli_register()
{
    require_once GP_PATH . GP_INC . 'cli/add-admin.php';
    require_once GP_PATH . GP_INC . 'cli/branch-project.php';
    require_once GP_PATH . GP_INC . 'cli/import-originals.php';
    require_once GP_PATH . GP_INC . 'cli/regenerate-paths.php';
    require_once GP_PATH . GP_INC . 'cli/remove-multiple-currents.php';
    require_once GP_PATH . GP_INC . 'cli/translation-set.php';
    require_once GP_PATH . GP_INC . 'cli/upgrade-set-permissions.php';
    require_once GP_PATH . GP_INC . 'cli/wipe-permissions.php';
    // Legacy commands
    WP_CLI::add_command('glotpress add-admin', 'GP_CLI_Add_Admin');
    WP_CLI::add_command('glotpress branch-project', 'GP_CLI_Branch_Project');
    WP_CLI::add_command('glotpress import-originals', 'GP_CLI_Import_Originals');
    WP_CLI::add_command('glotpress regenerate-paths', 'GP_CLI_Regenerate_Paths');
    WP_CLI::add_command('glotpress remove-multiple-currents', 'GP_CLI_Remove_Multiple_Currents');
    WP_CLI::add_command('glotpress upgrade-set-permissions', 'GP_CLI_Upgrade_Set_Permissions');
    WP_CLI::add_command('glotpress wipe-permissions', 'GP_CLI_Wipe_Permissions');
    // New style commands
    WP_CLI::add_command('glotpress translation-set', 'GP_CLI_Translation_Set');
}
 /**
  * Fire up the Syndication plugin
  *
  * Note: Class Autoloading is in use
  */
 public function __construct()
 {
     // Load our helper functions which autoload can't..load
     require_once SYNDICATION_PATH . 'includes/functions-helpers.php';
     // Always load.
     new Cron();
     // Settings helper.
     global $settings_manager;
     $settings_manager = new Syndication_Settings();
     global $client_manager;
     $client_manager = new Client_Manager();
     global $site_manager;
     $site_manager = new Site_Manager();
     Syndication_Logger::init();
     new Syndication_Event_Counter();
     new Syndication_Site_Failure_Monitor();
     new Syndication_Fail_Auto_Retry();
     new Upgrade_Tasks();
     new Legacy_Hooks();
     // Bootstrap admin.
     new Admin\Settings_Screen();
     new Admin\Site_List_Screen();
     new Admin\Site_Edit_Screen($client_manager);
     new Admin\Post_Edit_Screen();
     // Load the runner.
     new Syndication_Runner();
     // Bootstrap individual built-in clients.
     new Clients\Test\Bootstrap();
     new Clients\XML_Pull\Bootstrap();
     new Clients\RSS_Pull\Bootstrap();
     new Clients\XML_Push\Bootstrap();
     new Clients\REST_Push\Bootstrap();
     // Command line stuff.
     if (defined('WP_CLI') && WP_CLI) {
         require_once SYNDICATION_PATH . 'includes/class-syndication-cli-command.php';
         \WP_CLI::add_command('syndication', 'Syndication_CLI_Command');
     }
     // Hooks.
     add_action('init', [$this, 'init']);
 }
 function start_helper()
 {
     global $rt_wp_nginx_purger;
     add_action('shutdown', array(&$this, 'add_timestamps'), 99999);
     add_action('add_init', array(&$this, 'update_map'));
     //add_action( 'save_post', array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
     // add_action( 'publish_post', array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
     // add_action( 'publish_page', array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
     add_action('wp_insert_comment', array(&$rt_wp_nginx_purger, 'purgePostOnComment'), 200, 2);
     add_action('transition_comment_status', array(&$rt_wp_nginx_purger, 'purgePostOnCommentChange'), 200, 3);
     // $args = array( '_builtin' => false );
     // $_rt_custom_post_types = get_post_types( $args );
     // if ( isset( $post_types ) && !empty( $post_types ) ) {
     // 	if ( $this->options['rt_wp_custom_post_types'] == true ) {
     // 		foreach ( $_rt_custom_post_types as $post_type ) {
     // 			add_action( 'publish_' . trim( $post_type ), array( &$rt_wp_nginx_purger, 'purgePost' ), 200, 1 );
     // 		}
     // 	}
     // }
     add_action('transition_post_status', array(&$this, 'set_future_post_option_on_future_status'), 20, 3);
     add_action('delete_post', array(&$this, 'unset_future_post_option_on_delete'), 20, 1);
     add_action('nm_check_log_file_size_daily', array(&$rt_wp_nginx_purger, 'checkAndTruncateLogFile'), 100, 1);
     add_action('edit_attachment', array(&$rt_wp_nginx_purger, 'purgeImageOnEdit'), 100, 1);
     add_action('wpmu_new_blog', array(&$this, 'update_new_blog_options'), 10, 1);
     add_action('transition_post_status', array(&$rt_wp_nginx_purger, 'purge_on_post_moved_to_trash'), 20, 3);
     add_action('edit_term', array(&$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited'), 20, 3);
     add_action('delete_term', array(&$rt_wp_nginx_purger, 'purge_on_term_taxonomy_edited'), 20, 3);
     add_action('check_ajax_referer', array(&$rt_wp_nginx_purger, 'purge_on_check_ajax_referer'), 20, 2);
     add_action('admin_init', array(&$this, 'purge_all'));
     // expose action to allow other plugins to purge the cache
     add_action('rt_nginx_helper_purge_all', array(&$this, 'true_purge_all'));
     // Load WP-CLI command
     if (defined('WP_CLI') && WP_CLI) {
         require_once RT_WP_NGINX_HELPER_PATH . 'wp-cli.php';
         \WP_CLI::add_command(self::WP_CLI_COMMAND, 'Nginx_Helper_WP_CLI_Command');
     }
 }
Example #19
0
            }
        }
        /**
         * Import an image from the filesystem into NextGen
         *
         * @synopsis --filename=<absolute-path> --gallery=<gallery-id>
         */
        function import_image($args, $assoc_args)
        {
            $mapper = C_Gallery_Mapper::get_instance();
            $storage = C_Gallery_Storage::get_instance();
            if ($gallery = $mapper->find($assoc_args['gallery'], TRUE)) {
                $file_data = @file_get_contents($assoc_args['filename']);
                $file_name = M_I18n::mb_basename($assoc_args['filename']);
                if (empty($file_data)) {
                    WP_CLI::error('Could not load file');
                }
                $image = $storage->upload_base64_image($gallery, $file_data, $file_name);
                $image_id = $image->{$image->id_field};
                if (!$image) {
                    WP_CLI::error('Could not import image');
                } else {
                    WP_CLI::success("Imported image with id #{$image_id}");
                }
            } else {
                WP_CLI::error("Gallery not found (with id #{$assoc_args['gallery']}");
            }
        }
    }
    WP_CLI::add_command('ngg', 'C_NGG_WPCLI');
}
Example #20
0
    /**
     * Replace user_login value with user ID
     * user meta is a special case that also supports user_login
     *
     * @param array
     * @return array
     */
    private function replace_login_with_user_id($args)
    {
        $user = $this->fetcher->get_check($args[0]);
        $args[0] = $user->ID;
        return $args;
    }
}
/**
 * Manage user terms.
 *
 * ## EXAMPLES
 *
 *     # Set user terms
 *     $ wp user term set 123 test category
 *     Set terms.
 */
class User_Term_Command extends \WP_CLI\CommandWithTerms
{
    protected $obj_type = 'user';
}
WP_CLI::add_command('user', 'User_Command');
WP_CLI::add_command('user meta', 'User_Meta_Command');
WP_CLI::add_command('user term', 'User_Term_Command');
Example #21
0
 *
 *     # Get comment meta
 *     $ wp comment meta get 123 description
 *     Mary is a WordPress developer.
 *
 *     # Update comment meta
 *     $ wp comment meta update 123 description "Mary is an awesome WordPress developer."
 *     Success: Updated custom field 'description'.
 *
 *     # Delete comment meta
 *     $ wp comment meta delete 123 description
 *     Success: Deleted custom field.
 */
class Comment_Meta_Command extends \WP_CLI\CommandWithMeta
{
    protected $meta_type = 'comment';
    /**
     * Check that the comment ID exists
     *
     * @param int
     */
    protected function check_object_id($object_id)
    {
        $fetcher = new \WP_CLI\Fetchers\Comment();
        $comment = $fetcher->get_check($object_id);
        return $comment->comment_ID;
    }
}
WP_CLI::add_command('comment', 'Comment_Command');
WP_CLI::add_command('comment meta', 'Comment_Meta_Command');
<?php

/**
 * Plugin Name:  AWS SES wp_mail drop-in
 * Plugin URI:   https://github.com/humanmade/aws-ses-wp-mail
 * Description:  Drop-in replacement for wp_mail using the AWS SES.
 * Version:      0.0.1
 * Author:       Joe Hoyle | Human Made
 * Author URI:   https://github.com/humanmade
 * License:      GPL-2.0+
 * License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 */
if ((!defined('AWS_SES_WP_MAIL_KEY') || !defined('AWS_SES_WP_MAIL_SECRET') || !defined('AWS_SES_WP_MAIL_REGION')) && !defined('AWS_SES_WP_MAIL_USE_INSTANCE_PROFILE')) {
    return;
}
require_once dirname(__FILE__) . '/inc/class-ses.php';
if (defined('WP_CLI') && WP_CLI) {
    require_once dirname(__FILE__) . '/inc/class-wp-cli-command.php';
    WP_CLI::add_command('aws-ses', 'AWS_SES_WP_Mail\\WP_CLI_Command');
}
if (!function_exists('wp_mail')) {
    function wp_mail($to, $subject, $message, $headers = '', $attachments = array())
    {
        $result = AWS_SES_WP_Mail\SES::get_instance()->send_wp_mail($to, $subject, $message, $headers, $attachments);
        if (is_wp_error($result)) {
            return false;
        }
        return $result;
    }
}
Example #23
0
     **/
    public function taxonomy($args, $assoc_args)
    {
        $taxonomy = $args[0];
        $get_posts = $this->get_specified_posts($assoc_args);
        $message = $get_posts['message'];
        $posts = $get_posts['posts'];
        $args = $get_posts['args'];
        $preamble = "Will assign random {$taxonomy} terms";
        print_r("{$preamble} {$message}.\n");
        if (isset($assoc_args['terms'])) {
            $terms = explode(',', $assoc_args['terms']);
            \WP_CLI::log('Using terms ' . $assoc_args['terms']);
        } else {
            \WP_CLI::log('Gathering and processing random terms.');
            $terms = $this->get_random_terms();
            \WP_CLI::log('No term list given, using random terms.');
        }
        foreach ($posts as $p) {
            $index = array_rand($terms);
            $term = $terms[$index];
            \WP_CLI::log("Assigning {$term} to taxonomy {$taxonomy} for {$p->post_type} {$p->ID}");
            if (!term_exists($term, $taxonomy)) {
                wp_insert_term($term, $taxonomy);
            }
            wp_set_object_terms($p->ID, $term, $taxonomy, $append = false);
        }
    }
}
\WP_CLI::add_command('randomize', '\\CFPB\\Randomize_Command');
Example #24
0
     * @synopsis <key>
     */
    public function delete($args)
    {
        list($key) = $args;
        if (delete_transient($key)) {
            WP_CLI::success('Transient deleted.');
        } else {
            if (get_transient($key)) {
                WP_CLI::error('Transient was not deleted even though the transient appears to exist.');
            } else {
                WP_CLI::warning('Transient was not deleted; however, the transient does not appear to exist.');
            }
        }
    }
    /**
     * See whether the transients API is using an object cache or the options table.
     */
    public function type()
    {
        global $_wp_using_ext_object_cache, $wpdb;
        if ($_wp_using_ext_object_cache) {
            $message = 'Transients are saved to the object cache.';
        } else {
            $message = 'Transients are saved to the ' . $wpdb->prefix . 'options table.';
        }
        WP_CLI::line($message);
    }
}
WP_CLI::add_command('transient', 'Transient_Command');
Example #25
0
        WP_CLI::success(sprintf('%d mods removed.', count($args)));
    }
    /**
     * Set a theme mod.
     *
     * ## OPTIONS
     *
     * <mod>
     * : The name of the theme mod to set or update.
     *
     * <value>
     * : The new value.
     *
     * ## EXAMPLES
     *
     *     wp theme mod set background_color 000000
     */
    public function set($args = array(), $assoc_args = array())
    {
        list($mod, $value) = $args;
        set_theme_mod($mod, $value);
        if ($value == get_theme_mod($mod)) {
            WP_CLI::success(sprintf("Theme mod %s set to %s", $mod, $value));
        } else {
            WP_CLI::success(sprintf("Could not update theme mod %s", $mod));
        }
    }
}
WP_CLI::add_command('theme', 'Theme_Command');
WP_CLI::add_command('theme mod', 'Theme_Mod_Command');
Example #26
0
<?php

WP_CLI::add_command('jetpack', 'Jetpack_CLI');
/**
 * Control your local Jetpack installation.
 */
class Jetpack_CLI extends WP_CLI_Command
{
    // Aesthetics
    public $green_open = "";
    public $red_open = "";
    public $yellow_open = "";
    public $color_close = "";
    /**
     * Get Jetpack Details
     *
     * ## OPTIONS
     *
     * empty: Leave it empty for basic stats
     *
     * full: View full stats.  It's the data from the heartbeat
     *
     * ## EXAMPLES
     *
     * wp jetpack status
     * wp jetpack status full
     *
     */
    public function status($args, $assoc_args)
    {
        if (!Jetpack::is_active()) {
     *
     * @subcommand add
     * @synopsis <id> <key> <value> --site-id=<site-id>
     */
    public function add($args, $assoc_args)
    {
        $this->perform_meta_action('add', $args, $assoc_args);
    }
    /**
     * Update comment on a remote Site.
     *
     * @subcommand update
     * @synopsis <id> <key> <value> --site-id=<site-id>
     */
    public function update($args, $assoc_args)
    {
        $this->perform_meta_action('update', $args, $assoc_args);
    }
    /**
     * Delete a comment on a remote Site.
     *
     * @subcommand delete
     * @synopsis <id> <key> --site-id=<site-id>
     */
    public function delete($args, $assoc_args)
    {
        $this->perform_meta_action('delete', $args, $assoc_args);
    }
}
WP_CLI::add_command('remote-comment-meta', 'WP_Remote_Comment_Meta_Command');
Example #28
0
                ewww_image_optimizer_bulk_other($delay, $other_attachments);
                break;
            default:
                if ($ewww_reset) {
                    update_option('ewww_image_optimizer_bulk_resume', '');
                    update_option('ewww_image_optimizer_aux_resume', '');
                    update_option('ewww_image_optimizer_bulk_ngg_resume', '');
                    update_option('ewww_image_optimizer_bulk_flag_resume', '');
                    WP_CLI::success(__('Bulk status has been reset, the next bulk operation will start from the beginning.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
                } else {
                    WP_CLI::line(__('Please specify a valid library option, see "wp-cli help ewwwio optimize" for more information.', EWWW_IMAGE_OPTIMIZER_DOMAIN));
                }
        }
    }
}
WP_CLI::add_command('ewwwio', 'EWWWIO_CLI');
// prepares the bulk operation and includes the javascript functions
function ewww_image_optimizer_bulk_media($delay = 0)
{
    $attachments = null;
    // check if there is a previous bulk operation to resume
    if (get_option('ewww_image_optimizer_bulk_resume')) {
        // retrieve the attachment IDs that have not been finished from the 'bulk attachments' option
        $attachments = get_option('ewww_image_optimizer_bulk_attachments');
        // since we aren't resuming, and weren't given a list of IDs, we will optimize everything
    } else {
        global $wpdb;
        // load up all the image attachments we can find
        $attachments = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE (post_type = 'attachment' OR post_type = 'ims_image') AND (post_mime_type LIKE '%%image%%' OR post_mime_type LIKE '%%pdf%%') ORDER BY ID DESC");
        // store the attachment IDs we retrieved in the 'bulk_attachments' option so we can keep track of our progress in the database
        update_option('ewww_image_optimizer_bulk_attachments', $attachments, false);
Example #29
0
    /**
     * Import or update sessions from CSV.
     * 
     * @subcommand import-sessions
     * @synopsis <file>
     */
    public function import_sessions($args)
    {
        list($file) = $args;
        ONA_Importer::import_sessions($file, array($this, 'output'));
    }
    /**
     * Output some shiz
     */
    public static function output($message = '', $type = 'normal')
    {
        switch ($type) {
            case 'error':
                WP_CLI::line('error: ' . $message);
                break;
            case 'success':
                WP_CLI::$type($message);
                break;
            default:
                WP_CLI::line($message);
                break;
        }
    }
}
WP_CLI::add_command('ona13', 'ONA_CLI_Command');
Example #30
0
    }
    /**
     * Compare processed releases to the current one, and delete older one. Return remaining updates.
     *
     */
    private function remove_same_minor_releases($release_parts, $updates)
    {
        if (empty($updates)) {
            return false;
        }
        $difference = array();
        foreach ($updates as $processed) {
            $processed_parts = explode('.', $processed['version']);
            // later releases are always later in the array
            if ($processed_parts[0] !== $release_parts[0] || $processed_parts[1] !== $release_parts[1]) {
                $difference[] = $processed;
            }
        }
        return $difference;
    }
}
WP_CLI::add_command('core', 'Core_Command');
class Core_Language_Command extends WP_CLI\CommandWithTranslation
{
    protected $obj_type = 'core';
}
WP_CLI::add_command('core language', 'Core_Language_Command', array('before_invoke' => function () {
    if (version_compare($GLOBALS['wp_version'], '4.0', '<')) {
        WP_CLI::error("Requires WordPress 4.0 or greater.");
    }
}));