-
-
Save Aleksandar-Mitic/d353cb07a3ac17daee066e44b4d42758 to your computer and use it in GitHub Desktop.
Fix Expose by BeyondCode issues when working with the local WordPress site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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