-
-
Save felipeelia/3821646676923a46c6eb68c65a4dd750 to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* Place this file in the wp-content/mu-plugins directory and run ngrok with | |
* `ngrok http http://<local_url> --host-header=<local_url>` | |
*/ | |
$ngrok_url = '<id>.ngrok.io'; | |
define( 'WP_HOME', 'http://' . $ngrok_url ); | |
define( 'WP_SITEURL', 'http://' . $ngrok_url ); | |
function callback( $buffer ) { | |
global $ngrok_url; | |
$buffer = str_replace( '<your_local_url>', $ngrok_url, $buffer ); | |
return $buffer; | |
} | |
function buffer_start() { | |
ob_start( 'callback' ); | |
} | |
function buffer_end() { | |
ob_end_flush(); | |
} | |
add_action( 'wp_loaded', 'buffer_start' ); | |
add_action( 'shutdown', 'buffer_end' ); |
Updated. Thanks @Rahmon!
@felipeelia Thanks so much for this! I notice a minor issue in the example command, the host header should be --host-header=<local_url>
. Otherwise, we will get the following error running that command:
ERROR: unknown shorthand flag: 'o' in -ost-header=oss.test
For ClassifAI, we will need this line to proxy the image URLs that sent to Computer Vision
add_filter( 'wp_get_attachment_url', 'callback' );
I've updated the --host-header parameter in the example @dinhtungdu, thank you very much! Do you mind explaining a bit further why that line was needed for ClassifAI? Just so we can add a comment for people with similar problems.
Do you mind explaining a bit further why that line was needed for ClassifAI?
@felipeelia For ClassifAI, we need to proxy the image file URL because it's required by Computer Vision (which we use to process the images). We don't send the image file but the absolute URL to the API.
Small fix in callback function: