当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_CLI类代码示例

本文整理汇总了PHP中WP_CLI的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI类的具体用法?PHP WP_CLI怎么用?PHP WP_CLI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WP_CLI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: phonehome

 /**
  * 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));
 }
开发者ID:proudcity,项目名称:proudpack,代码行数:38,代码来源:proudpack-phone-home.php

示例2: __invoke

 /**
  * 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.");
 }
开发者ID:danielbachhuber,项目名称:wp-cli-reset-post-date-command,代码行数:35,代码来源:wp-cli-reset-post-date-command.php

示例3: recheck_queue

 /**
  * Recheck all comments in the Pending queue.
  *
  * ## EXAMPLES
  *
  *     wp akismet recheck_queue
  *
  * @alias recheck-queue
  */
 public function recheck_queue()
 {
     $batch_size = 100;
     $start = 0;
     $total_counts = array();
     do {
         $result_counts = Akismet_Admin::recheck_queue_portion($start, $batch_size);
         if ($result_counts['processed'] > 0) {
             foreach ($result_counts as $key => $count) {
                 if (!isset($total_counts[$key])) {
                     $total_counts[$key] = $count;
                 } else {
                     $total_counts[$key] += $count;
                 }
             }
             $start += $batch_size;
             $start -= $result_counts['spam'];
             // These comments will have been removed from the queue.
         }
     } while ($result_counts['processed'] > 0);
     WP_CLI::line(sprintf(_n("Processed %d comment.", "Processed %d comments.", $total_counts['processed'], 'akismet'), number_format($total_counts['processed'])));
     WP_CLI::line(sprintf(_n("%d comment moved to Spam.", "%d comments moved to Spam.", $total_counts['spam'], 'akismet'), number_format($total_counts['spam'])));
     if ($total_counts['error']) {
         WP_CLI::line(sprintf(_n("%d comment could not be checked.", "%d comments could not be checked.", $total_counts['error'], 'akismet'), number_format($total_counts['error'])));
     }
 }
开发者ID:coreymargulis,项目名称:karenmargulis,代码行数:35,代码来源:class.akismet-cli.php

示例4: perform_option_action

 /**
  * 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;
     }
 }
开发者ID:gokuale,项目名称:wp-remote-cli,代码行数:36,代码来源:class-wp-remote-option-command.php

示例5: register_commands

 /**
  * 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));
     }
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:38,代码来源:class-wc-cli-tool-command.php

示例6: __construct

 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']);
         }
     }
 }
开发者ID:guysyml,项目名称:software,代码行数:26,代码来源:my-wp-backup.php

示例7: __construct

 /**
  * 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');
     }
 }
开发者ID:selectSIFISO,项目名称:.comsite,代码行数:36,代码来源:class-plugin.php

示例8: _list

 /**
  * Lists one-time logins
  *
  * ## EXAMPLES
  *
  *     wp one-time-login list
  *
  * @subcommand list
  */
 function _list($args, $assoc_args)
 {
     // Get all one-time logins
     $otl_posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'onetimelogin', 'order' => ASC));
     // Error if no logins found
     if (empty($otl_posts)) {
         WP_CLI::error(__('No one time logins found.', 'one-time-login'));
     }
     // Set table headers
     $headers = array(__('ID', 'one-time-login'), __('Password', 'one-time-login'), __('User ID', 'one-time-login'), __('Date Generated', 'one-time-login'), __('Status', 'one-time-login'), __('Date Used', 'one-time-login'));
     $data = array();
     // loop through logins and format
     foreach ($otl_posts as $otl) {
         $id = $otl->ID;
         $password = $otl->post_title;
         $user_id = get_post_meta($otl->ID, 'otl_user', true);
         $generated = $otl->post_date;
         $status = '0' === get_post_meta($otl->ID, 'otl_times_used', true) ? __('Available', 'one-time-login') : __('Expired', 'one-time-login');
         $used = get_post_meta($otl->ID, 'otl_datetime_used', true);
         $data[] = array($id, $password, $user_id, $generated, $status, $used);
     }
     // Output table
     $table = new \cli\Table();
     $table->setHeaders($headers);
     $table->setRows($data);
     $table->display();
 }
开发者ID:ryanduff,项目名称:one-time-login,代码行数:36,代码来源:one-time-login-command.php

示例9: run

 public function run()
 {
     if (!function_exists('get_plugins')) {
         require_once \WP_CLI::get_config('path') . '/wp-admin/includes/plugin.php';
     }
     $all_plugins = get_plugins();
     $update = get_plugin_updates();
     $report = array();
     foreach ($all_plugins as $plugin_path => $data) {
         $slug = $plugin_path;
         if (stripos($plugin_path, '/')) {
             $slug = substr($plugin_path, 0, stripos($plugin_path, '/'));
         }
         $vulnerable = $this->is_vulnerable($slug, $data['Version']);
         $needs_update = 0;
         $available = '-';
         if (isset($update[$plugin_path])) {
             $needs_update = 1;
             $available = $update[$plugin_path]->update->new_version;
         }
         if (false === $vulnerable) {
             $vulnerable = "None";
         } else {
             $vulnerable = sprintf('<a href="https://wpvulndb.com/plugins/%s" target="_blank" >more info</a>', $slug);
         }
         $report[$slug] = array('slug' => $slug, 'installed' => (string) $data['Version'], 'available' => (string) $available, 'needs_update' => (string) $needs_update, 'vulnerable' => $vulnerable);
     }
     $this->alerts = $report;
 }
开发者ID:zepner,项目名称:wp_launch_check,代码行数:29,代码来源:plugins.php

示例10: handle_initial_sync

 /**
  * Initial player sync
  *
  * Retrieve all player and create/update when necessary.
  *
  * @since 1.0.0
  *
  * @param bool $is_cli whether the call is coming via WP_CLI
  *
  * @return bool True on success or false
  */
 public function handle_initial_sync($is_cli = false)
 {
     if (true === $is_cli) {
         WP_CLI::line(esc_html__('Starting Player Sync', 'brightcove'));
     }
     $players = $this->players_api->player_list();
     $players = $this->sort_api_response($players);
     if (!is_array($players)) {
         return false;
     }
     if (true === $is_cli) {
         WP_CLI::line(esc_html__(sprintf('There are %d players to sync for this account. Please be patient.', sizeof($players)), 'brightcove'));
     }
     $player_ids_to_keep = array();
     // for deleting outdated players
     /* process all players */
     foreach ($players as $player) {
         $this->add_or_update_wp_player($player);
         $player_ids_to_keep[] = BC_Utility::sanitize_subscription_id($player['id']);
     }
     BC_Utility::remove_deleted_players($player_ids_to_keep);
     BC_Utility::store_hash('players', $players, $this->cms_api->account_id);
     if (true === $is_cli) {
         WP_CLI::line(esc_html__('Player Sync Complete', 'brightcove'));
     }
     return true;
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:38,代码来源:class-bc-players.php

示例11: purge

 /**
  * 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.');
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:50,代码来源:wp-cli.php

示例12: flush

 /**
  * 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');
         }
     }
 }
开发者ID:isotopsweden,项目名称:wp-cachetop,代码行数:55,代码来源:class-command.php

示例13: install_plugins

 /**
  * 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) . ">");
     }
 }
开发者ID:dawnthemes,项目名称:tkb,代码行数:37,代码来源:class-wp-cli-commands.php

示例14: blank_media_fix

 /**
  * 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');
     }
 }
开发者ID:Automattic,项目名称:vip-mu-plugins-public,代码行数:69,代码来源:vip-fixers.php

示例15: import_from_csv

 /**
  * Bulk import redirects from a CSV file matching the following structure:
  *
  * redirect_from_path,(redirect_to_post_id|redirect_to_path|redirect_to_url)
  *
  * @subcommand import-from-csv
  * @synopsis --csv=<path-to-csv>
  */
 function import_from_csv($args, $assoc_args)
 {
     define('WP_IMPORTING', true);
     if (empty($assoc_args['csv']) || !file_exists($assoc_args['csv'])) {
         WP_CLI::error("Invalid 'csv' file");
     }
     global $wpdb;
     if (($handle = fopen($assoc_args['csv'], "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) {
             $row++;
             $redirect_from = $data[0];
             $redirect_to = $data[1];
             WP_CLI::line("Adding (CSV) redirect for {$redirect_from} to {$redirect_to}");
             WP_CLI::line("-- at {$row}");
             WPCOM_Legacy_Redirector::insert_legacy_redirect($redirect_from, $redirect_to);
             if (0 == $row % 100) {
                 if (function_exists('stop_the_insanity')) {
                     stop_the_insanity();
                 }
                 sleep(1);
             }
         }
         fclose($handle);
     }
 }
开发者ID:humanmade,项目名称:vip-mu-plugins-public,代码行数:33,代码来源:wp-cli.php


注:本文中的WP_CLI类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。