PluginProbe ʕ •ᴥ•ʔ
Aruba HiSpeed Cache / 3.0.15
Aruba HiSpeed Cache v3.0.15
3.0.15 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 days ago Events 3 days ago Purger 3 days ago assets 3 days ago AHSC_Apc.php 3 days ago AHSC_Check.php 3 days ago AHSC_Config.php 3 days ago AHSC_Dboptimization.php 3 days ago AHSC_Functions.php 3 days ago AHSC_HtmlOptimizer.php 5 months ago AHSC_Lazyload.php 3 days ago AHSC_Preconnect.php 5 months ago AHSC_Static.php 4 months ago AHSC_Version.php 5 months ago AHSC_Warmer.php 3 days ago AHSC_XmlRPC.php 5 months ago index.php 5 months ago
AHSC_Functions.php
510 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 // controllo la presenza del wp-cli.
13 $is_cli = (defined('WP_CLI') && WP_CLI);
14 // Controllo se è una richiesta HTTP reale (admin)
15 $is_admin_ui = (
16 isset($_SERVER['REQUEST_METHOD']) &&
17 is_admin() &&
18 isset($_SERVER['REQUEST_URI']) &&
19 strpos(sanitize_url( wp_unslash($_SERVER['REQUEST_URI'])), 'plugins.php') !== false
20 );
21
22 if ($is_cli) {
23 // attivazione
24 AHSC_activation_operation();
25 } else{
26 if ($is_admin_ui) {
27 $check = AHSC_check();
28 if ( ! $check['is_aruba_server'] ) {
29 AHSC_deactivate_me();
30 wp_die( esc_attr( ahsc_get_check_notice( $check ) ), 'Aruba HiSpeed Cache dependency check', array( 'back_link' => true ) );
31 } else {
32 AHSC_activation_operation();
33 }
34 }
35 }
36 }
37
38 function AHSC_activation_operation(){
39 $options = AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS'];
40 if ( ! $options ) {
41 $options = array_map(
42 function( $opt ) {
43 return $opt['default'];
44 },
45 AHSC_OPTIONS_LIST_DEFAULT
46 );
47 }
48 \update_site_option( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'] , $options );
49 \update_site_option( 'aruba_hispeed_cache_version', AHSC_CONSTANT['ARUBA_HISPEED_CACHE_VERSION']);
50
51 AHSC_remove_htaccess();
52 if(array_key_exists('ahsc_static_cache',AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS'])){
53 if(isset(AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_static_cache'])){
54 if(AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_static_cache']){
55 AHSC_edit_htaccess();
56 }
57 }
58 }
59 }
60 /**
61 * operation at plugin deactivation
62 * @return void
63 */
64 function AHSC_deactivation( ) {
65
66 \delete_site_option( 'aruba_hispeed_cache_options' );
67 \delete_site_option( 'aruba_hispeed_cache_version');
68 AHSC_remove_htaccess();
69 $file = WP_CONTENT_DIR . '/object-cache.php';
70 if ( file_exists( $file ) ) {
71 \wp_delete_file( $file );
72 }
73 }
74 /**
75 * operation at plugin check requirement
76 * @return void
77 */
78 function AHSC_deactivate_me() {
79 if ( \function_exists( 'deactivate_plugins' ) ) {
80 \deactivate_plugins( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_BASENAME']);
81 }
82 }
83 /**
84 * create Notice in plugin admin page
85 *
86 * @param $handle string notice html id
87 * @param $html_class string notice general class es error,warning etc.etc.
88 * @param $content string notice content
89 *
90 */
91 function AHSC_Notice_Render( $handle, $html_class, $content, $return=false) {
92 $HTML_CLASS = array(
93 'error' => 'notice notice-error',
94 'warning' => 'notice notice-warning',
95 'success' => 'notice notice-success',
96 'info ' => 'notice notice-info',
97 );
98
99 if(!$return){
100 printf(
101 '<div id="%1$s" class="%2$s"><p>%3$s</p></div>',
102 esc_attr( $handle ),
103 esc_attr( $HTML_CLASS[$html_class] ),
104 wp_kses_post( $content )
105 );
106 }else{
107 return sprintf(
108 '<div id="%1$s" class="%2$s"><p>%3$s</p></div>',
109 esc_attr( $handle ),
110 esc_attr( $HTML_CLASS[$html_class] ),
111 wp_kses_post( $content )
112 );
113 }
114 }
115
116 /**
117 * Outputs an admin notice.
118 *
119 * The core equivalent, wp_admin_notice(), only exists from WordPress 6.4.0 while the
120 * plugin declares "Requires at least: 6.2", so the markup is built here instead. It
121 * reproduces byte for byte what wp_kses_post( wp_get_admin_notice() ) returns, which is
122 * covered by a regression test comparing the two outputs.
123 *
124 * The delegation to core that used to sit at the top of this function was removed on
125 * purpose. It made the notice fatal-free on 6.2/6.3, but Plugin Check's
126 * WP_Functions_Compatibility_Check is a token scan: it flagged the literal
127 * wp_admin_notice() call regardless of the function_exists() guard around it, and being a
128 * native check rather than a PHPCS sniff it cannot be silenced with an annotation.
129 * Building the markup unconditionally is the only way to keep 6.2 support and a clean
130 * report without resorting to a dynamic call that hides the reference from the scanner.
131 *
132 * Trade-off: on WordPress 6.4 and later this notice no longer passes through the
133 * wp_admin_notice action nor the wp_admin_notice_args / wp_admin_notice_markup filters.
134 *
135 * @param string $message The message for the admin notice. May contain HTML.
136 * @param array $args Supported keys: 'type', 'dismissible', 'id',
137 * 'additional_classes', 'paragraph_wrap'.
138 *
139 * @return void
140 */
141 function ahsc_admin_notice( $message, $args = array() ) {
142 $args = wp_parse_args(
143 $args,
144 array(
145 'type' => '',
146 'dismissible' => false,
147 'id' => '',
148 'additional_classes' => array(),
149 'paragraph_wrap' => true,
150 )
151 );
152
153 $classes = 'notice';
154
155 if ( is_string( $args['type'] ) && '' !== trim( $args['type'] ) ) {
156 $classes .= ' notice-' . trim( $args['type'] );
157 }
158
159 if ( true === $args['dismissible'] ) {
160 $classes .= ' is-dismissible';
161 }
162
163 if ( is_array( $args['additional_classes'] ) && ! empty( $args['additional_classes'] ) ) {
164 $classes .= ' ' . implode( ' ', $args['additional_classes'] );
165 }
166
167 if ( false !== $args['paragraph_wrap'] ) {
168 $message = '<p>' . $message . '</p>';
169 }
170
171 $id = is_string( $args['id'] ) ? trim( $args['id'] ) : '';
172
173 if ( '' !== $id ) {
174 printf(
175 '<div id="%1$s" class="%2$s">%3$s</div>',
176 esc_attr( $id ),
177 esc_attr( $classes ),
178 wp_kses_post( $message )
179 );
180 } else {
181 printf(
182 '<div class="%1$s">%2$s</div>',
183 esc_attr( $classes ),
184 wp_kses_post( $message )
185 );
186 }
187 }
188
189 /**
190 * create link in plugin page
191 * @param array $actions The plugin action links.
192 * @return array
193 */
194 function AHSC_plugin_action_links($actions){
195
196 $settings_link = \sprintf(
197 '<a href="%s">%s</a>',
198 (( ! is_multisite() ) ? admin_url( 'options-general.php?page=aruba-hispeed-cache') : network_admin_url('settings.php?page=aruba-hispeed-cache')) ,
199 \esc_html(__( 'Settings', 'aruba-hispeed-cache' ))
200 );
201
202 $support_link = \sprintf(
203 '<a href="%s" target="_blank">%s</a>',
204 AHSC_LOCALIZE_LINK['link_assistance'][strtolower(substr( get_bloginfo ( 'language' ), 0, 2 ))],
205 \esc_html(__( 'Customer support', 'aruba-hispeed-cache' ))
206 );
207
208 \array_unshift( $actions, $settings_link, $support_link );
209
210 return $actions;
211
212 }
213
214 if ( ! \function_exists( 'ahsc_get_site_home_url' ) ) {
215 /**
216 * Return the complete home url of site.
217 *
218 * @return string
219 */
220 function ahsc_get_site_home_url() {
221 $home_uri = \trailingslashit( \home_url() );
222
223 if ( \function_exists( 'icl_get_home_url' ) ) {
224 $home_uri = \trailingslashit( \icl_get_home_url() );
225 }
226
227 return $home_uri;
228 }
229 }
230 /*
231
232 if ( ! \function_exists( 'ahsc_save_options' ) ) {
233 **
234 * Save plugin options
235 *
236 * @return void
237 *
238 function ahsc_save_options( ) {
239 if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === $_SERVER['REQUEST_METHOD'] ) {
240 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' ) ) {
241 $new_options = array();
242 //var_dump(ABSPATH . 'wp-config.php');
243 $wpc_transformer = new HASC_WPCT( ABSPATH . 'wp-config.php' );
244 foreach ( array_keys( AHSC_OPTIONS_LIST ) as $opt_key ) {
245 if($opt_key==="ahsc_cron_status" ){
246
247 if(isset($_POST[ $opt_key ])){
248 //var_dump("non disabilito cron ");
249 $wpc_transformer->update( 'constant', 'DISABLE_WP_CRON', 'false', array( 'raw' => true, 'normalize' => true ));
250 $new_options[ $opt_key ]= 'false';
251 }else{
252 //var_dump("disabilito cron ");
253 $wpc_transformer->update( 'constant', 'DISABLE_WP_CRON', 'true', array( 'raw' => true, 'normalize' => true ));
254 $new_options[ $opt_key ]= 'true';
255 }
256
257 }elseif($opt_key==="ahsc_cron_time"){
258
259 if(isset($_POST[ $opt_key ])){
260 //var_dump("setto time ");
261 $wpc_transformer->update( 'constant', 'WP_CRON_LOCK_TIMEOUT', "'".absint($_POST[ $opt_key ])."'", array( 'raw' => true, 'normalize' => true ));
262 $new_options[ $opt_key ]= sanitize_text_field( wp_unslash($_POST[ $opt_key ]));
263 }else{
264 //var_dump("non setto time ");
265 $wpc_transformer->remove('constant', 'WP_CRON_LOCK_TIMEOUT');
266 }
267 }elseif($opt_key!=="ahsc_dns_preconnect_domains"){
268 $new_options[ $opt_key ] = ( isset( $_POST[ $opt_key ] ) ) ? true : false;
269 }else{
270 if(isset( $_POST[ $opt_key ] ) ){
271 $trans_domain_list = explode( "\n", trim( sanitize_text_field( wp_unslash($_POST[ $opt_key ])) ) );
272 foreach ( $trans_domain_list as $index => $string ) {
273 if ( strpos( $string, $_SERVER['SERVER_NAME'] ) !== false ) {
274 unset( $trans_domain_list[ $index ] );
275 }
276 }
277 $new_options[ $opt_key ] =$trans_domain_list;
278 }else{
279 $new_options[ $opt_key ] ="";
280 }
281 }
282 }
283
284 if ( \update_site_option( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'], $new_options ) ) {
285 $content = \esc_html( __('Settings saved.', 'aruba-hispeed-cache') );
286 AHSC_Notice_Render('ahs_settings_saved', 'success',$content);
287 }
288 }
289 }
290 }
291 }
292
293 */
294 if ( ! \function_exists( 'ahsc_reset_options' ) ) {
295 /**
296 * Reset plugin options
297 *
298 * @return string The confirmation message.
299 */
300 function ahsc_reset_options( ) {
301 $new_options = array();
302
303 foreach ( array_keys( AHSC_OPTIONS_LIST_DEFAULT ) as $opt_key ) {
304 $new_options[ $opt_key ] = AHSC_OPTIONS_LIST_DEFAULT[$opt_key]['default'];
305 }
306 $wpc_transformer = new HASC_WPCT( ABSPATH . 'wp-config.php' );
307
308 $wpc_transformer->remove('constant', 'DISABLE_WP_CRON');
309 $wpc_transformer->remove('constant', 'WP_CRON_LOCK_TIMEOUT');
310
311 if ( isset( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_apc'] ) &&
312 AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS']['ahsc_apc'] ){
313 \wp_delete_file( WP_CONTENT_DIR . '/object-cache.php' );
314 }
315
316 \update_site_option( AHSC_CONSTANT['ARUBA_HISPEED_CACHE_OPTIONS_NAME'], $new_options );
317
318 $content = \esc_html( __('Original settings restored.', 'aruba-hispeed-cache') );
319 return $content;
320
321 }
322 }
323
324
325 if ( ! \function_exists( 'ahsc_has_transient' ) ) {
326
327 /**
328 * It checks whether a transinet exists if yes, it returns the value otherwise it returns false.
329 *
330 * @param string $transient .
331 * @return mixed
332 */
333 function ahsc_has_transient( $transient ) {
334 $temp=$GLOBALS['_wp_using_ext_object_cache'];
335 $GLOBALS['_wp_using_ext_object_cache'] = false;
336 $transient_value = ( \is_multisite() ) ? \get_site_transient( (string) $transient ) : \get_transient( (string) $transient );
337 $_value=( false !== $transient_value ) ? $transient_value : false;
338 $GLOBALS['_wp_using_ext_object_cache'] = $temp;
339 return $_value;
340 }
341 }
342
343 if ( ! \function_exists( 'ahsc_set_transient' ) ) {
344
345 /**
346 * Undocumented function
347 *
348 * @param string $transient .
349 * @param mixed $value .
350 * @param integer $expiration .
351 * @return bool
352 */
353 function ahsc_set_transient( $transient, $value, $expiration = 0 ) {
354 $temp=$GLOBALS['_wp_using_ext_object_cache'];
355 $GLOBALS['_wp_using_ext_object_cache'] = false;
356 $_value=( \is_multisite() ) ?
357 \set_site_transient( $transient, $value, $expiration ) :
358 \set_transient( $transient, $value, $expiration );
359 $GLOBALS['_wp_using_ext_object_cache'] = $temp;
360 return $_value;
361 }
362 }
363
364 if ( ! \function_exists( 'ahsc_delete_transient' ) ) {
365
366 /**
367 * Undocumented function
368 *
369 * @param string $transient .
370 * @return bool
371 */
372 function ahsc_delete_transient( $transient ) {
373 $temp=$GLOBALS['_wp_using_ext_object_cache'];
374 $GLOBALS['_wp_using_ext_object_cache'] = false;
375 if(class_exists('ArubaSPA\HiSpeedCache\Debug\Logger')) {
376 AHSC_log( 'hook::transient::delete', __NAMESPACE__ . '::' . __FUNCTION__, 'debug' );
377 // Logger.
378 }
379 $_value=( \is_multisite() ) ?
380 \delete_site_transient( $transient ) :
381 \delete_transient( $transient );
382 $GLOBALS['_wp_using_ext_object_cache'] = $temp;
383 return $_value;
384 }
385 }
386
387 if ( ! \function_exists( 'ahsc_has_notice' ) ) {
388
389 /**
390 * Return bool if transient notice check is set.
391 *
392 * @param bool $remove Set to true to clean the transinte if present.
393 * @return mixed
394 *
395 * @SuppressWarnings(PHPMD.StaticAccess)
396 */
397 function ahsc_has_notice( $remove = null ) {
398 $has_notice = ahsc_has_transient( AHSC_CHECKER['transient_name'] );
399
400 if ( false !== $has_notice && true === $remove ) {
401 if ( \is_multisite() ) {
402 \delete_site_transient(AHSC_CHECKER['transient_name'] );
403 return false;
404 }
405
406 \delete_transient( AHSC_CHECKER['transient_name']);
407 return false;
408 }
409
410 return $has_notice;
411 }
412 }
413
414 if ( ! \function_exists( 'ahsc_get_debug_file_content' ) ) {
415 /**
416 * Return the contente of log file.
417 *
418 * @return string
419 */
420 function ahsc_get_debug_file_content() {
421 global $wp_filesystem,$logger;
422 \WP_Filesystem();
423 if (class_exists('ArubaSPA\HiSpeedCache\Debug\Logger') ) {
424 if ( \file_exists( Logger::get_log_file_path_name() ) ) {
425 return $wp_filesystem->get_contents( Logger::get_log_file_path_name() );
426 }
427 }
428 return false;
429 }
430 }
431
432 if ( ! \function_exists('ahsc_current_theme_is_fse_theme' ) ) {
433 /**
434 * The function checks if the current theme is a Full Site Editing (FSE) theme in PHP.
435 *
436 * @return bool value indicating whether the current theme is a Full Site Editing (FSE) theme.
437 */
438 function ahsc_current_theme_is_fse_theme() {
439 if ( function_exists( 'wp_is_block_theme' ) ) {
440 return (bool) wp_is_block_theme();
441 }
442 if ( function_exists( 'gutenberg_is_fse_theme' ) ) {
443 return (bool) gutenberg_is_fse_theme();
444 }
445 return false;
446 }
447 }
448
449 /**
450 * Write a debug info in to file.
451 *
452 * @param string $message the messagge.
453 * @param string $name the name of message.
454 * @param string $type the type of log debug|info|warning|error.
455 * @return void
456 */
457 function AHSC_log( $message, $name = '', $type = 'info' ) {
458
459 if ( class_exists('\ArubaSPA\HiSpeedCache\Debug\Logger') ) {
460
461 //die(var_export(Logger::$logger_ready,true));
462 switch ( $type ) {
463 case 'debug':
464 Logger::debug( $message, $name );
465 break;
466 case 'info':
467 Logger::info( $message, $name );
468 break;
469 case 'warning':
470 Logger::warning( $message, $name );
471 break;
472 case 'error':
473 Logger::error( $message, $name );
474 break;
475 }
476 }
477 }
478
479 /** 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!
480 */
481
482 add_filter('site_status_tests', function (array $test_type) {
483
484 unset($test_type['async']['background_updates']); // remove warning about Automatic background updates
485
486 return $test_type;
487 }, 10, 1);
488
489 if ( ! \function_exists('ahsc_check_debug_status' ) ) {
490
491 function ahsc_check_debug_status(){
492 $ahsc_debug_status=false;
493 $wpc_transformer = new HASC_WPCT( ABSPATH . 'wp-config.php', true );
494 $ahsc_db = false;
495 $ahsc_dbl = false;
496 if ($wpc_transformer->exists( 'constant', 'WP_DEBUG' )) {
497 $ahsc_db = filter_var($wpc_transformer->get_value('constant','WP_DEBUG'), FILTER_VALIDATE_BOOLEAN);
498 }
499 if ($wpc_transformer->exists( 'constant', 'WP_DEBUG_LOG' )) {
500 $ahsc_dbl = filter_var($wpc_transformer->get_value('constant','WP_DEBUG_LOG'), FILTER_VALIDATE_BOOLEAN);
501 }
502 if($ahsc_db || $ahsc_dbl ){
503 $ahsc_debug_status=true;
504
505 }
506 return $ahsc_debug_status;
507 }
508
509 }
510