Skip to content

Instantly share code, notes, and snippets.

@slaFFik
Created January 31, 2021 19:27
Show Gist options
  • Save slaFFik/321c0998694898df0285fca14b3b03c5 to your computer and use it in GitHub Desktop.
Save slaFFik/321c0998694898df0285fca14b3b03c5 to your computer and use it in GitHub Desktop.
Fix Expose by BeyondCode issues when working with the local WordPress site
<?php
// phpcs:ignoreFile
define( 'EXPOSED_DOMAIN', 'example.sharedwithexpose.com' );
// Load only if we are running under Expose.
if ( empty( $_SERVER['HTTP_X_ORIGINAL_HOST'] ) || $_SERVER['HTTP_X_ORIGINAL_HOST'] !== EXPOSED_DOMAIN ) {
return;
}
function get_exposed_url( $url ) {
return str_replace( [ 'http://example.local', 'https://example.local' ], 'https://' . EXPOSED_DOMAIN, $url );
}
add_filter( 'site_url', static function ( $url, $path, $orig_scheme, $blog_id ) {return get_exposed_url( $url );}, PHP_INT_MAX, 4 );
add_filter( 'home_url', static function ( $url, $path, $orig_scheme, $blog_id ) {return get_exposed_url( $url );}, PHP_INT_MAX, 4 );
add_filter( 'plugins_url', static function ( $url, $path, $plugin ) {return get_exposed_url( $url );}, PHP_INT_MAX, 3 );
add_filter( 'content_url', static function ( $url, $path ) {return get_exposed_url( $url );}, PHP_INT_MAX, 2 );
add_filter( 'wp_get_attachment_image_src', static function( $image, $attachment_id, $size, $icon ){return get_exposed_url( $image );}, PHP_INT_MAX, 4 );
add_filter(
'upload_dir',
static function($uploads){
$uploads['url'] = get_exposed_url( $uploads['url']);
$uploads['baseurl'] = get_exposed_url( $uploads['baseurl']);
return $uploads;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment