Skip to content

Instantly share code, notes, and snippets.

@golderweb
Last active January 21, 2024 19:16
Show Gist options
  • Save golderweb/3a2aaec2d56125cc004e to your computer and use it in GitHub Desktop.
Save golderweb/3a2aaec2d56125cc004e to your computer and use it in GitHub Desktop.
Wordpress (MU-)Plugin: cURL disable IPv6
<?php
/**
* @package curl-no-ipv6
* @version 1.0
* @since 1.0
*/
/*
Plugin Name: cURL no IPv6
Plugin URI: https:
Description: On systems where cURL is compiled with IPv6, Requests to Wordpress Update API will timeout since cURL tries it about 15s. Since the timeout defined by WordPress is 3s/5s/10s this will breake the Updater. This Plugin simply forces cURL to use IPv4 only.
Author: GOLDERWEB – Jonathan Golder
Version: 1.0
Author URI: http://golderweb.de/
*/
/*
* Copyright 2014 GOLDERWEB – Jonathan Golder <jonathan@golderweb.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
// Safety first
defined( 'ABSPATH' ) OR die();
/**
* Sets CURLOPT_IPRESOLVE to CURL_IPRESOLVE_V4 for cURL-Handle provided as parameter
*
* @param resource $handle A cURL handle returned by curl_init()
* @return resource $handle A cURL handle returned by curl_init() with CURLOPT_IPRESOLVE set to CURL_IPRESOLVE_V4
*
*/
function gw_curl_setopt_ipresolve( $handle ){
curl_setopt( $handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
return $handle;
}
// Add function to hook 'http_api_curl' with priority 10 and expecting 1 parameter.
if( function_exists( 'gw_curl_setopt_ipresolve' ) ){
add_action( 'http_api_curl', 'gw_curl_setopt_ipresolve', 10, 1);
}
@dbalabka
Copy link

Following line is redundant:
if( function_exists( 'gw_curl_setopt_ipresolve' ) ){

@dalbert2
Copy link

dalbert2 commented Jan 21, 2024

Thank you for creating this and sorry for the dumb question, but how do you install this in WP?
(I'm running WP on arch linux. I'm very familiar with linux and software development, but not PHP or the WP ecosystem)

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