PluginProbe ʕ •ᴥ•ʔ
Aruba HiSpeed Cache / 3.0.7
Aruba HiSpeed Cache v3.0.7
3.0.14 3.0.13 1.2.4 1.2.5 1.2.6 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.18 2.0.19 2.0.20 2.0.21 2.0.22 2.0.23 2.0.24 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3
aruba-hispeed-cache / src / AHSC_Functions.php
aruba-hispeed-cache / src Last commit date
APC 3 months ago Events 3 months ago Purger 3 months ago assets 3 months ago AHSC_Apc.php 3 months ago AHSC_Check.php 3 months ago AHSC_Config.php 3 months ago AHSC_Dboptimization.php 3 months ago AHSC_Functions.php 3 months ago AHSC_HtmlOptimizer.php 3 months ago AHSC_Lazyload.php 3 months ago AHSC_Preconnect.php 3 months ago AHSC_Static.php 3 months ago AHSC_Version.php 3 months ago AHSC_Warmer.php 3 months ago AHSC_XmlRPC.php 3 months ago index.php 3 months ago
AHSC_Functions.php
390 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5 use ArubaSPA\HiSpeedCache\Debug\Logger;
6
7 /**
8 * operation at plugin activation
9 * @return void
10 */
11 function AHSC_activation( ) {
12 // Get the option.
13 $check=AHSC_check();
14 if(!$check['is_aruba_server']){
15 AHSC_deactivate_me();
16 wp_die( esc_attr(ahsc_get_check_notice($check)), 'Aruba HiSpeed Cache dependency check', array( 'back_link' => true ) );
17 }else{
18 $options = AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS'];
19 if ( ! $options ) {
20 $options = array_map(
21 function( $opt ) {
22 return $opt['default'];
23 },
24 AHSC_OPTIONS_LIST_DEFAULT
25 );
26 }
27 \update_site_option( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'] , $options );
28 \update_site_option( 'aruba_hispeed_cache_version', AHSC_CONSTANT['ARUBA_HISPEED_CACHE_VERSION']);
29
30 AHSC_remove_htaccess();
31 if(array_key_exists('ahsc_static_cache',AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS'])){
32 if(isset(AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_static_cache'])){
33 if(AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_static_cache']){
34 AHSC_edit_htaccess();
35 }
36 }
37 }
38 }
39 }
40 /**
41 * operation at plugin deactivation
42 * @return void
43 */
44 function AHSC_deactivation( ) {
45
46 \delete_site_option( 'aruba_hispeed_cache_options' );
47 \delete_site_option( 'aruba_hispeed_cache_version');
48 AHSC_remove_htaccess();
49 }
50 /**
51 * operation at plugin check requirement
52 * @return void
53 */
54 function AHSC_deactivate_me() {
55 if ( \function_exists( 'deactivate_plugins' ) ) {
56 \deactivate_plugins( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_BASENAME']);
57 }
58 }
59 /**
60 * create Notice in plugin admin page
61 *
62 * @param $handle string notice html id
63 * @param $html_class string notice general class es error,warning etc.etc.
64 * @param $content string notice content
65 *
66 */
67 function AHSC_Notice_Render( $handle, $html_class, $content, $return=false) {
68 $HTML_CLASS = array(
69 'error' => 'notice notice-error',
70 'warning' => 'notice notice-warning',
71 'success' => 'notice notice-success',
72 'info ' => 'notice notice-info',
73 );
74
75 if(!$return){
76 printf(
77 '<div id="%1$s" class="%2$s"><p>%3$s</p></div>',
78 esc_attr( $handle ),
79 esc_attr( $HTML_CLASS[$html_class] ),
80 wp_kses_post( $content )
81 );
82 }else{
83 return sprintf(
84 '<div id="%1$s" class="%2$s"><p>%3$s</p></div>',
85 esc_attr( $handle ),
86 esc_attr( $HTML_CLASS[$html_class] ),
87 wp_kses_post( $content )
88 );
89 }
90 }
91
92 /**
93 * create link in plugin page
94 * @return void
95 */
96 function AHSC_plugin_action_links($actions){
97
98 $settings_link = \sprintf(
99 '<a href="%s">%s</a>',
100 (( ! is_multisite() ) ? admin_url( 'options-general.php?page=aruba-hispeed-cache') : network_admin_url('settings.php?page=aruba-hispeed-cache')) ,
101 \esc_html(__( 'Settings', 'aruba-hispeed-cache' ))
102 );
103
104 $support_link = \sprintf(
105 '<a href="%s" target="_blank">%s</a>',
106 AHSC_LOCALIZE_LINK['link_assistance'][strtolower(substr( get_bloginfo ( 'language' ), 0, 2 ))],
107 \esc_html(__( 'Customer support', 'aruba-hispeed-cache' ))
108 );
109
110 \array_unshift( $actions, $settings_link, $support_link );
111
112 return $actions;
113
114 }
115
116 if ( ! \function_exists( 'ahsc_get_site_home_url' ) ) {
117 /**
118 * Return the complete home url of site.
119 *
120 * @return string
121 */
122 function ahsc_get_site_home_url() {
123 $home_uri = \trailingslashit( \home_url() );
124
125 if ( \function_exists( 'icl_get_home_url' ) ) {
126 $home_uri = \trailingslashit( \icl_get_home_url() );
127 }
128
129 return $home_uri;
130 }
131 }
132 /*
133
134 if ( ! \function_exists( 'ahsc_save_options' ) ) {
135 **
136 * Save plugin options
137 *
138 * @return void
139 *
140 function ahsc_save_options( ) {
141 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] ) {
142 if ( isset( $_POST['ahsc_settings_save'] ) && isset( $_POST['ahs-settings-nonce'] ) && \wp_verify_nonce( \sanitize_key( \wp_unslash( $_POST['ahs-settings-nonce'] ) ), 'ahs-save-settings-nonce' ) ) {
143 $new_options = array();
144 //var_dump(ABSPATH . 'wp-config.php');
145 $wpc_transformer = new HASC_WPCT( ABSPATH . 'wp-config.php' );
146 foreach ( array_keys( AHSC_OPTIONS_LIST ) as $opt_key ) {
147 if($opt_key==="ahsc_cron_status" ){
148
149 if(isset($_POST[ $opt_key ])){
150 //var_dump("non disabilito cron ");
151 $wpc_transformer->update( 'constant', 'DISABLE_WP_CRON', 'false', array( 'raw' => true, 'normalize' => true ));
152 $new_options[ $opt_key ]= 'false';
153 }else{
154 //var_dump("disabilito cron ");
155 $wpc_transformer->update( 'constant', 'DISABLE_WP_CRON', 'true', array( 'raw' => true, 'normalize' => true ));
156 $new_options[ $opt_key ]= 'true';
157 }
158
159 }elseif($opt_key==="ahsc_cron_time"){
160
161 if(isset($_POST[ $opt_key ])){
162 //var_dump("setto time ");
163 $wpc_transformer->update( 'constant', 'WP_CRON_LOCK_TIMEOUT', "'".absint($_POST[ $opt_key ])."'", array( 'raw' => true, 'normalize' => true ));
164 $new_options[ $opt_key ]= sanitize_text_field( wp_unslash($_POST[ $opt_key ]));
165 }else{
166 //var_dump("non setto time ");
167 $wpc_transformer->remove('constant', 'WP_CRON_LOCK_TIMEOUT');
168 }
169 }elseif($opt_key!=="ahsc_dns_preconnect_domains"){
170 $new_options[ $opt_key ] = ( isset( $_POST[ $opt_key ] ) ) ? true : false;
171 }else{
172 if(isset( $_POST[ $opt_key ] ) ){
173 $trans_domain_list = explode( "\n", trim( sanitize_text_field( wp_unslash($_POST[ $opt_key ])) ) );
174 foreach ( $trans_domain_list as $index => $string ) {
175 if ( strpos( $string, $_SERVER['SERVER_NAME'] ) !== false ) {
176 unset( $trans_domain_list[ $index ] );
177 }
178 }
179 $new_options[ $opt_key ] =$trans_domain_list;
180 }else{
181 $new_options[ $opt_key ] ="";
182 }
183 }
184 }
185
186 if ( \update_site_option( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'], $new_options ) ) {
187 $content = \esc_html( __('Settings saved.', 'aruba-hispeed-cache') );
188 AHSC_Notice_Render('ahs_settings_saved', 'success',$content);
189 }
190 }
191 }
192 }
193 }
194
195 */
196 if ( ! \function_exists( 'ahsc_reset_options' ) ) {
197 /**
198 * Reset plugin options
199 *
200 * @return void
201 */
202 function ahsc_reset_options( ) {
203 $new_options = array();
204
205 foreach ( array_keys( AHSC_OPTIONS_LIST_DEFAULT ) as $opt_key ) {
206 $new_options[ $opt_key ] = AHSC_OPTIONS_LIST_DEFAULT[$opt_key]['default'];
207 }
208 $wpc_transformer = new HASC_WPCT( ABSPATH . 'wp-config.php' );
209
210 $wpc_transformer->remove('constant', 'DISABLE_WP_CRON');
211 $wpc_transformer->remove('constant', 'WP_CRON_LOCK_TIMEOUT');
212
213 if ( isset( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_apc'] ) &&
214 AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_apc'] ){
215 // phpcs:ignore
216 @unlink( WP_CONTENT_DIR . '/object-cache.php' );
217 }
218
219 \update_site_option( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'], $new_options );
220
221 $content = \esc_html( __('Original settings restored.', 'aruba-hispeed-cache') );
222 return $content;
223
224 }
225 }
226
227
228 if ( ! \function_exists( 'ahsc_has_transient' ) ) {
229
230 /**
231 * It checks whether a transinet exists if yes, it returns the value otherwise it returns false.
232 *
233 * @param string $transient .
234 * @return mixed
235 */
236 function ahsc_has_transient( $transient ) {
237 $temp=$GLOBALS['_wp_using_ext_object_cache'];
238 $GLOBALS['_wp_using_ext_object_cache'] = false;
239 $transient_value = ( \is_multisite() ) ? \get_site_transient( (string) $transient ) : \get_transient( (string) $transient );
240 $_value=( false !== $transient_value ) ? $transient_value : false;;
241 $GLOBALS['_wp_using_ext_object_cache'] = $temp;
242 return $_value;
243 }
244 }
245
246 if ( ! \function_exists( 'ahsc_set_transient' ) ) {
247
248 /**
249 * Undocumented function
250 *
251 * @param string $transient .
252 * @param mixed $value .
253 * @param integer $expiration .
254 * @return bool
255 */
256 function ahsc_set_transient( $transient, $value, $expiration = 0 ) {
257 $temp=$GLOBALS['_wp_using_ext_object_cache'];
258 $GLOBALS['_wp_using_ext_object_cache'] = false;
259 $_value=( \is_multisite() ) ?
260 \set_site_transient( $transient, $value, $expiration ) :
261 \set_transient( $transient, $value, $expiration );
262 $GLOBALS['_wp_using_ext_object_cache'] = $temp;
263 return $_value;
264 }
265 }
266
267 if ( ! \function_exists( 'ahsc_delete_transient' ) ) {
268
269 /**
270 * Undocumented function
271 *
272 * @param string $transient .
273 * @return bool
274 */
275 function ahsc_delete_transient( $transient ) {
276 $temp=$GLOBALS['_wp_using_ext_object_cache'];
277 $GLOBALS['_wp_using_ext_object_cache'] = false;
278 if(class_exists('ArubaSPA\HiSpeedCache\Debug\Logger')) {
279 AHSC_log( 'hook::transient::delete', __NAMESPACE__ . '::' . __FUNCTION__, 'debug' );
280 // Logger.
281 }
282 $_value=( \is_multisite() ) ?
283 \delete_site_transient( $transient ) :
284 \delete_transient( $transient );
285 $GLOBALS['_wp_using_ext_object_cache'] = $temp;
286 return $_value;
287 }
288 }
289
290 if ( ! \function_exists( 'ahsc_has_notice' ) ) {
291
292 /**
293 * Return bool if transient notice check is set.
294 *
295 * @param bool $remove Set to true to clean the transinte if present.
296 * @return mixed
297 *
298 * @SuppressWarnings(PHPMD.StaticAccess)
299 */
300 function ahsc_has_notice( $remove = null ) {
301 $has_notice = ahsc_has_transient( AHSC_CHECKER['transient_name'] );
302
303 if ( false !== $has_notice && true === $remove ) {
304 if ( \is_multisite() ) {
305 \delete_site_transient(AHSC_CHECKER['transient_name'] );
306 return false;
307 }
308
309 \delete_transient( AHSC_CHECKER['transient_name']);
310 return false;
311 }
312
313 return $has_notice;
314 }
315 }
316
317 if ( ! \function_exists( 'ahsc_get_debug_file_content' ) ) {
318 /**
319 * Return the contente of log file.
320 *
321 * @return string
322 */
323 function ahsc_get_debug_file_content() {
324 global $wp_filesystem,$logger;
325 \WP_Filesystem();
326 if (class_exists('ArubaSPA\HiSpeedCache\Debug\Logger') ) {
327 if ( \file_exists( Logger::get_log_file_path_name() ) ) {
328 return $wp_filesystem->get_contents( Logger::get_log_file_path_name() );
329 }
330 }
331 return false;
332 }
333 }
334
335 if ( ! \function_exists('ahsc_current_theme_is_fse_theme' ) ) {
336 /**
337 * The function checks if the current theme is a Full Site Editing (FSE) theme in PHP.
338 *
339 * @return bool value indicating whether the current theme is a Full Site Editing (FSE) theme.
340 */
341 function ahsc_current_theme_is_fse_theme() {
342 if ( function_exists( 'wp_is_block_theme' ) ) {
343 return (bool) wp_is_block_theme();
344 }
345 if ( function_exists( 'gutenberg_is_fse_theme' ) ) {
346 return (bool) gutenberg_is_fse_theme();
347 }
348 return false;
349 }
350 }
351
352 /**
353 * Write a debug info in to file.
354 *
355 * @param string $message the messagge.
356 * @param string $name the name of message.
357 * @param string $type the type of log debug|info|warning|error.
358 * @return void
359 */
360 function AHSC_log( $message, $name = '', $type = 'info' ) {
361
362 if ( class_exists('\ArubaSPA\HiSpeedCache\Debug\Logger') ) {
363
364 //die(var_export(Logger::$logger_ready,true));
365 switch ( $type ) {
366 case 'debug':
367 Logger::debug( $message, $name );
368 break;
369 case 'info':
370 Logger::info( $message, $name );
371 break;
372 case 'warning':
373 Logger::warning( $message, $name );
374 break;
375 case 'error':
376 Logger::error( $message, $name );
377 break;
378 }
379 }
380 }
381
382 /** Let's get rid of the annoying Site Health warning about no auto-updates. We don't want autoupdates because we want to do backups before updates!
383 */
384
385 add_filter('site_status_tests', function (array $test_type) {
386
387 unset($test_type['async']['background_updates']); // remove warning about Automatic background updates
388
389 return $test_type;
390 }, 10, 1);