Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This gist is used to redirect ngrok.io image url to a private server created to serve simply image files to access from remote.
<?php
/**
* This gist is used to redirect ngrok.io image url to a private server created to serve simply image files
* to access from remote
* Thanks to @moff's answer at https://stackoverflow.com/a/772551/9229256
*/
if (ENVIRONMENT !== 'development') return;
/**
* Output Buffering
*
* Buffers the entire WP process, capturing the final output for manipulation.
*/
ob_start();
add_action('shutdown', function() {
$final = '';
// We'll need to get the number of ob levels we're in, so that we can iterate over each, collecting
// that buffer's output into the final output.
$levels = ob_get_level();
for ($i = 0; $i < $levels; $i++) {
$final .= ob_get_clean();
}
// Apply any filters to the final output
echo apply_filters('final_output', $final);
}, 0);
// Uncomment the filter to replace url in output
add_filter('final_output', function($output) {
define('NEW_WP_HOME', 'example.com');
return str_replace('inm_lifemat.test/wp-content/uploads/', NEW_WP_HOME . '/wp-content/uploads/', $output);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment