change upload url with add_filter

2018-06-20 18:53:08

I have here two identical wordpress installations. One is online and one is in a local network environment. Both uses the same database, without modfications. For development purposes I use a mu-plugin, to redirect home/siteurl/plugin URL:

function dev_home() {

$url = 'https://' . $_SERVER['HTTP_HOST'];

return $url;

}

function dev_siteurl() {

$url = 'https://' . $_SERVER['HTTP_HOST'] . '/subfolder';

return $url;

}

// fixes the plugins_url

function dev_plugins_uri( $full_url, $path=NULL, $plugin=NULL ) {

return get_option( 'siteurl' ) . substr( $full_url, stripos( $full_url, PLUGINDIR ) - 1 );

}

if (!empty($_SERVER['WP_ENV']) && $_SERVER['WP_ENV'] == 'development') {

add_filter('pre_option_home', 'dev_home');

add_filter('pre_option_siteurl', 'dev_siteurl');

add_filter('plugins_url', 'dev_plugins_uri');

}

The problem is now, when I upload a picture in the admin panel/media tab, it generate the URL for the online version. Witch is good,