PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.7
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.7
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 / options.php

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

135 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' );
3
4 /**
5 * A wrapper to easily get imagify option.
6 *
7 * @since 1.0
8 * @since 1.7 The $default parameter was removed.
9 *
10 * @param string $key The option name.
11 * @return mixed The option value.
12 */
13 function get_imagify_option( $key ) {
14 return Imagify_Options::get_instance()->get( $key );
15 }
16
17 /**
18 * Update an Imagify option.
19 *
20 * @since 1.6
21 * @author Remy Perona
22 *
23 * @param string $key The option name.
24 * @param mixed $value The value of the option.
25 */
26 function update_imagify_option( $key, $value ) {
27 Imagify_Options::get_instance()->set( $key, $value );
28 }
29
30 /**
31 * Determine if the Imagify API key is valid.
32 *
33 * @since 1.0
34 *
35 * @return bool True if the API key is valid.
36 */
37 function imagify_valid_key() {
38 static $is_valid;
39
40 if ( isset( $is_valid ) ) {
41 return $is_valid;
42 }
43
44 if ( ! Imagify_Options::get_instance()->get( 'api_key' ) ) {
45 $is_valid = false;
46 return $is_valid;
47 }
48
49 if ( get_site_transient( 'imagify_check_licence_1' ) ) {
50 $is_valid = true;
51 return $is_valid;
52 }
53
54 if ( is_wp_error( get_imagify_user() ) ) {
55 $is_valid = false;
56 return $is_valid;
57 }
58
59 $is_valid = true;
60 set_site_transient( 'imagify_check_licence_1', $is_valid, YEAR_IN_SECONDS );
61
62 return $is_valid;
63 }
64
65 /**
66 * Autoload network options and put them in cache.
67 *
68 * @since 1.7
69 * @author Grégory Viguier
70 * @source SecuPress
71 *
72 * @param array $option_names A list of option names to cache.
73 * @param string|array $prefixes A prefix for the option names. Handy for transients for example (`_site_transient_` and `_site_transient_timeout_`).
74 */
75 function imagify_load_network_options( $option_names, $prefixes = '' ) {
76 global $wpdb;
77
78 $prefixes = (array) $prefixes;
79
80 if ( ! $option_names || count( $option_names ) * count( $prefixes ) === 1 ) {
81 return;
82 }
83
84 // Get values.
85 $not_exist = array();
86 $option_names = array_flip( array_flip( $option_names ) );
87 $options = '';
88
89 foreach ( $prefixes as $prefix ) {
90 $options .= "'$prefix" . implode( "','$prefix", esc_sql( $option_names ) ) . "',";
91 }
92
93 $options = rtrim( $options, ',' );
94
95 if ( is_multisite() ) {
96 $network_id = function_exists( 'get_current_network_id' ) ? get_current_network_id() : (int) $wpdb->siteid;
97 $cache_prefix = "$network_id:";
98 $notoptions_key = "$network_id:notoptions";
99 $cache_group = 'site-options';
100 $results = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key as name, meta_value as value FROM $wpdb->sitemeta WHERE meta_key IN ( $options ) AND site_id = %d", $network_id ), OBJECT_K ); // WPCS: unprepared SQL ok.
101 } else {
102 $cache_prefix = '';
103 $notoptions_key = 'notoptions';
104 $cache_group = 'options';
105 $results = $wpdb->get_results( "SELECT option_name as name, option_value as value FROM $wpdb->options WHERE option_name IN ( $options )", OBJECT_K ); // WPCS: unprepared SQL ok.
106 }
107
108 foreach ( $prefixes as $prefix ) {
109 foreach ( $option_names as $option_name ) {
110 $option_name = $prefix . $option_name;
111
112 if ( isset( $results[ $option_name ] ) ) {
113 // Cache the value.
114 $value = $results[ $option_name ]->value;
115 $value = maybe_unserialize( $value );
116 wp_cache_set( "$cache_prefix$option_name", $value, $cache_group );
117 } else {
118 // No value.
119 $not_exist[ $option_name ] = true;
120 }
121 }
122 }
123
124 if ( ! $not_exist ) {
125 return;
126 }
127
128 // Cache the options that don't exist in the DB.
129 $notoptions = wp_cache_get( $notoptions_key, $cache_group );
130 $notoptions = is_array( $notoptions ) ? $notoptions : array();
131 $notoptions = array_merge( $notoptions, $not_exist );
132
133 wp_cache_set( $notoptions_key, $notoptions, $cache_group );
134 }
135