From aff792e7cff01c7ebf3c5d9bc22e0769fcfc2498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Viguier?= Date: Tue, 18 Dec 2018 23:22:51 +0100 Subject: [PATCH 1/2] Closes #324: Add missing cURL options --- inc/classes/class-imagify.php | 36 ++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/inc/classes/class-imagify.php b/inc/classes/class-imagify.php index 334812b96..af4f5ff05 100644 --- a/inc/classes/class-imagify.php +++ b/inc/classes/class-imagify.php @@ -11,7 +11,7 @@ class Imagify extends Imagify_Deprecated { * * @var string */ - const VERSION = '1.2'; + const VERSION = '1.2.1'; /** * The Imagify API endpoint. * @@ -454,10 +454,9 @@ private function curl_http_call( $url, $args = array() ) { return new WP_Error( 'curl', 'cURL isn\'t installed on the server.' ); } - $url = self::API_ENDPOINT . $url; - try { - $ch = @curl_init(); + $url = self::API_ENDPOINT . $url; + $ch = @curl_init(); if ( ! is_resource( $ch ) ) { throw new Exception( 'Could not initialize a new cURL handle' ); @@ -489,13 +488,36 @@ private function curl_http_call( $url, $args = array() ) { curl_setopt( $ch, CURLOPT_POSTFIELDS, $args['post_data'] ); } + if ( defined( 'CURLOPT_PROTOCOLS' ) ) { + curl_setopt( $ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS ); + } + + $user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ) ); + curl_setopt( $ch, CURLOPT_URL, $url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_HEADER, false ); curl_setopt( $ch, CURLOPT_HTTPHEADER, $this->headers ); curl_setopt( $ch, CURLOPT_TIMEOUT, $args['timeout'] ); - @curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true ); - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); + curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $args['timeout'] ); + curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent ); + @curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, false ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); + + /** + * Tell which http version to use with cURL during image optimization. + * + * @since 1.8.4.1 + * @author Grégory Viguier + * + * @param $use_version_1_0 bool True to use version 1.0. False for 1.1. Default is true. + */ + if ( apply_filters( 'imagify_curl_http_version_1_0', true ) ) { + curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); + } else { + curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); + } $response = curl_exec( $ch ); $error = curl_error( $ch ); From 2e86b2bc79c072a87028c96aca8f97f27f67ad04 Mon Sep 17 00:00:00 2001 From: Git I Hate You Date: Tue, 18 Dec 2018 23:26:35 +0100 Subject: [PATCH 2/2] Hotfix: bump plugin version to 1.8.4.1, added changelog --- imagify.php | 4 ++-- package.json | 2 +- readme.txt | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/imagify.php b/imagify.php index ec39f5599..245225a2f 100644 --- a/imagify.php +++ b/imagify.php @@ -3,7 +3,7 @@ * Plugin Name: Imagify * Plugin URI: https://wordpress.org/plugins/imagify/ * Description: Dramaticaly reduce image file sizes without losing quality, make your website load faster, boost your SEO and save money on your bandwidth using Imagify, the new most advanced image optimization tool. - * Version: 1.8.4 + * Version: 1.8.4.1 * Author: WP Media * Author URI: https://wp-media.me/ * Licence: GPLv2 @@ -17,7 +17,7 @@ defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); // Imagify defines. -define( 'IMAGIFY_VERSION', '1.8.4' ); +define( 'IMAGIFY_VERSION', '1.8.4.1' ); define( 'IMAGIFY_WP_MIN', '4.0' ); define( 'IMAGIFY_SLUG', 'imagify' ); define( 'IMAGIFY_FILE', __FILE__ ); diff --git a/package.json b/package.json index cb896343d..e915afc74 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "imagify", "description": "Imagify Image Optimizer. Dramatically reduce image file sizes without losing quality, make your website load faster, boost your SEO and save money on your bandwidth.", - "version": "1.8.4", + "version": "1.8.4.1", "homepage": "https://wordpress.org/plugins/imagify/", "license": "GPL-2.0", "private": true, diff --git a/readme.txt b/readme.txt index f212864d3..37b6d4ad3 100755 --- a/readme.txt +++ b/readme.txt @@ -138,6 +138,9 @@ When the plugin is disabled, your existing images remain optimized. Backups of t 4. Other Media Page == Changelog == += 1.8.4.1 - 2018/12/18 = +* Improvement: prevent "unknown error" messages that some users are getting since yesterday. + = 1.8.4 - 2018/11/12 = * Improvement: automatic optimization is delayed further, it now happens after the image original data is stored in the database. This new process should be more reliable. * Improvement: compatibility with wordpress.com.