Skip to content

Instantly share code, notes, and snippets.

@zaherg
Last active August 18, 2025 08:27
Show Gist options
  • Save zaherg/cd7819300255ed80a87b52182a572b37 to your computer and use it in GitHub Desktop.
Save zaherg/cd7819300255ed80a87b52182a572b37 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: SSL Verification Control
* Description: Disables SSL verification for development and proxy usage
* Version: 1.0.0
* Author: Dev Team
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Only run in development environments
if (!defined('WP_ENVIRONMENT_TYPE') || WP_ENVIRONMENT_TYPE !== 'development') {
return;
}
/**
* Check if a proxy service is running on a specific host and port.
*
* @param string $host The host to check.
* @param integer $port The port to check.
* @param integer $timeout The connection timeout in seconds.
* @return boolean
*/
function isProxymanRunning($host = '127.0.0.1', $port = 9090, $timeout = 1)
{
// Cache result for the default host / port within a single request to avoid repeated connection attempts
static $cache = [];
$cacheKey = $host . ':' . $port . ':' . $timeout;
if (array_key_exists($cacheKey, $cache)) {
return $cache[$cacheKey];
}
// Swallow any warnings/notices from failed connection attempts regardless of global error handlers
set_error_handler(function () {
// Return true to indicate the PHP internal handler should not be called
return true;
});
$fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
// Restore previous error handler
restore_error_handler();
if ($fp) {
fclose($fp);
$cache[$cacheKey] = true;
return true;
}
$cache[$cacheKey] = false;
return false;
}
// Define constants if not already defined
if (!defined('USE_PROXYMAN')) {
$isRunning = isProxymanRunning();
define('USE_PROXYMAN', $isRunning);
}
if (!defined('IGNORE_SSL')) {
define('IGNORE_SSL', getenv('IGNORE_SSL') || false);
}
// Proxyman configuration
if (isProxymanRunning()) {
if (!defined('WP_PROXY_HOST')) {
define('WP_PROXY_HOST', '127.0.0.1');
}
if (!defined('WP_PROXY_PORT')) {
define('WP_PROXY_PORT', '9090');
}
// Disable SSL verification for HTTPS requests
add_filter('https_ssl_verify', '__return_false');
// Disable SSL verification for all HTTP requests
add_filter('http_request_args', function($args, $url) {
$args['sslverify'] = false;
$args['reject_unsafe_urls'] = false;
$args['timeout'] = 30;
return $args;
}, 10, 2);
}
// Global SSL ignore
if (IGNORE_SSL) {
// Disable SSL verification for HTTPS requests
add_filter('https_ssl_verify', '__return_false');
// Disable SSL verification for all HTTP requests
add_filter('http_request_args', function($args, $url) {
$args['sslverify'] = false;
$args['reject_unsafe_urls'] = false;
return $args;
}, 10, 2);
// Disable SSL peer verification
add_filter('https_local_ssl_verify', '__return_false');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment