Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $site_name = 'news_blog'; // e.g. "example.com/news_blog"
- $site_domain = 'example.com';
- /**
- * Construct a fake $_SERVER global to get WordPress to load a specific site.
- * This avoids alot of messing about with switch_to_blog() and all its pitfalls.
- */
- $_SERVER = array(
- 'HTTP_HOST' => $site_domain,
- 'REQUEST_METHOD' => 'GET',
- 'REQUEST_URI' => "/{$site_name}/",
- 'SERVER_NAME' => $site_domain,
- );
- // Remove all our bespoke variables as they'll be in scope as globals and could affect WordPress
- unset( $site_name, $site_domain );
- // Pretend that we're executing an AJAX process. This should help WordPress not load all of the things.
- define( 'DOING_AJAX', true );
- // Stop WordPress doing any of its normal output handling.
- define( 'WP_USE_THEMES', false );
- // Load WordPress - intentionally using an absolute URL due to issues with relative paths on the CLI.
- require( '/opt/wp/blogs/wp-load.php' );
- // Do normal WordPress stuff here
- ?>
Add Comment
Please, Sign In to add comment