Skip to content

Instantly share code, notes, and snippets.

@verygoodplugins
Last active April 4, 2024 21:36
Show Gist options
  • Save verygoodplugins/53b4e94bed93dba6652e6320c463a40f to your computer and use it in GitHub Desktop.
Save verygoodplugins/53b4e94bed93dba6652e6320c463a40f to your computer and use it in GitHub Desktop.
Bypass WordPress' unsafe URL check for CRM connection
<?php
/**
*
* This sometimes fixes the error "A valid URL was not provided." wen connecting to self
* hosted CRMs like Mautic, FluentCRM, or FunnelKit.
*
* @param array $args HTTP request arguments.
* @param string $url The request URL.
* @return array HTTP request arguments.
*/
function allow_insecure_urls( $args, $url ) {
if ( function_exists( 'wp_fusion' ) && false !== strpos( $url, wp_fusion()->crm->url ) ) {
$args['reject_unsafe_urls'] = false;
}
return $args;
}
add_filter( 'http_request_args', 'allow_insecure_urls', 100, 2 );
// Sometimes this works as well
add_filter( 'http_request_host_is_external', '__return_true' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment