Settings.php
2.18 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
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
<?php
namespace WP_Rocket\Engine\Preload\Admin;
use WP_Rocket\Engine\Preload\Controller\PreloadUrl;
use WP_Rocket\Admin\Options_Data;
class Settings {
/**
* Instance of options handler.
*
* @var Options_Data
*/
protected $options;
/**
* PreloadUrl instance
*
* @var PreloadUrl
*/
private $preload_url;
/**
* Instantiate the class
*
* @param Options_Data $options Instance of options handler.
* @param PreloadUrl $preload_url PreloadUrl instance.
*/
public function __construct( Options_Data $options, PreloadUrl $preload_url ) {
$this->options = $options;
$this->preload_url = $preload_url;
}
/**
* Maybe display the preload notice.
*
* @return void
*/
public function maybe_display_preload_notice() {
if ( ! $this->can_display_notice() ) {
return;
}
if ( false === get_transient( 'wpr_preload_running' ) ) {
return;
}
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( in_array( 'preload_notice', (array) $boxes, true ) ) {
return;
}
$message = sprintf(
// translators: %1$s = plugin name.
__( '%1$s: The preload service is now active. After the initial preload it will continue to cache all your pages whenever they are purged. No further action is needed.', 'rocket' ),
'<strong>WP Rocket</strong>'
);
rocket_dismiss_box( 'preload_notice' );
rocket_notice_html(
[
'status' => 'info',
'message' => $message,
'id' => 'rocket-notice-preload-processing',
]
);
}
/**
* Checks if we can display the Preload notices.
*
* @return bool
*/
private function can_display_notice(): bool {
$screen = get_current_screen();
if (
isset( $screen->id )
&&
'settings_page_wprocket' !== $screen->id
) {
return false;
}
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return false;
}
return $this->is_enabled();
}
/**
* Determines if Preload option is enabled.
*
* @return boolean
*/
public function is_enabled() : bool {
return (bool) $this->options->get( 'manual_preload', 0 );
}
/**
* Preload the homepage
*
* @return void
*/
public function preload_homepage() {
$this->preload_url->preload_url( home_url() );
}
}