本文整理匯總了PHP中WP_CLI::set_url_params方法的典型用法代碼示例。如果您正苦於以下問題:PHP WP_CLI::set_url_params方法的具體用法?PHP WP_CLI::set_url_params怎麽用?PHP WP_CLI::set_url_params使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::set_url_params方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: install
/**
* Run wp_install. Assumes that wp-config.php is already in place.
*/
public function install($args, $assoc_args)
{
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
if (is_blog_installed()) {
WP_CLI::error('WordPress is already installed.');
}
extract(wp_parse_args($assoc_args, array('site_url' => defined('WP_SITEURL') ? WP_SITEURL : '', 'site_title' => '', 'admin_name' => 'admin', 'admin_email' => '', 'admin_password' => '')), EXTR_SKIP);
$missing = false;
foreach (array('site_url', 'site_title', 'admin_email', 'admin_password') as $required_arg) {
if (empty(${$required_arg})) {
WP_CLI::warning("missing --{$required_arg} parameter");
$missing = true;
}
}
if ($site_url) {
WP_CLI::set_url_params($site_url);
}
if ($missing) {
exit(1);
}
$public = true;
$result = wp_install($site_title, $admin_name, $admin_email, $public, '', $admin_password);
if (is_wp_error($result)) {
WP_CLI::error('Installation failed (' . WP_CLI::errorToString($result) . ').');
} else {
WP_CLI::success('WordPress installed successfully.');
}
}
示例2: _set_url
static function _set_url(&$assoc_args)
{
if (isset($assoc_args['url'])) {
$blog = $assoc_args['url'];
unset($assoc_args['url']);
} elseif (isset($assoc_args['blog'])) {
$blog = $assoc_args['blog'];
unset($assoc_args['blog']);
if (true === $blog) {
WP_CLI::line('usage: wp --blog=example.com');
}
} elseif (is_readable(WP_ROOT . 'wp-cli-blog')) {
$blog = trim(file_get_contents(WP_ROOT . 'wp-cli-blog'));
} else {
// Try to find the blog parameter in the wp-config file
if (file_exists(WP_ROOT . '/wp-config.php')) {
$wp_config_file = file_get_contents(WP_ROOT . '/wp-config.php');
$hit = array();
if (preg_match_all("#.*define\\s*\\(\\s*(['|\"]{1})(.+)(['|\"]{1})\\s*,\\s*(['|\"]{1})(.+)(['|\"]{1})\\s*\\)\\s*;#iU", $wp_config_file, $matches)) {
foreach ($matches[2] as $def_key => $def_name) {
if ('DOMAIN_CURRENT_SITE' == $def_name) {
$hit['domain'] = $matches[5][$def_key];
}
if ('PATH_CURRENT_SITE' == $def_name) {
$hit['path'] = $matches[5][$def_key];
}
}
}
if (!empty($hit) && isset($hit['domain'])) {
$blog = $hit['domain'];
}
if (!empty($hit) && isset($hit['path'])) {
$blog .= $hit['path'];
}
}
}
if (isset($blog)) {
WP_CLI::set_url_params($blog);
}
}