Skip to content

Instantly share code, notes, and snippets.

@aaemnnosttv
Created December 14, 2023 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaemnnosttv/baf4b8552f21f9dd994870d89c7b344e to your computer and use it in GitHub Desktop.
Save aaemnnosttv/baf4b8552f21f9dd994870d89c7b344e to your computer and use it in GitHub Desktop.
Site Kit helper plugin for sites impacted by IPv6 connection issues
<?php
/**
* Plugin Name: Site Kit by Google – IPv6 Support Helper
* Description: Helper plugin for sites impacted by IPv6 connection issues.
* Author: Evan Mattson
* Version: 0.2
*/
add_action(
'plugins_loaded',
function () {
if ( ! defined( 'GOOGLESITEKIT_VERSION' ) ) {
return;
}
add_action(
'requests-requests.before_request',
function ( $url, $headers, $data, $type, $options ) {
if ( 0 === strpos( $url, 'https://sitekit.withgoogle.com' ) ) {
$options['hooks']->register( 'curl.before_send', function ( $ch ) {
curl_setopt( $ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
} );
}
},
10,
5
);
add_filter(
'googlesitekit_force_ip_resolve',
function () {
return 'v4';
}
);
}
);
@adamdunnage
Copy link

Further documentation on the IPv6 block error in Site Kit can be found here: https://sitekit.withgoogle.com/documentation/troubleshooting/setup/#google_api_connection_fail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment