}
}
- private static function set_url( $assoc_args ) {
+ private static function guess_url( $assoc_args ) {
if ( isset( $assoc_args['blog'] ) ) {
$assoc_args['url'] = $assoc_args['blog'];
unset( $assoc_args['blog'] );
}
if ( isset( $url ) ) {
- Utils\set_url_params( $url );
+ return $url;
}
+
+ return false;
}
private function cmd_starts_with( $prefix ) {
self::set_wp_root( $this->config );
// Handle --url and --blog parameters
- self::set_url( $this->config );
+ $url = self::guess_url( $this->config );
+ if ( $url ) {
+ $url_parts = self::parse_url( $url );
+ Utils\set_url_params( $url_parts );
+ }
$this->do_early_invoke( 'before_wp_load' );
) {
define( 'WP_INSTALLING', true );
+ // We really need a URL here
if ( !isset( $_SERVER['HTTP_HOST'] ) ) {
- Utils\set_url_params( 'http://example.com' );
+ $url_parts = self::parse_url( 'http://example.com' );
+ Utils\set_url_params( $url_parts );
+ }
+
+ if ( 'multisite-install' == $this->arguments[1] ) {
+ // need to fake some globals to skip the checks in wp-inclues/ms-settings.php
+ self::fake_current_site_blog( $url_parts );
}
}
define( 'WP_LOAD_IMPORTERS', true );
define( 'WP_IMPORTING', true );
}
+ }
+
+ private static function parse_url( $url ) {
+ $url_parts = parse_url( $url );
+
+ if ( !isset( $url_parts['scheme'] ) ) {
+ $url_parts = parse_url( 'http://' . $url );
+ }
+ return $url_parts;
+ }
+
+ private static function fake_current_site_blog( $url_parts ) {
+ global $current_site, $current_blog;
+
+ if ( !isset( $url_parts['path'] ) ) {
+ $url_parts['path'] = '/';
+ }
+
+ $current_site = (object) array(
+ 'id' => 1,
+ 'blog_id' => 1,
+ 'domain' => $url_parts['host'],
+ 'path' => $url_parts['path'],
+ 'cookie_domain' => $url_parts['host'],
+ 'site_name' => 'Fake Site',
+ );
+
+ $current_blog = (object) array(
+ 'blog_id' => 1,
+ 'site_id' => 1,
+ 'domain' => $url_parts['host'],
+ 'path' => $url_parts['path'],
+ 'public' => '1',
+ 'archived' => '0',
+ 'mature' => '0',
+ 'spam' => '0',
+ 'deleted' => '0',
+ 'lang_id' => '0',
+ );
}
public function after_wp_load() {
/**
* Sets the appropriate $_SERVER keys based on a given string
*
- * @param string $url The URL
+ * @param array $url_parts The URL, as represented by parse_url()
*/
-function set_url_params( $url ) {
- $url_parts = parse_url( $url );
-
- if ( !isset( $url_parts['scheme'] ) ) {
- $url_parts = parse_url( 'http://' . $url );
- }
-
+function set_url_params( $url_parts ) {
$f = function( $key ) use ( $url_parts ) {
return isset( $url_parts[ $key ] ) ? $url_parts[ $key ] : '';
};
* @param array|string $fields Named fields for each item of data. Can be array or comma-separated list
*/
function format_items( $format, $items, $fields ) {
-
+
if ( 'ids' == $format ) {
echo implode( ' ', $items );
return;