PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.4.2
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.4.2
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / inc / functions / api.php

api.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.4.2, at inc/functions/api.php

61 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
3
4 /**
5 * Check if external requests are blocked for Imagify.
6 *
7 * @since 1.0
8 *
9 * return bool True if Imagify API can't be called
10 */
11 function is_imagify_blocked() {
12 if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL ) {
13 return false;
14 }
15
16 if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) {
17 $accessible_hosts = explode( ',', WP_ACCESSIBLE_HOSTS );
18 $accessible_hosts = array_map( 'trim', $accessible_hosts );
19
20 if ( in_array( '*.imagify.io', $accessible_hosts ) ) {
21 return false;
22 }
23 }
24
25 return true;
26 }
27
28 /**
29 * Determine if the Imagify API is available by checking the API version.
30 *
31 * @since 1.0
32 *
33 * @return bool True if the Imagify API is available.
34 */
35 function is_imagify_servers_up() {
36 static $imagify_api_version = null;
37
38 if ( null !== $imagify_api_version ) {
39 return $imagify_api_version;
40 }
41
42 $transient_name = 'imagify_check_api_version';
43 $transient_expiration = 3 * MINUTE_IN_SECONDS;
44
45 if ( get_site_transient( $transient_name ) ) {
46 $imagify_api_version = true;
47 return true;
48 }
49
50 if ( is_wp_error( get_imagify_api_version() ) ) {
51 $imagify_api_version = false;
52 set_site_transient( $transient_name, 0, $transient_expiration );
53
54 return false;
55 }
56
57 $imagify_api_version = true;
58 set_site_transient( $transient_name, 1, $transient_expiration );
59
60 return true;
61 }