PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.9.13
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.9.13
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.9.13, at inc/functions/options.php

100 lines 3.0 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 * Autoload network options and put them in cache.
32 *
33 * @since 1.7
34 * @author Grégory Viguier
35 * @source SecuPress
36 *
37 * @param array $option_names A list of option names to cache.
38 * @param string|array $prefixes A prefix for the option names. Handy for transients for example (`_site_transient_` and `_site_transient_timeout_`).
39 */
40 function imagify_load_network_options( $option_names, $prefixes = '' ) {
41 global $wpdb;
42
43 $prefixes = (array) $prefixes;
44
45 if ( ! $option_names || count( $option_names ) * count( $prefixes ) === 1 ) {
46 return;
47 }
48
49 // Get values.
50 $not_exist = array();
51 $option_names = array_flip( array_flip( $option_names ) );
52 $options = '';
53
54 foreach ( $prefixes as $prefix ) {
55 $options .= "'$prefix" . implode( "','$prefix", esc_sql( $option_names ) ) . "',";
56 }
57
58 $options = rtrim( $options, ',' );
59
60 if ( is_multisite() ) {
61 $network_id = function_exists( 'get_current_network_id' ) ? get_current_network_id() : (int) $wpdb->siteid;
62 $cache_prefix = "$network_id:";
63 $notoptions_key = "$network_id:notoptions";
64 $cache_group = 'site-options';
65 $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.
66 } else {
67 $cache_prefix = '';
68 $notoptions_key = 'notoptions';
69 $cache_group = 'options';
70 $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.
71 }
72
73 foreach ( $prefixes as $prefix ) {
74 foreach ( $option_names as $option_name ) {
75 $option_name = $prefix . $option_name;
76
77 if ( isset( $results[ $option_name ] ) ) {
78 // Cache the value.
79 $value = $results[ $option_name ]->value;
80 $value = maybe_unserialize( $value );
81 wp_cache_set( "$cache_prefix$option_name", $value, $cache_group );
82 } else {
83 // No value.
84 $not_exist[ $option_name ] = true;
85 }
86 }
87 }
88
89 if ( ! $not_exist ) {
90 return;
91 }
92
93 // Cache the options that don't exist in the DB.
94 $notoptions = wp_cache_get( $notoptions_key, $cache_group );
95 $notoptions = is_array( $notoptions ) ? $notoptions : array();
96 $notoptions = array_merge( $notoptions, $not_exist );
97
98 wp_cache_set( $notoptions_key, $notoptions, $cache_group );
99 }
100