Success message is written to STDOUT.
Typically recommended to inform user of successful script conclusion.
# wp rewrite flush expects 'rewrite_rules' option to be set after flush.
flush_rewrite_rules( \WP_CLI\Utils\get_flag_value( $assoc_args, 'hard' ) );
if ( ! get_option( 'rewrite_rules' ) ) {
WP_CLI::warning( "Rewrite rules are empty." );
} else {
WP_CLI::success( 'Rewrite rules flushed.' );
}
/** * Clear something from the cache * * @param array $args * @param array $vars */ function flush($args = array(), $vars = array()) { if (function_exists('w3tc_pgcache_flush')) { $args = array_unique($args); do { $cache_type = array_shift($args); switch ($cache_type) { case 'db': case 'database': if (w3tc_dbcache_flush()) { WP_CLI::success('The object cache is flushed successfully.'); } else { WP_CLI::error('Flushing the object cache failed.'); } break; case 'minify': if (w3tc_minify_flush()) { WP_CLI::success('The object cache is flushed successfully.'); } else { WP_CLI::error('Flushing the object cache failed.'); } break; case 'object': if (w3tc_objectcache_flush()) { WP_CLI::success('The object cache is flushed successfully.'); } else { WP_CLI::error('Flushing the object cache failed.'); } break; case 'post': default: if (isset($vars['post_id'])) { if (is_numeric($vars['post_id'])) { w3tc_pgcache_flush_post($vars['post_id']); } else { WP_CLI::error('This is not a valid post id.'); } w3tc_pgcache_flush_post($vars['post_id']); } elseif (isset($vars['permalink'])) { $id = url_to_postid($vars['permalink']); if (is_numeric($id)) { w3tc_pgcache_flush_post($id); } else { WP_CLI::error('There is no post with this permalink.'); } } else { if (isset($flushed_page_cache) && $flushed_page_cache) { break; } $flushed_page_cache = true; w3tc_pgcache_flush(); } } } while (!empty($args)); } else { WP_CLI::error('The W3 Total Cache could not be found, is it installed?'); } }
/** * Delete orphaned tables * * @synopsis [--force] */ function delete($args, $assoc_args) { if (!isset($assoc_args['force'])) { WP_CLI::error('Use the --force'); return; } $orphanTables = $this->get_orphan_tables(); if (count($orphanTables) == 0) { WP_CLI::success('No orphan tables were found'); return; } global $wpdb; $i = 0; foreach ($orphanTables as $tableName) { $tableName = $tableName['Orphaned Table Name']; $result = $wpdb->query('DROP TABLE ' . $tableName); if ($result === false) { WP_CLI::error('Could not drop table ' . $tableName . ' - ' . $wpdb->last_error); continue; } WP_CLI::success('Dropped Table ' . $tableName); $i++; } WP_CLI::success('Dropped ' . $i . ' orphaned tables.'); }
/** * Subcommand to purge all cache from Nginx * * Examples: * wp nginx-helper purge-all * * @subcommand purge-all */ public function purge_all($args, $assoc_args) { global $rt_wp_nginx_purger; $rt_wp_nginx_purger->true_purge_all(); $message = __('Purged Everything!'); WP_CLI::success($message); }
/** * Set auth token. * * ## OPTIONS * * <token> * : Enter your Piwik auth token here. It is an alphanumerical code like 0a1b2c34d56e78901fa2bc3d45678efa (see WP-Piwik faq for more info) * * ## EXAMPLES * * wp piwik token 0a1b2c34d56e78901fa2bc3d45678efa * * @synopsis <token> */ function token($args, $assoc_args) { list($token) = $args; update_site_option('wp-piwik_global-piwik_token', $token); // Print a success message WP_CLI::success("Auth token set to: {$token}"); }
/** * Destroy a session for the given user. * * ## OPTIONS * * <user> * : User ID, user email, or user login. * * [<token>] * : The token of the session to destroy. Defaults to the most recently created session. * * [--all] * : Destroy all of the user's sessions. * * ## EXAMPLES * * # Destroy the most recent session of the given user. * $ wp user session destroy admin * Success: Destroyed session. 3 sessions remaining. * * # Destroy a specific session of the given user. * $ wp user session destroy admin e073ad8540a9c2... * Success: Destroyed session. 2 sessions remaining. * * # Destroy all the sessions of the given user. * $ wp user session destroy admin --all * Success: Destroyed all sessions. * * # Destroy all sessions for all users. * $ wp user list --field=ID | xargs wp user session destroy --all * Success: Destroyed all sessions. * Success: Destroyed all sessions. */ public function destroy($args, $assoc_args) { $user = $this->fetcher->get_check($args[0]); $token = \WP_CLI\Utils\get_flag_value($args, 1, null); $all = \WP_CLI\Utils\get_flag_value($assoc_args, 'all', false); $manager = WP_Session_Tokens::get_instance($user->ID); if ($token && $all) { WP_CLI::error('The --all flag cannot be specified along with a session token.'); } if ($all) { $manager->destroy_all(); WP_CLI::success('Destroyed all sessions.'); return; } $sessions = $this->get_all_sessions($manager); if (!$token) { if (empty($sessions)) { WP_CLI::success('No sessions to destroy.'); } $last = end($sessions); $token = $last['token']; } if (!isset($sessions[$token])) { WP_CLI::error('Session not found.'); } $this->destroy_session($manager, $token); $remaining = count($manager->get_all()); WP_CLI::success(sprintf('Destroyed session. %s remaining.', $remaining)); }
public function test($args = array(), $assoc_args = array()) { WP_CLI::line('Processing ... '); WP_CLI::line(print_r($args, true)); WP_CLI::line(print_r($assoc_args, true)); WP_CLI::success('Success!'); }
/** * create optional test nav menu * * At least two custom menus should be created in order to test a theme * The standard Theme data file now ships with optimal menus built-in * This method actually makes sense with custom WXR files only * * @since 0.2 */ private function create_test_menus() { $pages = get_all_page_ids(); $items = array(); foreach ($pages as $page_ID) { $info = get_page($page_ID); $items[$info->post_title] = get_permalink($page_ID); } # pick three random entries $random = array_rand($items, 3); # build menus $menus = array('Full Menu' => array('slug' => 'full-menu', 'menu_items' => $items), 'Short Menu' => array('slug' => 'short-menu', 'menu_items' => array($items[$random[0]], $items[$random[1]], $items[$random[2]]))); # register menus foreach ($menus as $title => $data) { register_nav_menu($data['slug'], $title); if (false == is_nav_menu($title)) { $menu_ID = wp_create_nav_menu($title); foreach ($data['menu_items'] as $name => $url) { $add_item = array('menu-item-type' => 'custom', 'menu-item-url' => $url, 'menu-item-title' => $name); wp_update_nav_menu_item($menu_ID, 0, $add_item); } WP_CLI::success('Created menu ' . $title); } } }
/** * Calls back to ProudCity API to get initial config settings * * ## OPTIONS * * ## EXAMPLES * * wp proudpack phonehome * * @synopsis */ function phonehome($args, $assoc_args) { //list( $name ) = $args; $request = wp_remote_get(PROUD_URL . '/sites/' . PROUD_ID . '/launched'); $response = json_decode(wp_remote_retrieve_body($request)); // Set options update_option('blogname', $response->location->city); update_option('lat', $response->location->lat); update_option('lng', $response->location->lng); update_option('city', $response->location->city); update_option('state', $response->location->stateFull); // Set theme settings $mods = get_option('theme_mods_wp-proud-theme', array()); if (!empty($response->settings->colors->main)) { $mods['color_main'] = $response->settings->colors->main; } if (!empty($response->settings->colors->secondary)) { $mods['color_secondary'] = $response->settings->colors->secondary; } if (!empty($response->settings->colors->highlight)) { $mods['color_highlight'] = $response->settings->colors->highlight; } update_option('theme_mods_wp-proud-theme', $mods); // Print a success message WP_CLI::success(print_r($response, 1)); WP_CLI::success(PROUD_URL . '/sites/' . PROUD_ID . '/launched' . $response->color->highlight . print_r(get_option('theme_mods_wp-proud-theme', array()), 1)); }
/** * Flush cache by hash, post id, url or all posts. * * ## OPTIONS * * [--all] * : Flush all posts. * * [--hash=<hash>] * : Flush by cache hash. * * [--post_id=<post_id>] * : Flush by post id * * [--url=<url>] * : Flush by url. * * @param array $args * @param array $assoc_args */ public function flush($args, $assoc_args) { // Flush all posts. if (isset($assoc_args['all'])) { if (cachetop_flush_all_posts()) { WP_CLI::success('Cache flushed'); } else { WP_CLI::error('Cached not flushed'); } } // Flush by hash. if (isset($assoc_args['hash'])) { if (cachetop_flush_hash($assoc_args['hash'])) { WP_CLI::success(sprintf('Cache flushed for hash: %s', $assoc_args['hash'])); } else { WP_CLI::error('Cached not flushed'); } } // Flush post by id. if (isset($assoc_args['post_id']) && is_numeric($assoc_args['post_id'])) { if (cachetop_flush_post($args[0])) { WP_CLI::success(sprintf('Cache flushed for post id: %s', $assoc_args['post_id'])); } else { WP_CLI::error('Cached not flushed'); } } // Flush by url. if (isset($assoc_args['url'])) { if (cachetop_flush_url($assoc_args['url'])) { WP_CLI::success(sprintf('Cache flushed for url: %s', $assoc_args['url'])); } else { WP_CLI::error('Cached not flushed'); } } }
public function sync($args, $assoc_args) { $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser()); WP_CLI::line('Syncing ' . MainWP_DB::num_rows($websites) . ' sites'); $warnings = 0; $errors = 0; while ($websites && ($website = @MainWP_DB::fetch_object($websites))) { WP_CLI::line(' -> ' . $website->name . ' (' . $website->url . ')'); try { if (MainWP_Sync::syncSite($website)) { WP_CLI::success(' Sync succeeded'); } else { WP_CLI::warning(' Sync failed'); $warnings++; } } catch (Exception $e) { WP_CLI::error(' Sync failed'); $errors++; } } @MainWP_DB::free_result($websites); if ($errors > 0) { WP_CLI::error('Sync completed with errors'); } else { if ($warnings > 0) { WP_CLI::warning('Sync completed with warnings'); } else { WP_CLI::success('Sync completed'); } } }
public function db($command = '', $args = '') { if (count($command) == 1 && reset($command) == 'help') { return $this->db_help(); } $defaults = array('host' => defined('IMPORT_DB_HOST') ? IMPORT_DB_HOST : DB_HOST, 'user' => defined('IMPORT_DB_USER') ? IMPORT_DB_USER : DB_USER, 'password' => defined('IMPORT_DB_PASSWORD') ? IMPORT_DB_PASSWORD : '', 'name' => defined('IMPORT_DB_NAME') ? IMPORT_DB_NAME : '', 'port' => '3306', 'ssh_host' => defined('IMPORT_DB_SSH_HOST') ? IMPORT_DB_SSH_HOST : '', 'ssh_user' => defined('IMPORT_DB_SSH_USER') ? IMPORT_DB_SSH_USER : '', 'table' => ''); $args = wp_parse_args($args, $defaults); $start_time = time(); if ($args['ssh_host']) { shell_exec(sprintf("ssh -f -L 3308:%s:%s %s@%s sleep 600 >> logfile", $args['host'], $args['port'], $args['ssh_user'], $args['ssh_host'])); $args['host'] = '127.0.0.1'; $args['port'] = '3308'; } WP_CLI::line('Importing database from ' . $args['host'] . '...' . ($args['ssh_host'] ? ' via ssh tunnel: ' . $args['ssh_host'] : '')); $password = $args['password'] ? '--password='******'password']) : ''; // TODO pipe through sed or interconnectIT's search replace script if (defined('IMPORT_DB_REMOTE_ABSPATH')) { $sed = " | sed s," . trailingslashit(IMPORT_DB_REMOTE_ABSPATH) . "," . ABSPATH . ",g"; } else { $sed = ''; } if ($args['site']) { $args['table'] = "wp_{$args['site']}_commentmeta wp_{$args['site']}_comments wp_{$args['site']}_links wp_{$args['site']}_options wp_{$args['site']}_postmeta wp_{$args['site']}_posts wp_{$args['site']}_term_relationships wp_{$args['site']}_term_taxonomy wp_{$args['site']}_terms"; } $exec = sprintf('mysqldump --verbose --host=%s --user=%s %s -P %s %s %s %s | mysql --host=%s --user=%s --password=%s %s', $args['host'], $args['user'], $password, $args['port'], $args['name'], $args['table'], $sed, DB_HOST, DB_USER, escapeshellarg(DB_PASSWORD), DB_NAME); WP_CLI::line('Running: ' . $exec); WP_CLI::launch($exec); WP_CLI::success(sprintf('Finished. Took %d seconds', time() - $start_time)); wp_cache_flush(); }
/** * Import content from a WXR file. * * ## OPTIONS * * <file>... * : Path to one or more valid WXR files for importing. * * --authors=<authors> * : How the author mapping should be handled. Options are 'create', 'mapping.csv', or 'skip'. The first will create any non-existent users from the WXR file. The second will read author mapping associations from a CSV, or create a CSV for editing if the file path doesn't exist. The CSV requires two columns, and a header row like "old_user_login,new_user_login". The last option will skip any author mapping. * * [--skip=<data-type>] * : Skip importing specific data. Supported options are: 'attachment' and 'image_resize' (skip time-consuming thumbnail generation). */ public function __invoke($args, $assoc_args) { $defaults = array('authors' => null, 'skip' => array()); $assoc_args = wp_parse_args($assoc_args, $defaults); if (!is_array($assoc_args['skip'])) { $assoc_args['skip'] = explode(',', $assoc_args['skip']); } $importer = $this->is_importer_available(); if (is_wp_error($importer)) { WP_CLI::error($importer); } $this->add_wxr_filters(); WP_CLI::log('Starting the import process...'); foreach ($args as $file) { if (!is_readable($file)) { WP_CLI::warning("Can't read {$file} file."); } $ret = $this->import_wxr($file, $assoc_args); if (is_wp_error($ret)) { WP_CLI::warning($ret); } else { WP_CLI::line(); // WXR import ends with HTML, so make sure message is on next line WP_CLI::success("Finished importing from {$file} file."); } } }
/** * Setup Elasticsearch. * * ## OPTIONS * * [--host=<url>] * : The name of the person to greet. * * [--port=<number>] * : Accepted values: csv, json. Default: csv * * ## EXAMPLES * * wp elasticsearch setup --host=example.com --port=9200 * * @subcommand setup */ function setup($args, $assoc_args) { $param = array(); $param['endpoint'] = preg_replace('/(^https:\\/\\/|^http:\\/\\/)/is', '', $assoc_args['host']); $param['port'] = $assoc_args['port']; $tries = 5; $sleep = 3; do { $response = wp_remote_get(esc_url($assoc_args['host']) . ':' . $assoc_args['port']); if (200 == wp_remote_retrieve_response_code($response)) { // Looks good! break; } else { WP_CLI::log("\nInvalid response from ES, sleeping {$sleep} seconds and trying again...\n"); sleep($sleep); } } while (--$tries); if (200 != wp_remote_retrieve_response_code($response)) { WP_CLI::error('Could not connect to Elasticsearch server.'); exit; } update_option('wpels_settings', $param); try { if (!\MegumiTeam\WooCommerceElasticsearch\Loader::get_instance()->data_sync()) { WP_CLI::error('Elasticsearch built index failed.'); } } catch (Exception $e) { WP_CLI::error($e->getMessage()); exit; } WP_CLI::success("Elasticsearch built index completed."); }
/** * Clear the product/shop transients cache. * * ## EXAMPLES * * wp wc tool clear_transients * * @since 2.5.0 */ public function clear_transients($args, $assoc_args) { wc_delete_product_transients(); wc_delete_shop_order_transients(); WC_Cache_Helper::get_transient_version('shipping', true); WP_CLI::success('Product transients and shop order transients were cleared.'); }
/** * Perform an option action on a remote site */ private function perform_option_action($action, $args, $assoc_args) { $site_id = $assoc_args['site-id']; unset($assoc_args['site-id']); list($option_name) = $args; $this->set_account(); $method = strtoupper($action); if ('update' == $action) { $method = 'POST'; $api_args = array('option_value' => WP_CLI::read_value($args[1], $assoc_args)); } else { $api_args = array(); } $args = array('endpoint' => 'site/' . (int) $site_id . '/option/' . $option_name, 'method' => $method, 'body' => $api_args); $response = $this->api_request($args); if (is_wp_error($response)) { WP_CLI::error($response->get_error_message()); } switch ($action) { case 'get': if (empty($response)) { die(1); } WP_CLI::print_value($response, $assoc_args); break; case 'update': WP_CLI::success("Updated '{$option_name}' option."); break; case 'delete': WP_CLI::success("Deleted '{$option_name}' option."); break; } }
/** * 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); if ($result2 && !is_wp_error($result2)) { unlink($file); update_attached_file($image->ID, $result['path']); wp_update_attachment_metadata($image->ID, wp_generate_attachment_metadata($image->ID, $result['path'])); $succeed++; } else { unlink($result['path']); $failed++; } } else { $failed++; } } WP_CLI::success(sprintf('%d images are converted and %s failed', $succeed, $failed)); } else { WP_CLI::success('No images to convert'); } }
/** * Forces a full Varnish Purge of the entire site (provided * regex is supported). * * ## EXAMPLES * * wp varnish purge * * wp varnish purge http://example.com/wp-content/themes/twentyeleventy/style.css * * wp vanrish purge "/wp-content/themes/twentysixty/style.css" * * wp varnish purge http://example.com/wp-content/themes/ --wildcard * * wp varnish purge "/wp-content/themes/" --wildcard * */ function purge($args, $assoc_args) { $wp_version = get_bloginfo('version'); $cli_version = WP_CLI_VERSION; // Set the URL/path list($url) = $args; // If wildcard is set, or the URL argument is empty // then treat this as a full purge if (isset($assoc_args['wildcard']) || empty($url)) { $pregex = '/?vhp-regex'; $wild = ".*"; } else { $pregex = $wild = ''; } wp_create_nonce('vhp-flush-cli'); // Make sure the URL is a URL: if (!empty($url)) { // If the URL isn't a URL, make it a URL if (empty(esc_url($url))) { $url = $this->varnish_purge->the_home_url() . $url; } } else { $url = $this->varnish_purge->the_home_url(); } if (version_compare($wp_version, '4.6', '>=') && (version_compare($cli_version, '0.25.0', '<') || version_compare($cli_version, '0.25.0-alpha', 'eq'))) { WP_CLI::log(sprintf('This plugin does not work on WP 4.6 and up, unless WP-CLI is version 0.25.0 or greater. You\'re using WP-CLI %s and WordPress %s.', $cli_version, $wp_version)); WP_CLI::log('To flush your cache, please run the following command:'); WP_CLI::log(sprintf('$ curl -X PURGE "%s"', $url . $wild)); WP_CLI::error('Varnish Cache must be purged manually.'); } $this->varnish_purge->purgeUrl($url . $pregex); WP_CLI::success('The Varnish cache was purged.'); }
/** * Reset the post_date field on your posts. * A sadly necessary step after you change your timezone in WordPress * * @synopsis --post_type=<post-type> */ public function __invoke($args, $assoc_args) { global $wpdb; $query_args = array('post_type' => $assoc_args['post_type'], 'posts_per_page' => -1, 'post_status' => 'publish'); $query = new WP_Query($query_args); if (empty($query->posts)) { WP_CLI::error("No posts found"); } WP_CLI::line(sprintf("Updating post_date on %d posts.", count($query->posts))); foreach ($query->posts as $key => $post) { if (empty($post->post_date_gmt) || "0000-00-00 00:00:00" == $post->post_date_gmt) { WP_CLI::line(sprintf("Error: Post %d is missing a publish date.", $post->ID)); continue; } $original = $post->post_date; $new = get_date_from_gmt($post->post_date_gmt); if ($new == $original) { WP_CLI::line(sprintf("No Change: Post %d has the correct post_date of %s", $post->ID, $original)); continue; } $wpdb->update($wpdb->posts, array('post_date' => $new), array('ID' => $post->ID)); clean_post_cache($post->ID); WP_CLI::line(sprintf("Updated: Post %d changed from %s to %s", $post->ID, $original, $new)); if ($key && $key % 10 == 0) { sleep(1); } } WP_CLI::success("Posts were updated with the correct post_date."); }
/** * Sets up Developer Plugin * @subcommand install-plugins * @synopsis --type=<type> [--activate] */ function install_plugins($args, $assoc_args) { global $automattic_developer; // wp-cli doesn't fire admin_init since 0.11.2 if (!did_action('admin_init')) { $automattic_developer->admin_init(); } $type = $assoc_args['type']; $activate = isset($assoc_args['activate']) && $assoc_args['activate'] == "true"; $reco_plugins = $automattic_developer->recommended_plugins; $installed_plugins = array_keys(get_plugins()); $types = array_keys($automattic_developer->get_project_types()); if (in_array($type, $types)) { $automattic_developer->save_project_type($type); foreach ($reco_plugins as $slug => $plugin) { $path = $automattic_developer->get_path_for_recommended_plugin($slug); $activate_plugin = $activate && ('all' == $plugin['project_type'] || $type == $plugin['project_type']); // Download the plugin if we don't already have it if (!in_array($path, $installed_plugins)) { WP_CLI::run_command(explode(" ", "plugin install {$slug}")); } // Install the plugin if --activate and it's the right type if (is_plugin_inactive($path) && $activate_plugin) { if (NULL == activate_plugin($path)) { WP_CLI::success("Activated " . $plugin['name']); } } } } else { WP_CLI::error("Specify a valid type to install: <" . implode("|", $types) . ">"); } }
/** * Fixes issues with slow saving in wp-admin due to no audio/video media files * * Core Ticket: https://core.trac.wordpress.org/ticket/31071 * * eg.: `wp vip-go-one-time-fixers blank-media-fix --allow-root --url=beta.thesun.co.uk` * * @subcommand blank-media-fix */ public function blank_media_fix($args, $assoc_args) { if (!function_exists('wpcom_vip_download_image')) { WP_CLI::error('This script requires the wpcom_vip_download_image() function, https://vip.wordpress.com/functions/wpcom_vip_download_image/'); } $audio_file_url = 'https://cldup.com/xmre07YagX.mp3'; // 1sec.mp3 $video_file_url = 'https://cldup.com/KHsK5yZkvv.avi'; // 1sec.avi $args = array('post_type' => 'attachment', 'post_status' => 'inherit', 'meta_query' => array(array('key' => '_vip_blank_media_fix', 'value' => 'video'))); $video_query = new WP_Query($args); if (!$video_query->post_count) { WP_CLI::log('Video fix not found, applying...'); $video_file_id = $this->wpcom_vip_download_image($video_file_url, 0, 'VIP: Fix for slow post saving'); if (!is_wp_error($video_file_id)) { $args = array('ID' => $video_file_id, 'post_date' => '2000-01-01', 'post_date_gmt' => '2000-01-01', 'post_modified' => '2000-01-01', 'post_modified_gmt' => '2000-01-01'); $updated_video_file_id = wp_update_post($args, true); if (!is_wp_error($updated_video_file_id)) { WP_CLI::success('Video fix applied'); $video_meta = update_post_meta($updated_video_file_id, '_vip_blank_media_fix', 'video'); if (false === $video_meta) { WP_CLI::warning('Could not update video _vip_blank_media_fix meta'); } } else { // Video date was not updated WP_CLI::error($updated_video_file_id->get_error_message()); } } else { // Sideload failed WP_CLI::error($video_file_id->get_error_message()); } } else { WP_CLI::warning('Blank video fix already exists for this site'); } $args = array('post_type' => 'attachment', 'post_status' => 'inherit', 'meta_query' => array(array('key' => '_vip_blank_media_fix', 'value' => 'audio'))); $audio_query = new WP_Query($args); if (!$audio_query->post_count) { WP_CLI::log('Audio fix not found, applying...'); $audio_file_id = $this->wpcom_vip_download_image($audio_file_url, 0, 'VIP: Fix for slow post saving'); if (!is_wp_error($audio_file_id)) { $args = array('ID' => $audio_file_id, 'post_date' => '2000-01-01', 'post_date_gmt' => '2000-01-01', 'post_modified' => '2000-01-01', 'post_modified_gmt' => '2000-01-01'); $updated_audio_file_id = wp_update_post($args, true); if (!is_wp_error($updated_audio_file_id)) { WP_CLI::success('Audio fix applied'); $audio_meta = update_post_meta($updated_audio_file_id, '_vip_blank_media_fix', 'audio'); if (false === $audio_meta) { WP_CLI::warning('Could not update audio _vip_blank_media_fix meta'); } } else { // Audio date was not updated WP_CLI::error($updated_audio_file_id->get_error_message()); } } else { // Sideload failed WP_CLI::error($video_file_id->get_error_message()); } } else { WP_CLI::warning('Blank video fix already exists for this site'); } }
/** * Upgrade the Genesis settings, usually after an upgrade. * * ## EXAMPLES * * wp genesis upgrade-db * */ public function upgrade_db($args, $assoc_args) { //* Disable post-upgrade redirect remove_action('genesis_upgrade', 'genesis_upgrade_redirect'); // Call the upgrade function genesis_upgrade(); WP_CLI::success(__('Genesis database upgraded.', 'genesis')); }
/** * Pull a bundle into the database * * ## OPTIONS * * <bundle_name> * : The bundle name to import (or use "all") * * ## EXAMPLES * * wp config pull bundle_name * * @synopsis <bundle_name> [--network] * */ function pull($args, $assoc_args) { if (isset($assoc_args['network'])) { WPCFM()->options->is_network = true; } WPCFM()->readwrite->pull_bundle($args[0]); WP_CLI::success('The bundle has been pulled into the database.'); }
private function reset(array $tables) { foreach ($tables as $key => $value) { WP_CLI::success($value); } $this->resetter->reset($tables); $this->output_successful_notice(); }
public function __invoke() { WP_CLI::confirm("This will erase all current permissions!\nAre you sure you want to delete them?"); if (!GP::$permission->delete_all()) { WP_CLI::error(__('Error in deleting permissions.', 'glotpress')); } WP_CLI::success(__('Permissions were deleted. Now you can use `wp glotpress add-admin` to add a new administrator.', 'glotpress')); }
/** * @param $args * @param $assoc_args */ public function import_settings($args, $assoc_args) { $nonce = wp_create_nonce('import_wpseo_settings'); //$link = hw_get_ajax_url('hw-import-wpseo', $nonce ); global $hwcli; $result = $hwcli->handler->get_handler_object('wpseo')->import_file(array('settings_import_file' => 'settings.zip'), array('action' => 'wp_handle_upload', 'nonce' => $nonce, 'hw_import_action' => 'settings')); WP_CLI::success("Import WP SEO successful.\n" . $result); }
/** * delete all galleries * @cmd wp gallery delete_all_galleries * @param $args * @param $assoc_args */ public function delete_all_galleries($args, $assoc_args) { $forms = get_posts('post_type=hw-gallery&showposts=-1'); foreach ($forms as $post) { wp_delete_post($post->ID); } WP_CLI::success(' Deleted all galleries.'); }
/** * remove all forms * @param $args * @param $assoc_args */ public function delete_all_forms($args, $assoc_args) { $forms = get_posts('post_type=wpcf7_contact_form&showposts=-1'); foreach ($forms as $post) { wp_delete_post($post->ID); } WP_CLI::success(' Deleted all contact form 7.'); }
/** * Revoke super-admin privileges to one or more users. * * <user>... * : One or more user IDs, user emails, or user logins. */ public function remove($args, $_) { $users = $this->fetcher->get_many($args); $user_logins = wp_list_pluck($users, 'user_login'); $super_admins = self::get_admins(); $super_admins = array_diff($super_admins, $user_logins); update_site_option('site_admins', $super_admins); WP_CLI::success('Revoked super-admin capabilities.'); }
/** * Abort a working BackWPup Job * * @synopsis abort */ public function abort($args, $assoc_args) { if (file_exists(BackWPup::get_plugin_data('running_file'))) { WP_CLI::error(__('Nothing to abort!', 'backwpup')); } //abort BackWPup_Job::user_abort(); WP_CLI::success(__('Job will be terminated.', 'backwpup')); }
/** * Loop through all posts, setting the first attached image as the featured images * * ## OPTIONS * * ## EXAMPLES * * wp auto-thumbnail * */ public function __invoke($args, $assoc_args) { set_time_limit(0); // Get all public post types $get_post_types = get_post_types(array('public' => true)); // Post types array that will be used by default $post_types = array(); foreach ($get_post_types as $post_type) { // Only add post types that support if (post_type_supports($post_type, 'thumbnail')) { $post_types[] = $post_type; } } // Default values for wp query $defaults = array('post_type' => $post_types, 'posts_per_page' => -1, 'post_status' => 'any'); // Merge user args with defaults $assoc_args = wp_parse_args($assoc_args, $defaults); // The Query $the_query = new WP_Query($assoc_args); // Number of posts returned by query $found_posts = $the_query->found_posts; // Generate progess bar $progress = new \cli\progress\Bar('Progress', $found_posts); // Counter for number of post successfully processed $counter_success = 0; // Counter for number of post processed $counter_processed = 0; // The Loop while ($the_query->have_posts()) { $the_query->the_post(); // Move the processbar on $progress->tick(); $has_thumb = has_post_thumbnail(get_the_ID()); if (!$has_thumb) { $attached_image = get_children("post_parent=" . get_the_ID() . "&post_type=attachment&post_mime_type=image&numberposts=1"); if ($attached_image) { foreach ($attached_image as $attachment_id => $attachment) { set_post_thumbnail(get_the_ID(), $attachment_id); $counter_success++; } } $counter_processed++; } } $progress->finish(); /* Restore original Post Data * NB: Because we are using new WP_Query we aren't stomping on the * original $wp_query and it does not need to be reset. */ wp_reset_postdata(); if ($found_posts == 0) { WP_CLI::error("No posts found"); } elseif ($counter_processed == 0) { WP_CLI::error("No posts processed"); } elseif ($counter_success == 0) { WP_CLI::success("Unable to processed any posts"); } else { WP_CLI::success("Processing compelete. {$counter_success} of {$counter_processed} where processed successfully."); } }