1 | <?php |
---|
2 | namespace LiteSpeed; |
---|
3 | defined( 'WPINC' ) || exit; |
---|
4 | |
---|
5 | $presets = array(); |
---|
6 | |
---|
7 | $presets['essentials'] = array( |
---|
8 | 'title' => __( 'Essentials', 'litespeed-cache' ), |
---|
9 | 'body' => array( |
---|
10 | __( 'Default Cache', 'litespeed-cache' ), |
---|
11 | __( 'Higher TTL', 'litespeed-cache' ), |
---|
12 | __( 'Browser Cache', 'litespeed-cache' ) |
---|
13 | ), |
---|
14 | 'footer' => array( |
---|
15 | __( 'This no-risk preset is appropriate for all websites. Good for new users, simple websites, or cache-oriented development.', 'litespeed-cache' ), |
---|
16 | __( 'A Domain Key is not required to use this preset. Only basic caching features are enabled.', 'litespeed-cache' ) |
---|
17 | ) |
---|
18 | ); |
---|
19 | |
---|
20 | $presets['basic'] = array( |
---|
21 | 'title' => __( 'Basic', 'litespeed-cache' ), |
---|
22 | 'body' => array( |
---|
23 | __( 'Everything in Essentials, Plus', 'litespeed-cache' ), |
---|
24 | __( 'Image Optimization', 'litespeed-cache' ), |
---|
25 | __( 'Mobile Cache', 'litespeed-cache' ) |
---|
26 | ), |
---|
27 | 'footer' => array( |
---|
28 | __( 'This low-risk preset introduces basic optimizations for speed and user experience. Appropriate for enthusiastic beginners.', 'litespeed-cache' ), |
---|
29 | __( 'A Domain Key is required to use this preset. Includes optimizations known to improve site score in page speed measurement tools.', 'litespeed-cache' ) |
---|
30 | ) |
---|
31 | ); |
---|
32 | |
---|
33 | $presets['advanced'] = array( |
---|
34 | 'title' => __( 'Advanced (Recommended)', 'litespeed-cache' ), |
---|
35 | 'body' => array( |
---|
36 | __( 'Everything in Basic, Plus', 'litespeed-cache' ), |
---|
37 | __( 'Guest Mode and Guest Optimization', 'litespeed-cache' ), |
---|
38 | __( 'CSS, JS and HTML Minification', 'litespeed-cache' ), |
---|
39 | __( 'Font Display Optimization', 'litespeed-cache' ), |
---|
40 | __( 'JS Defer for both external and inline JS', 'litespeed-cache' ), |
---|
41 | __( 'DNS Prefetch for static files', 'litespeed-cache' ), |
---|
42 | __( 'Gravatar Cache', 'litespeed-cache' ), |
---|
43 | __( 'Remove Query Strings from Static Files', 'litespeed-cache' ), |
---|
44 | __( 'Remove WordPress Emoji', 'litespeed-cache' ), |
---|
45 | __( 'Remove Noscript Tags', 'litespeed-cache' ) |
---|
46 | ), |
---|
47 | 'footer' => array( |
---|
48 | __( 'This preset is good for most websites, and is unlikely to cause conflicts. Any CSS or JS conflicts may be resolved with Page Optimization > Tuning tools.', 'litespeed-cache' ), |
---|
49 | __( 'A Domain Key is required to use this preset. Includes many optimizations known to improve page speed scores.', 'litespeed-cache' ) |
---|
50 | ) |
---|
51 | ); |
---|
52 | |
---|
53 | $presets['aggressive'] = array( |
---|
54 | 'title' => __( 'Aggressive', 'litespeed-cache' ), |
---|
55 | 'body' => array( |
---|
56 | __( 'Everything in Advanced, Plus', 'litespeed-cache' ), |
---|
57 | __( 'CSS & JS Combine', 'litespeed-cache' ), |
---|
58 | __( 'Asynchronous CSS Loading with Critical CSS', 'litespeed-cache' ), |
---|
59 | __( 'Removed Unused CSS for Users', 'litespeed-cache' ), |
---|
60 | __( 'Lazy Load for Iframes', 'litespeed-cache' ) |
---|
61 | ), |
---|
62 | 'footer' => array( |
---|
63 | __( 'This preset might work out of the box for some websites, but be sure to test! Some CSS or JS exclusions may be necessary in Page Optimization > Tuning.', 'litespeed-cache' ), |
---|
64 | __( 'A Domain Key is required to use this preset. Includes many optimizations known to improve page speed scores.', 'litespeed-cache' ) |
---|
65 | ) |
---|
66 | ); |
---|
67 | |
---|
68 | $presets['extreme'] = array( |
---|
69 | 'title' => __( 'Extreme', 'litespeed-cache' ), |
---|
70 | 'body' => array( |
---|
71 | __( 'Everything in Aggressive, Plus', 'litespeed-cache' ), |
---|
72 | __( 'Lazy Load for Images', 'litespeed-cache' ), |
---|
73 | __( 'Viewport Image Generation', 'litespeed-cache' ), |
---|
74 | __( 'JS Delayed', 'litespeed-cache' ), |
---|
75 | __( 'Inline JS added to Combine', 'litespeed-cache' ), |
---|
76 | __( 'Inline CSS added to Combine', 'litespeed-cache' ) |
---|
77 | ), |
---|
78 | 'footer' => array( |
---|
79 | __( 'This preset almost certainly will require testing and exclusions for some CSS, JS and Lazy Loaded images. Pay special attention to logos, or HTML-based slider images.', 'litespeed-cache' ), |
---|
80 | __( 'A Domain Key is required to use this preset. Enables the maximum level of optimizations for improved page speed scores.', 'litespeed-cache' ) |
---|
81 | ) |
---|
82 | ); |
---|
83 | |
---|
84 | ?> |
---|
85 | |
---|
86 | <h3 class="litespeed-title-short"> |
---|
87 | <?php esc_html_e( 'LiteSpeed Cache Standard Presets', 'litespeed-cache' ); ?> |
---|
88 | <?php Doc::learn_more( 'https://docs.litespeedtech.com/lscache/lscwp/presets/#standard-tab' ); ?> |
---|
89 | </h3> |
---|
90 | |
---|
91 | <p><?php esc_html_e( 'Use an official LiteSpeed-designed Preset to configure your site in one click. Try no-risk caching essentials, extreme optimization, or something in between.', 'litespeed-cache' ); ?></p> |
---|
92 | |
---|
93 | <div class="litespeed-comparison-cards"> |
---|
94 | <?php |
---|
95 | foreach ( array_keys( $presets ) as $name ) : |
---|
96 | $title = $presets[ $name ]['title']; |
---|
97 | $recommend = 'advanced' === $name; |
---|
98 | $card_class = $recommend ? 'litespeed-comparison-card-rec' : ''; |
---|
99 | $button_class = $recommend ? 'button-primary' : 'button-secondary'; |
---|
100 | ?> |
---|
101 | <div class="litespeed-comparison-card postbox <?php echo $card_class; ?>"> |
---|
102 | <div class="litespeed-card-content"> |
---|
103 | <div class="litespeed-card-header"> |
---|
104 | <h3 class="litespeed-h3"> |
---|
105 | <?php echo esc_html( $title ); ?> |
---|
106 | </h3> |
---|
107 | </div> |
---|
108 | <div class="litespeed-card-body"> |
---|
109 | <ul> |
---|
110 | <?php foreach ( $presets[ $name ]['body'] as $line ) : ?> |
---|
111 | <li><?php echo esc_html( $line ); ?></li> |
---|
112 | <?php endforeach; ?> |
---|
113 | </ul> |
---|
114 | </div> |
---|
115 | <div class="litespeed-card-footer"> |
---|
116 | <h4><?php esc_html_e( 'Who should use this preset?', 'litespeed-cache' ); ?></h4> |
---|
117 | <?php foreach ( $presets[ $name ]['footer'] as $line ) : ?> |
---|
118 | <p><?php echo esc_html( $line ); ?></p> |
---|
119 | <?php endforeach; ?> |
---|
120 | </div> |
---|
121 | </div> |
---|
122 | <div class="litespeed-card-action"> |
---|
123 | <a |
---|
124 | href="<?php echo Utility::build_url( Router::ACTION_PRESET, Preset::TYPE_APPLY, false, null, array( 'preset' => $name ) ); ?>" |
---|
125 | class="button <?php echo $button_class; ?>" |
---|
126 | data-litespeed-cfm="<?php printf( esc_html__( 'This will back up your current settings and replace them with the %1$s preset settings. Do you want to continue?', 'litespeed-cache' ), $title ); ?>" |
---|
127 | > |
---|
128 | <?php esc_html_e( 'Apply Preset', 'litespeed-cache' ); ?> |
---|
129 | </a> |
---|
130 | </div> |
---|
131 | </div> |
---|
132 | <?php endforeach; ?> |
---|
133 | </div> |
---|
134 | |
---|
135 | <?php |
---|
136 | $summary = Preset::get_summary(); |
---|
137 | $backups = array(); |
---|
138 | foreach ( Preset::get_backups() as $backup ) { |
---|
139 | $backup = explode( '-', $backup ); |
---|
140 | if ( empty( $backup[1] ) ) { |
---|
141 | continue; |
---|
142 | } |
---|
143 | $timestamp = $backup[1]; |
---|
144 | $time = trim( Utility::readable_time( $timestamp ) ); |
---|
145 | $name = empty( $backup[3] ) ? null : $backup[3]; |
---|
146 | $title = empty( $presets[ $name ]['title'] ) ? $name : $presets[ $name ]['title']; |
---|
147 | $title = null === $title ? __( 'unknown', 'litespeed-cache' ) : $title; |
---|
148 | $backups[] = array( |
---|
149 | 'timestamp' => $timestamp, |
---|
150 | 'time' => $time, |
---|
151 | 'title' => $title |
---|
152 | ); |
---|
153 | } |
---|
154 | |
---|
155 | if ( ! empty( $summary['preset'] ) || ! empty( $backups ) ) : |
---|
156 | ?> |
---|
157 | <h3 class="litespeed-title-short"> |
---|
158 | <?php esc_html_e( 'History', 'litespeed-cache' ); ?> |
---|
159 | </h3> |
---|
160 | <?php endif; ?> |
---|
161 | |
---|
162 | <?php if ( ! empty( $summary['preset'] ) ) : ?> |
---|
163 | <p> |
---|
164 | <?php |
---|
165 | $name = strtolower( $summary['preset'] ); |
---|
166 | $time = trim( Utility::readable_time( $summary['preset_timestamp'] ) ); |
---|
167 | if ( 'error' === $name ) { |
---|
168 | printf( esc_html__( 'Error: Failed to apply the settings %1$s', 'litespeed-cache' ), $time ); |
---|
169 | } elseif ( 'backup' === $name ) { |
---|
170 | printf( esc_html__( 'Restored backup settings %1$s', 'litespeed-cache' ), $time ); |
---|
171 | } else { |
---|
172 | printf( |
---|
173 | esc_html__( 'Applied the %1$s preset %2$s', 'litespeed-cache' ), |
---|
174 | '<strong>' . esc_html( $presets[ $name ]['title'] ) . '</strong>', |
---|
175 | $time |
---|
176 | ); |
---|
177 | } |
---|
178 | ?> |
---|
179 | </p> |
---|
180 | <?php endif; ?> |
---|
181 | |
---|
182 | <?php foreach ( $backups as $backup ) : ?> |
---|
183 | <p> |
---|
184 | <?php printf( esc_html__( 'Backup created %1$s before applying the %2$s preset', 'litespeed-cache' ), $backup['time'], $backup['title'] ); ?> |
---|
185 | <a |
---|
186 | href="<?php echo Utility::build_url( Router::ACTION_PRESET, Preset::TYPE_RESTORE, false, null, array( 'timestamp' => $backup['timestamp'] ) ); ?>" |
---|
187 | class="litespeed-left10" |
---|
188 | data-litespeed-cfm="<?php printf( esc_html__( 'This will restore the backup settings created %1$s before applying the %2$s preset. Any changes made since then will be lost. Do you want to continue?', 'litespeed-cache' ), $backup['time'], $backup['title'] ); ?>" |
---|
189 | > |
---|
190 | <?php esc_html_e( 'Restore Settings', 'litespeed-cache' ); ?> |
---|
191 | </a> |
---|
192 | </p> |
---|
193 | <?php |
---|
194 | endforeach; |
---|