Created
December 14, 2023 20:26
-
-
Save aaemnnosttv/baf4b8552f21f9dd994870d89c7b344e to your computer and use it in GitHub Desktop.
Site Kit helper plugin for sites impacted by IPv6 connection issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
} | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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