Guest User

Untitled

a guest
Nov 21st, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <?php
  2. $site_name = 'news_blog'; // e.g. "example.com/news_blog"
  3. $site_domain = 'example.com';
  4.  
  5. /**
  6. * Construct a fake $_SERVER global to get WordPress to load a specific site.
  7. * This avoids alot of messing about with switch_to_blog() and all its pitfalls.
  8. */
  9. $_SERVER = array(
  10. 'HTTP_HOST' => $site_domain,
  11. 'REQUEST_METHOD' => 'GET',
  12. 'REQUEST_URI' => "/{$site_name}/",
  13. 'SERVER_NAME' => $site_domain,
  14. );
  15.  
  16. // Remove all our bespoke variables as they'll be in scope as globals and could affect WordPress
  17. unset( $site_name, $site_domain );
  18.  
  19. // Pretend that we're executing an AJAX process. This should help WordPress not load all of the things.
  20. define( 'DOING_AJAX', true );
  21.  
  22. // Stop WordPress doing any of its normal output handling.
  23. define( 'WP_USE_THEMES', false );
  24.  
  25. // Load WordPress - intentionally using an absolute URL due to issues with relative paths on the CLI.
  26. require( '/opt/wp/blogs/wp-load.php' );
  27.  
  28. // Do normal WordPress stuff here
  29. ?>
Add Comment
Please, Sign In to add comment