PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 1.9.1.1
LiteSpeed Cache v1.9.1.1
trunk 1.0.15 1.9.1.1 2.9.9.2 3.6.4 4.6 5.7.0.1 6.5.4 7.0.0.1 7.0.1 7.1 7.2 7.3 7.3.0.1 7.4 7.5 7.5.0.1 7.6 7.6.1 7.6.2 7.7 7.8 7.8.0.1 7.8.1
litespeed-cache / inc / activation.class.php
litespeed-cache / inc Last commit date
activation.class.php 8 years ago api.class.php 8 years ago cdn.class.php 8 years ago config.class.php 8 years ago control.class.php 8 years ago crawler-sitemap.class.php 8 years ago crawler.class.php 8 years ago data.class.php 8 years ago esi.class.php 8 years ago gui.class.php 8 years ago import.class.php 8 years ago litespeed-cache.class.php 8 years ago litespeed.autoload.php 8 years ago log.class.php 8 years ago media.class.php 8 years ago object.class.php 8 years ago object.lib.php 8 years ago optimize.class.php 8 years ago optimizer.class.php 8 years ago purge.class.php 8 years ago router.class.php 8 years ago tag.class.php 8 years ago task.class.php 8 years ago utility.class.php 8 years ago vary.class.php 8 years ago
activation.class.php
243 lines
1 <?php
2 /**
3 * The plugin activation class.
4 *
5 * @since 1.1.0
6 * @since 1.5 Moved into /inc
7 * @package LiteSpeed_Cache
8 * @subpackage LiteSpeed_Cache/inc
9 * @author LiteSpeed Technologies <info@litespeedtech.com>
10 */
11 class LiteSpeed_Cache_Activation
12 {
13 const NETWORK_TRANSIENT_COUNT = 'lscwp_network_count' ;
14
15 /**
16 * The activation hook callback.
17 *
18 * Attempts to set up the advanced cache file. If it fails for any reason,
19 * the plugin will not activate.
20 *
21 * @since 1.0.0
22 * @access public
23 */
24 public static function register_activation()
25 {
26 $count = 0 ;
27 ! defined( 'LSCWP_LOG_TAG' ) && define( 'LSCWP_LOG_TAG', 'Activate_' . get_current_blog_id() ) ;
28
29 self::try_copy_advanced_cache() ;
30 LiteSpeed_Cache_Config::wp_cache_var_setter( true ) ;
31
32 if ( is_multisite() ) {
33 $count = self::get_network_count() ;
34 if ( $count !== false ) {
35 $count = intval( $count ) + 1 ;
36 set_site_transient( self::NETWORK_TRANSIENT_COUNT, $count, DAY_IN_SECONDS ) ;
37 }
38 }
39 do_action( 'litespeed_cache_api_load_thirdparty' ) ;
40 LiteSpeed_Cache_Config::get_instance()->plugin_activation( $count ) ;
41 LiteSpeed_Cache_Admin_Report::get_instance()->generate_environment_report() ;
42
43 if ( defined( 'LSCWP_PLUGIN_NAME' ) ) {
44 set_transient( LiteSpeed_Cache::WHM_TRANSIENT, LiteSpeed_Cache::WHM_TRANSIENT_VAL ) ;
45 }
46
47 // Register crawler cron task
48 LiteSpeed_Cache_Task::update() ;
49 }
50
51 /**
52 * Uninstall plugin
53 * @since 1.1.0
54 */
55 public static function uninstall_litespeed_cache()
56 {
57 LiteSpeed_Cache_Task::clear() ;
58 LiteSpeed_Cache_Admin_Rules::get_instance()->clear_rules( true ) ;
59 delete_option( LiteSpeed_Cache_Config::OPTION_NAME ) ;
60 if ( is_multisite() ) {
61 delete_site_option( LiteSpeed_Cache_Config::OPTION_NAME ) ;
62 }
63 }
64
65 /**
66 * Get the blog ids for the network. Accepts function arguments.
67 *
68 * Will use wp_get_sites for WP versions less than 4.6
69 *
70 * @since 1.0.12
71 * @access public
72 * @param array $args Arguments to pass into get_sites/wp_get_sites.
73 * @return array The array of blog ids.
74 */
75 public static function get_network_ids( $args = array() )
76 {
77 global $wp_version ;
78 if ( version_compare( $wp_version, '4.6', '<' ) ) {
79 $blogs = wp_get_sites( $args ) ;
80 if ( ! empty( $blogs ) ) {
81 foreach ( $blogs as $key => $blog ) {
82 $blogs[ $key ] = $blog[ 'blog_id' ] ;
83 }
84 }
85 }
86 else {
87 $args[ 'fields' ] = 'ids' ;
88 $blogs = get_sites( $args ) ;
89 }
90 return $blogs ;
91 }
92
93 /**
94 * Gets the count of active litespeed cache plugins on multisite.
95 *
96 * @since 1.0.12
97 * @access private
98 * @return mixed The count on success, false on failure.
99 */
100 private static function get_network_count()
101 {
102 $count = get_site_transient( self::NETWORK_TRANSIENT_COUNT ) ;
103 if ( $count !== false ) {
104 return intval( $count ) ;
105 }
106 // need to update
107 $default = array() ;
108 $count = 0 ;
109
110 $sites = self::get_network_ids( array( 'deleted' => 0 ) ) ;
111 if ( empty( $sites ) ) {
112 return false ;
113 }
114
115 foreach ( $sites as $site ) {
116 $bid = is_object( $site ) && property_exists( $site, 'blog_id' ) ? $site->blog_id : $site ;
117 $plugins = get_blog_option( $bid , 'active_plugins', $default ) ;
118 if ( in_array( LSCWP_BASENAME, $plugins, true ) ) {
119 $count++ ;
120 }
121 }
122 if ( is_plugin_active_for_network( LSCWP_BASENAME ) ) {
123 $count++ ;
124 }
125 return $count ;
126 }
127
128 /**
129 * Is this deactivate call the last active installation on the multisite
130 * network?
131 *
132 * @since 1.0.12
133 * @access private
134 * @return bool True if yes, false otherwise.
135 */
136 private static function is_deactivate_last()
137 {
138 $count = self::get_network_count() ;
139 if ( $count === false ) {
140 return false ;
141 }
142 if ( $count !== 1 ) {
143 // Not deactivating the last one.
144 $count-- ;
145 set_site_transient( self::NETWORK_TRANSIENT_COUNT, $count, DAY_IN_SECONDS ) ;
146 return false ;
147 }
148
149 delete_site_transient( self::NETWORK_TRANSIENT_COUNT ) ;
150 return true ;
151 }
152
153 /**
154 * The deactivation hook callback.
155 *
156 * Initializes all clean up functionalities.
157 *
158 * @since 1.0.0
159 * @access public
160 */
161 public static function register_deactivation()
162 {
163 LiteSpeed_Cache_Task::clear() ;
164
165 ! defined( 'LSCWP_LOG_TAG' ) && define( 'LSCWP_LOG_TAG', 'Deactivate_' . get_current_blog_id() ) ;
166
167 LiteSpeed_Cache_Purge::purge_all() ;
168
169 if ( is_multisite() ) {
170
171 if ( ! self::is_deactivate_last() ) {
172 if ( is_network_admin() ) {
173 // Still other activated subsite left, set .htaccess with only CacheLookUp
174 LiteSpeed_Cache_Admin_Rules::get_instance()->insert_wrapper() ;
175 }
176 return ;
177 }
178 }
179
180 $adv_cache_path = LSCWP_CONTENT_DIR . '/advanced-cache.php' ;
181 // this file can be generated by other cache plugin like w3tc, we only delete our own file
182 if ( file_exists( $adv_cache_path ) && is_writable( $adv_cache_path ) ) {
183 if ( strpos( file_get_contents( $adv_cache_path ), 'LSCACHE_ADV_CACHE' ) !== false ) {
184 unlink( $adv_cache_path ) ;
185 }
186 else {
187 error_log(' Keep advanced-cache.php as it belongs to other plugins' ) ;
188 }
189 }
190 else {
191 error_log( 'Failed to remove advanced-cache.php, file does not exist or is not writable!' ) ;
192 }
193
194 /**
195 * Remove object cache file if is us
196 * @since 1.8.2
197 */
198 LiteSpeed_Cache_Object::get_instance()->del_file() ;
199
200 if ( ! LiteSpeed_Cache_Config::wp_cache_var_setter( false ) ) {
201 error_log('In wp-config.php: WP_CACHE could not be set to false during deactivation!') ;
202 }
203
204 LiteSpeed_Cache_Admin_Rules::get_instance()->clear_rules( true ) ;
205
206 // delete in case it's not deleted prior to deactivation.
207 self::dismiss_whm() ;
208 }
209
210 /**
211 * Try to copy our advanced-cache.php file to the wordpress directory.
212 *
213 * @since 1.0.11
214 * @access public
215 * @return boolean True on success, false on failure.
216 */
217 public static function try_copy_advanced_cache()
218 {
219 $adv_cache_path = LSCWP_CONTENT_DIR . '/advanced-cache.php' ;
220 if ( file_exists( $adv_cache_path ) && ( filesize( $adv_cache_path ) !== 0 || ! is_writable( $adv_cache_path ) ) ) {
221 return false ;
222 }
223
224 copy( LSCWP_DIR . 'includes/advanced-cache.php', $adv_cache_path ) ;
225 include( $adv_cache_path ) ;
226 $ret = defined( 'LSCACHE_ADV_CACHE' ) ;
227 return $ret ;
228 }
229
230 /**
231 * Delete whm transient msg tag
232 *
233 * @since 1.1.1
234 * @access public
235 */
236 public static function dismiss_whm()
237 {
238 delete_transient( LiteSpeed_Cache::WHM_TRANSIENT ) ;
239 }
240
241
242 }
243