PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / webp / class-wpo-webp-self-test.php

class-wpo-webp-self-test.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at webp/class-wpo-webp-self-test.php

87 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('WPO_VERSION')) die('No direct access allowed');
4
5 if (!class_exists('WPO_WebP_Self_Test')) :
6
7 class WPO_WebP_Self_Test {
8
9 /**
10 * Decided whether we can get a webp image or not
11 *
12 * @return bool
13 */
14 public function get_webp_image() {
15 WP_Optimize()->log('Checking if we can get webp image');
16 $args = array(
17 'headers' => array(
18 'accept' => 'image/webp'
19 )
20 );
21
22 $upload_dir = wp_upload_dir();
23 $url = $upload_dir['baseurl']. '/wpo/images/wpo_logo_small.png.webp';
24
25 $response = wp_remote_get($url, $args);
26
27 if (is_wp_error($response)) return false;
28 if (200 != $response['response']['code']) return false;
29
30 $headers = wp_remote_retrieve_headers($response);
31 if (is_a($headers, 'Requests_Utility_CaseInsensitiveDictionary')) {
32 $headers = $headers->getAll();
33 if (isset($headers['content-type']) && 'image/webp' == $headers['content-type']) {
34 return true;
35 }
36 }
37
38 return false;
39 }
40
41 /**
42 * Decided whether webp version is served or not
43 *
44 * @return bool
45 */
46 public function is_webp_served() {
47 $args = array(
48 'headers' => array(
49 'accept' => 'image/webp'
50 )
51 );
52
53 $upload_dir = wp_upload_dir();
54 $url = $upload_dir['baseurl']. '/wpo/images/wpo_logo_small.png';
55
56 $response = wp_remote_get($url, $args);
57
58 if (is_wp_error($response)) return false;
59 if (200 != $response['response']['code']) return false;
60
61 $headers = wp_remote_retrieve_headers($response);
62 if (is_a($headers, 'Requests_Utility_CaseInsensitiveDictionary')) {
63 $headers = $headers->getAll();
64 if (isset($headers['content-type']) && 'image/webp' == $headers['content-type']) {
65 return true;
66 }
67 }
68
69 return false;
70 }
71
72 /**
73 * Returns singleton instance
74 *
75 * @return WPO_WebP_Self_Test
76 */
77 public static function get_instance() {
78 static $_instance = null;
79 if (null === $_instance) {
80 $_instance = new self();
81 }
82 return $_instance;
83 }
84 }
85
86 endif;
87