1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
<?php /** * Smush trait. * * @since 2.4.0 * @package Hummingbird\Core */
namespace Hummingbird\Core\Traits;
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * Trait Smush */ trait Smush { /** * Variable used to distinguish between versions of Smush. * Sets true if the Pro version is installed. False in all other cases. * * @var bool $is_smush_pro */ public $is_smush_pro = false;
/** * Check if Smush is installed. * * @return bool */ public function is_smush_installed() { if ( ! function_exists( 'get_plugins' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; }
$plugins = get_plugins(); if ( array_key_exists( 'wp-smush-pro/wp-smush.php', $plugins ) ) { $this->is_smush_pro = true; }
return array_key_exists( 'wp-smush-pro/wp-smush.php', $plugins ) || array_key_exists( 'wp-smushit/wp-smush.php', $plugins ); }
/** * Check if Smush is active. * * @return bool */ public function is_smush_enabled() { if ( ! function_exists( 'is_plugin_active' ) ) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; }
return is_plugin_active( 'wp-smush-pro/wp-smush.php' ) || is_plugin_active( 'wp-smushit/wp-smush.php' ); }
/** * Checks whether the Smush can be configured on a site or not. * * @return bool */ public function is_smush_configurable() { // If single site return true. if ( ! is_multisite() || is_network_admin() ) { return true; }
$networkwide = get_site_option( 'wp-smush-networkwide' ); return '0' !== $networkwide && false !== $networkwide; }
/** * Check if Smush has lazy load enabled. * * @return bool */ public function is_lazy_load_enabled() { if ( ! $this->is_smush_enabled() ) { return false; }
$subsite_control = get_site_option( 'wp-smush-networkwide' );
$settings = is_multisite() && ! $subsite_control ? get_site_option( 'wp-smush-settings', array() ) : get_option( 'wp-smush-settings', array() ); if ( empty( $settings ) || ! is_array( $settings ) ) { return false; }
return ! empty( $settings['lazy_load'] ) && $settings['lazy_load']; }
/** * Check if user can enable Smush lazy loading. * * @since 2.5.0 * * @return bool */ public function is_lazy_load_configurable() { // Render all pages on single site installs. if ( ! is_multisite() ) { return true; }
$access = get_site_option( 'wp-smush-networkwide' );
if ( ! $access ) { return is_network_admin() ? true : false; }
if ( '1' === $access ) { return is_network_admin() ? false : true; }
if ( is_array( $access ) ) { if ( is_network_admin() && ! in_array( 'lazy_load', $access, true ) ) { return true; }
if ( ! is_network_admin() && in_array( 'lazy_load', $access, true ) ) { return true; } }
return false; }
}
|