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


PHP WP_CLI::runcommand方法代码示例

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


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

示例1: structure

 /**
  * Update the permalink structure.
  *
  * Sets the post permalink structure to the specified pattern.
  *
  * To regenerate a .htaccess file with WP-CLI, you'll need to add
  * the mod_rewrite module to your [WP-CLI config](http://wp-cli.org/config/).
  * For example:
  *
  * ```
  * apache_modules:
  *   - mod_rewrite
  * ```
  *
  * ## OPTIONS
  *
  * <permastruct>
  * : The new permalink structure to apply.
  *
  * [--category-base=<base>]
  * : Set the base for category permalinks, i.e. '/category/'.
  *
  * [--tag-base=<base>]
  * : Set the base for tag permalinks, i.e. '/tag/'.
  *
  * [--hard]
  * : Perform a hard flush - update `.htaccess` rules as well as rewrite rules in database.
  *
  * ## EXAMPLES
  *
  *     $ wp rewrite structure '/%year%/%monthnum%/%postname%'
  *     Success: Rewrite structure set.
  */
 public function structure($args, $assoc_args)
 {
     global $wp_rewrite;
     // copypasta from /wp-admin/options-permalink.php
     $prefix = $blog_prefix = '';
     if (is_multisite() && !is_subdomain_install() && is_main_site()) {
         $blog_prefix = '/blog';
     }
     $permalink_structure = $args[0] == 'default' ? '' : $args[0];
     if (!empty($permalink_structure)) {
         $permalink_structure = preg_replace('#/+#', '/', '/' . str_replace('#', '', $permalink_structure));
         if ($prefix && $blog_prefix) {
             $permalink_structure = $prefix . preg_replace('#^/?index\\.php#', '', $permalink_structure);
         } else {
             $permalink_structure = $blog_prefix . $permalink_structure;
         }
     }
     $wp_rewrite->set_permalink_structure($permalink_structure);
     // Update category or tag bases
     if (isset($assoc_args['category-base'])) {
         $category_base = $assoc_args['category-base'];
         if (!empty($category_base)) {
             $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $category_base));
         }
         $wp_rewrite->set_category_base($category_base);
     }
     if (isset($assoc_args['tag-base'])) {
         $tag_base = $assoc_args['tag-base'];
         if (!empty($tag_base)) {
             $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace('#', '', $tag_base));
         }
         $wp_rewrite->set_tag_base($tag_base);
     }
     // make sure we detect mod_rewrite if configured in apache_modules in config
     self::apache_modules();
     // Launch a new process to flush rewrites because core expects flush
     // to happen after rewrites are set
     $new_assoc_args = array();
     $cmd = 'rewrite flush';
     if (\WP_CLI\Utils\get_flag_value($assoc_args, 'hard')) {
         $cmd .= ' --hard';
         $new_assoc_args['hard'] = true;
         if (!in_array('mod_rewrite', (array) WP_CLI::get_config('apache_modules'))) {
             WP_CLI::warning("Regenerating a .htaccess file requires special configuration. See usage docs.");
         }
     }
     $process_run = WP_CLI::runcommand($cmd);
     if (!empty($process_run->stderr)) {
         // Strip "Warning: "
         WP_CLI::warning(substr($process_run->stderr, 9));
     }
     WP_CLI::success("Rewrite structure set.");
 }
开发者ID:wp-cli,项目名称:wp-cli,代码行数:86,代码来源:rewrite.php

示例2: update_db

 /**
  * Run the WordPress database update procedure.
  *
  * [--network]
  * : Update databases for all sites on a network
  *
  * [--dry-run]
  * : Compare database versions without performing the update.
  *
  * ## EXAMPLES
  *
  *     # Update the WordPress database
  *     $ wp core update-db
  *     Success: WordPress database upgraded successfully from db version 36686 to 35700.
  *
  *     # Update databases for all sites on a network
  *     $ wp core update-db --network
  *     WordPress database upgraded successfully from db version 35700 to 29630 on example.com/
  *     Success: WordPress database upgraded on 123/123 sites
  *
  * @subcommand update-db
  */
 function update_db($_, $assoc_args)
 {
     global $wpdb, $wp_db_version, $wp_current_db_version;
     $network = Utils\get_flag_value($assoc_args, 'network');
     if ($network && !is_multisite()) {
         WP_CLI::error('This is not a multisite install.');
     }
     $dry_run = Utils\get_flag_value($assoc_args, 'dry-run');
     if ($dry_run) {
         WP_CLI::log('Performing a dry run, with no database modification.');
     }
     if ($network) {
         $iterator_args = array('table' => $wpdb->blogs, 'where' => array('spam' => 0, 'deleted' => 0, 'archived' => 0));
         $it = new \WP_CLI\Iterators\Table($iterator_args);
         $success = $total = 0;
         foreach ($it as $blog) {
             $total++;
             $url = $blog->domain . $blog->path;
             $cmd = "--url={$url} core update-db";
             if ($dry_run) {
                 $cmd .= ' --dry-run';
             }
             $process = WP_CLI::runcommand($cmd, array('return' => 'all'));
             if (0 == $process->return_code) {
                 // See if we can parse the stdout
                 if (preg_match('#Success: (.+)#', $process->stdout, $matches)) {
                     $message = rtrim($matches[1], '.');
                     $message = "{$message} on {$url}";
                 } else {
                     $message = "Database upgraded successfully on {$url}";
                 }
                 WP_CLI::log($message);
                 $success++;
             } else {
                 WP_CLI::warning("Database failed to upgrade on {$url}");
             }
         }
         if (!$dry_run && $total && $success == $total) {
             update_site_option('wpmu_upgrade_site', $wp_db_version);
         }
         WP_CLI::success(sprintf('WordPress database upgraded on %d/%d sites.', $success, $total));
     } else {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         $wp_current_db_version = __get_option('db_version');
         if ($wp_db_version != $wp_current_db_version) {
             if ($dry_run) {
                 WP_CLI::success("WordPress database will be upgraded from db version {$wp_current_db_version} to {$wp_db_version}.");
             } else {
                 wp_upgrade();
                 WP_CLI::success("WordPress database upgraded successfully from db version {$wp_current_db_version} to {$wp_db_version}.");
             }
         } else {
             WP_CLI::success("WordPress database already at latest db version {$wp_db_version}.");
         }
     }
 }
开发者ID:wp-cli,项目名称:wp-cli,代码行数:78,代码来源:core.php


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