Skip to content

Commit 7cda247

Browse files
author
Jippe Holwerda
committed
Added version specific user agent for requests to TinyPNG webservice.
1 parent 8f36934 commit 7cda247

5 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/class-tiny-compress-curl.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ protected function shrink_options($input) {
2828
CURLOPT_RETURNTRANSFER => true,
2929
CURLOPT_HEADER => true,
3030
CURLOPT_CAINFO => self::get_ca_file(),
31-
CURLOPT_SSL_VERIFYPEER => true
31+
CURLOPT_SSL_VERIFYPEER => true,
32+
CURLOPT_USERAGENT => Tiny_WP_Base::plugin_identification()
3233
);
3334
}
3435

src/class-tiny-compress-fopen.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ protected function shrink_options($input) {
2525
'method' => 'POST',
2626
'header' => array(
2727
'Content-type: image/png',
28-
'Authorization: Basic ' . base64_encode('api:' . $this->api_key)
28+
'Authorization: Basic ' . base64_encode('api:' . $this->api_key),
29+
'User-Agent: ' . Tiny_WP_Base::plugin_identification(),
2930
),
3031
'content' => $input
3132
),

src/class-tiny-plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ public function admin_init() {
6060

6161
public function enqueue_scripts() {
6262
wp_enqueue_style(self::NAME .'_admin', plugins_url('/styles/admin.css', __FILE__),
63-
array(), self::VERSION);
63+
array(), self::plugin_version());
6464

6565
$handle = self::NAME .'_admin';
6666
wp_register_script($handle, plugins_url('/scripts/admin.js', __FILE__),
67-
array(), self::VERSION, true);
67+
array(), self::plugin_version(), true);
6868
wp_localize_script($handle, 'tinypngImageCompressL10n', array(
6969
'bulkAction' => self::translate('Compress all uncompressed sizes'),
7070
));

src/class-tiny-wp-base.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020

2121
abstract class Tiny_WP_Base {
2222
const NAME = 'tiny-compress-images';
23-
const VERSION = '1.0.0';
23+
24+
public static function plugin_version() {
25+
$plugin_data = get_plugin_data(dirname(__FILE__) . '/../tiny-compress-images.php');
26+
return $plugin_data['Version'];
27+
}
28+
29+
public static function plugin_identification() {
30+
return 'Wordpress/' . $GLOBALS['wp_version'] . ' Tiny/' . self::plugin_version() . ' cURL';
31+
}
2432

2533
protected static function translate($phrase) {
2634
return translate($phrase, self::NAME);

tiny-compress-images.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Plugin Name: Tiny Compress Images
4-
* Plugin URI: https://tinypng.com
3+
* Plugin Name: Compress JPEG & PNG images
4+
* Plugin URI: https://wordpress.org/plugins/tiny-compress-images
55
* Description: Speed up your website. Optimize your JPEG and PNG images automatically with TinyPNG.
66
* Version: 1.0.0
77
* Author: TinyPNG

0 commit comments

Comments
 (0)