trait-config-updater.php
1.31 KB
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
<?php
namespace WP_Rocket\Traits;
trait Config_Updater {
/**
* Update htaccess and WP Rocket config file if the option was modified.
*
* @since 3.1
* @author Remy Perona
*
* @param string $old_value Option's previous value.
* @param string $value Option's new value.
* @return void
*/
public function after_update_single_option( $old_value, $value ) {
if ( $old_value !== $value ) {
$this->flush_htaccess();
$this->generate_config_file();
}
}
/**
* Sets the htaccess update request
*
* @since 3.1
* @author Remy Perona
*
* @return void
*/
protected function flush_htaccess() {
wp_cache_set( 'rocket_flush_htaccess', 1 );
}
/**
* Sets WP Rocket config file update request
*
* @since 3.1
* @author Remy Perona
*
* @return void
*/
protected function generate_config_file() {
wp_cache_set( 'rocket_generate_config_file', 1 );
}
/**
* Performs the files update if requested
*
* @since 3.1
* @author Remy Perona
*
* @return void
*/
public function maybe_update_config() {
if ( wp_cache_get( 'rocket_flush_htaccess' ) ) {
flush_rocket_htaccess();
wp_cache_delete( 'rocket_flush_htaccess' );
}
if ( wp_cache_get( 'rocket_generate_config_file' ) ) {
\rocket_generate_config_file();
wp_cache_delete( 'rocket_generate_config_file' );
}
}
}