WP_Importer::set_blog() WordPress Method
The WP_Importer::set_blog() method allows you to change the blog being imported to. This is useful if you are importing content from one blog to another and you need to change the blog being imported to match the content you are importing.
WP_Importer::set_blog( int $blog_id ) #
Parameters
- $blog_id
(int)(Required)
Return
(int|void)
Source
File: wp-admin/includes/class-wp-importer.php
public function set_blog( $blog_id ) { if ( is_numeric( $blog_id ) ) { $blog_id = (int) $blog_id; } else { $blog = 'http://' . preg_replace( '#^https?://#', '', $blog_id ); $parsed = parse_url( $blog ); if ( ! $parsed || empty( $parsed['host'] ) ) { fwrite( STDERR, "Error: can not determine blog_id from $blog_id\n" ); exit; } if ( empty( $parsed['path'] ) ) { $parsed['path'] = '/'; } $blogs = get_sites( array( 'domain' => $parsed['host'], 'number' => 1, 'path' => $parsed['path'], ) ); if ( ! $blogs ) { fwrite( STDERR, "Error: Could not find blog\n" ); exit; } $blog = array_shift( $blogs ); $blog_id = (int) $blog->blog_id; } if ( function_exists( 'is_multisite' ) ) { if ( is_multisite() ) { switch_to_blog( $blog_id ); } } return $blog_id; }
Expand full source codeCollapse full source codeView on TracView on GitHub