PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.9
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.9
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.9, at webp/class-wpo-webp-self-test.php

86 lines 1.8 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 $args = array(
16 'headers' => array(
17 'accept' => 'image/webp'
18 )
19 );
20
21 $upload_dir = wp_upload_dir();
22 $url = $upload_dir['baseurl']. '/wpo/images/wpo_logo_small.png.webp';
23
24 $response = wp_remote_get($url, $args);
25
26 if (is_wp_error($response)) return false;
27 if (200 != $response['response']['code']) return false;
28
29 $headers = wp_remote_retrieve_headers($response);
30 if (is_a($headers, 'Requests_Utility_CaseInsensitiveDictionary')) {
31 $headers = $headers->getAll();
32 if (isset($headers['content-type']) && 'image/webp' == $headers['content-type']) {
33 return true;
34 }
35 }
36
37 return false;
38 }
39
40 /**
41 * Decided whether webp version is served or not
42 *
43 * @return bool
44 */
45 public function is_webp_served() {
46 $args = array(
47 'headers' => array(
48 'accept' => 'image/webp'
49 )
50 );
51
52 $upload_dir = wp_upload_dir();
53 $url = $upload_dir['baseurl']. '/wpo/images/wpo_logo_small.png';
54
55 $response = wp_remote_get($url, $args);
56
57 if (is_wp_error($response)) return false;
58 if (200 != $response['response']['code']) return false;
59
60 $headers = wp_remote_retrieve_headers($response);
61 if (is_a($headers, 'Requests_Utility_CaseInsensitiveDictionary')) {
62 $headers = $headers->getAll();
63 if (isset($headers['content-type']) && 'image/webp' == $headers['content-type']) {
64 return true;
65 }
66 }
67
68 return false;
69 }
70
71 /**
72 * Returns singleton instance
73 *
74 * @return WPO_WebP_Self_Test
75 */
76 public static function get_instance() {
77 static $_instance = null;
78 if (null === $_instance) {
79 $_instance = new self();
80 }
81 return $_instance;
82 }
83 }
84
85 endif;
86