PluginProbe
JCH Optimize / trunk
JCH Optimize vtrunk
6.0.2 6.0.1 trunk 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.10.0 2.2.0 2.2.1 All 58 releases
jch-optimize / src / Admin / Settings / SectionCallbacks.php

SectionCallbacks.php in JCH Optimize trunk, at src/Admin/Settings/SectionCallbacks.php

417 lines 18.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * JCH Optimize - Performs several front-end optimizations for fast downloads
5 *
6 * @package jchoptimize/wordpress-platform
7 * @author Samuel Marshall <samuel@jch-optimize.net>
8 * @copyright Copyright (c) 2020 Samuel Marshall / JCH Optimize
9 * @license GNU/GPLv3, or later. See LICENSE file
10 *
11 * If LICENSE file missing, see <http://www.gnu.org/licenses/>.
12 */
13
14 namespace JchOptimize\WordPress\Admin\Settings;
15
16 use function __;
17
18 class SectionCallbacks
19 {
20 public static function miscellaneousSection(): void
21 {
22 echo SettingsPageLayout::addTab('general-tab', true);
23
24 $title = __('General', 'jch-optimize');
25
26 echo SettingsPageLayout::addSection($title);
27 }
28
29 public static function excludeMenuItemsSection(): void
30 {
31 $title = __('Exclude Menu Urls', 'jch-optimize');
32 $description = __(
33 'Enter any part of a url to exclude that page from optimization. You will need to add these urls to the list manually by typing the url in the textbox and click the \'Add item\' button.',
34 'jch-optimize'
35 );
36
37 echo SettingsPageLayout::addSection($title, $description);
38 }
39
40 public static function elementsAboveFoldSection(): void
41 {
42 $title = __('Elements Above Fold', 'jch-optimize');
43 $description = __('This is used by the Optimize CSS Delivery, Lazy Load, and Reduce DOM features. Enter the value that represents the amount of HTML elements above the fold so these features can find the critical CSS for the section above the fold, and lazy load images and HTML sections below the fold respectively.', 'jch-optimize');
44
45 echo SettingsPageLayout::addSection($title, $description);
46 }
47
48 public static function cacheStorageSection(): void
49 {
50 $title = __('Cache Storage', 'jch-optimize');
51 $description = __(
52 'Select and configure the storage adapters you want to use with JCH Optimize. The available adapters are Filesystem, APCu, Memcached, Redis, and WinCache. The default is filesystem and will be used if there is a failure to load any other adapter or if you\'re using the free version.'
53 );
54
55 echo SettingsPageLayout::addSection($title, $description);
56 }
57
58 public static function recacheSettingsSection(): void
59 {
60 $title = __('Recache Settings', 'jch-optimize');
61 $description = __('You can configure your options for the Recache feature here.', 'jch-optimize');
62
63 echo SettingsPageLayout::addSection($title, $description);
64 }
65
66 public static function combineCssJsSection(): void
67 {
68 echo SettingsPageLayout::addTab('combine-files-tab');
69
70 $title = __('Optimize CSS/JS', 'jch-optimize');
71 $description = __(
72 'Info These settings are concerned with optimizing CSS and JavaScript files, primarily minifying the contents, but also performing other optimization techniques. By default, files will not be combined together',
73 'jch-optimize'
74 );
75
76 echo SettingsPageLayout::addSection($title, $description);
77 }
78
79 public static function combineCssJsAutoSection(): void
80 {
81 $title = __('Optimize Files Automatic Settings', 'jch-optimize');
82 $description = __(
83 'These settings are configured by the automatic settings. You don\'t need to configure them yourself.',
84 'jch-optimize'
85 );
86
87 echo SettingsPageLayout::addSection($title, $description);
88 }
89
90 public static function cssAutoSettingsSection(): void
91 {
92 echo SettingsPageLayout::addTab('css-tab');
93
94 $title = __('CSS Automatic Settings', 'jch-optimize');
95 $description = __(
96 'These settings are configured by the Automatic settings on the Control Panel tab. You don\'t need to configure them yourself.',
97 'jch-optimize'
98 );
99
100 echo SettingsPageLayout::addSection($title, $description);
101 }
102
103 public static function excludeCssSection(): void
104 {
105 $title = __('Exclude CSS Files', 'jch-optimize');
106 $description = __(
107 'Exclude individual CSS files or files from select plugins. To add an item to the drop-down list manually, type any part of the url in the textbox then click the \'Add item\' button. CSS files are always excluded while preserving execution order. If the files are combined, the combined file will split itself around excluded files to preserve the original order of files on the page. '
108 );
109
110 echo SettingsPageLayout::addSection($title, $description);
111 }
112
113 public static function removeCssSection(): void
114 {
115 $title = __('Remove CSS Files', 'jch-optimize');
116 $description = __(
117 'You can remove and prevent CSS files from loading on the page if they\'re not being used at all to speed up page load and rendering. Please be sure these files are not being used anywhere on the site to prevent breaking your pages.',
118 'jch-optimize'
119 );
120
121 echo SettingsPageLayout::addSection($title, $description);
122 }
123
124 public static function customCssSection(): void
125 {
126 $title = __('Custom CSS', 'jch-optimize');
127 $description = __(
128 'This section is for adding CSS to correct Cumulative Layout Shift (CLS) issues caused by the page shifting around because the space wasn\'t allocated to accomodate the HTML elements rendering, such as some slideshows. The appropriate media queries will be generated for mobile and/or desktop, so you\'ll only need to add simple CSS declarations for e.g., #slideshow-container {min-height: 300px;}',
129 'jch-optimize'
130 );
131
132 echo SettingsPageLayout::addSection($title, $description);
133 }
134
135 public static function optimizeCssDeliverySection(): void
136 {
137 $title = __('Optimize CSS Delivery', 'jch-optimize');
138 $description = __(
139 'The plugin will attempt to extract the critical CSS that is required to format the page above the fold and put this in a &lt;style&gt; element inside the &lt;head&gt; section of the HTML to prevent \'render-blocking\'. The generated CSS will then be loaded asynchronously. Select the number of HTML elements from the top of the page that you want the plugin to find the critical CSS for. The smaller the number, the smaller the size of the critical CSS but you might see some jumping of the page if the number is too small.',
140 'jch-optimize'
141 );
142
143 echo SettingsPageLayout::addSection($title, $description);
144 }
145
146 public static function javascriptAutomaticSettingsSection(): void
147 {
148 echo SettingsPageLayout::addTab('javascript-tab');
149
150 $title = __('JavaScript Automatic Settings', 'jch-optimize');
151 $description = __(
152 'These settings are configured by the Automatic settings on the Control Panel tab. You don\'t need to configure them yourself',
153 'jch-optimize'
154 );
155
156 echo SettingsPageLayout::addSection($title, $description);
157 }
158
159 public static function excludePeoSection(): void
160 {
161 $title = __('Exclude JavaScript files', 'jch-optimize');
162 $description = __(
163 'Exclude individual JavaScript files or files from selected plugins. Files by default will be excluded while preserving execution order on the page by splitting the combined files around excluded files if the Combine Files setting is enabled. This ensures no dependency between files are broken and break the page. To modify this behavior, you can click to select the respective checkboxes, \'Ignore execution order\' and/or \'Don\'t move to the bottom\' for each exclusion.',
164 'jch-optimize'
165 );
166
167 echo SettingsPageLayout::addSection($title, $description);
168 }
169
170 public static function removeJsSection(): void
171 {
172 $title = __('Remove JavaScript Files', 'jch-optimize');
173 $description = __(
174 'You can remove and prevent JavaScript files from loading on the page if they\'re not being used at all. This helps to speed up page download and rendering. Please be sure these files are not being used anywhere on the site to prevent breaking your pages.',
175 'jch-optimize'
176 );
177
178 echo SettingsPageLayout::addSection($title, $description);
179 }
180
181 public static function reduceUnusedJavascriptSection(): void
182 {
183 $title = __('Reduce Unused JavaScript', 'jch-optimize');
184 $description = __(
185 'This setting will defer the loading of JavaScript on the page until after the use interacts with the page to improve page load performance adversely affected by unused JavaScript. If your site uses JavaScript to perform any of the initial render, particularly to sections of page above the fold, you may need to exclude these files using the critical JavaScript settings below.'
186 );
187
188 echo SettingsPageLayout::addSection($title, $description);
189 }
190
191 public static function pageCacheSection(): void
192 {
193 echo SettingsPageLayout::addTab('page-cache-tab');
194
195 $title = __('Page Cache', 'jch-optimize');
196 $description = __(
197 'The HTML source of the page will be cached to significantly speed up page loads. Deactivate caching while configuring the plugin and be sure to flush cache after making changes to the site.',
198 'jch-optimize'
199 );
200
201 echo SettingsPageLayout::addSection($title, $description);
202 }
203
204 public static function cloudflareCachePurgeIntegrationSection(): void
205 {
206 $title = __('Cloudflare Cache Purge Integration', 'jch-optimize');
207
208 $cf_url = 'https://developers.cloudflare.com/fundamentals/api/get-started/create-token/';
209 /* translators: %s: URL to Cloudflare "create token" docs */
210 $raw = __(
211 'Integrate Cloudflare to purge cache when JCH Optimize deletes its cache. This DOES NOT configure Cloudflare; It ONLY purges cache. <a href="%s" target="_blank" rel="noopener noreferrer">Use or create a custom token</a> with Cache Purge access on the zone associated with this site',
212 'jch-optimize'
213 );
214
215 $description = sprintf(
216 wp_kses(
217 $raw,
218 ['a' => ['href' => true, 'target' => true, 'rel' => true]]
219 ),
220 esc_url($cf_url)
221 );
222
223 echo SettingsPageLayout::addSection($title, $description);
224 }
225
226 public static function addImageAttributesSection(): void
227 {
228 echo SettingsPageLayout::addTab('media-tab');
229
230 $title = __('Add Image Attributes', 'jch-optimize');
231 $description = __(
232 'When enabled, the plugin will add missing \'width\' and \'height\' attributes to &lt;img/&gt; elements. PLEASE NOTE: This works best when the images are scaled to the size they are shown onscreen. If images appear the wrong size, try rescaling the images correctly or disabling this option.',
233 'jch-optimize'
234 );
235
236 echo SettingsPageLayout::addSection($title, $description);
237 }
238
239 public static function spriteGeneratorSection(): void
240 {
241 $title = __('Sprite Generator', 'jch-optimize');
242 $description = __(
243 'The plugin will combine selected background images into one image called a sprite to reduce http requests. Combine CSS must be enabled for the Sprite Generator to work.',
244 'jch-optimize'
245 );
246
247 echo SettingsPageLayout::addSection($title, $description);
248 }
249
250 public static function lazyLoadSection(): void
251 {
252 $title = __('Lazy-Load Images');
253 $description = __(
254 'Enable to delay the loading of iframes, images and responsive images until they are scrolled into view. This further speeds up the loading of the page and reduces http requests.',
255 'jch-optimize'
256 );
257
258 echo SettingsPageLayout::addSection($title, $description);
259 }
260
261 public static function http2PushSection(): void
262 {
263 echo SettingsPageLayout::addTab('preloads-tab');
264
265 $title = __('Http/2 Preload', 'jch-optimize');
266 $description = __(
267 'Plugin will send appropriate headers to your server to push resource files before the browser requests them. Please note this only works if http/2 is enabled on the server',
268 'jch-optimize'
269 );
270
271 echo SettingsPageLayout::addSection($title, $description);
272 }
273
274 public static function largestContentfulPaintSection(): void
275 {
276 $title = __('Largest Contentful Paint Images', 'jch-optimize');
277 $description = __(
278 'Use this section to preload any image identified as the LCP element with a high priority using the new \'fetchpriority\' attribute. These are only preloaded if they appear on the page and will be automatically excluded from lazy load.'
279 );
280
281 echo SettingsPageLayout::addSection($title, $description);
282 }
283
284 public static function optimizeFontsSection(): void
285 {
286 $title = __('Optimize Fonts', 'jch-optimize');
287 $description = __(
288 'Will optimize the loading of fonts by placing all @font-face content in a separate combined files and preload them. Preconnects will be added for all external domains. Google Font files will simply be preloaded since they already only contain @font-face content.'
289 );
290
291 echo SettingsPageLayout::addSection($title, $description);
292 }
293
294 public static function preconnectThirdPartySection(): void
295 {
296 $title = __('Preconnect Third-party Origins', 'jch-optimize');
297 $description = __(
298 'Reduce the impact of third-party code by establising early connections with the external origins. The origin is the part of the URL containing the scheme, hostname, and port. The plugin will add preconnects to the top of the page to reduce performance impacts of thrid-party providers. CDNs and third-party origins in CSS files can be automatically detected, but you may need to manually add preconnect for scripts in the main thread.'
299 );
300
301 echo SettingsPageLayout::addSection($title, $description);
302 }
303
304 public static function cdnSection(): void
305 {
306 echo SettingsPageLayout::addTab('cdn-tab');
307
308 $title = __('CDN', 'jch-optimize');
309 $description = __(
310 'Enter your CDN or cookieless domain here. The plugin will load all static files including background images, generated JavaScript and CSS files, and generated sprite from this domain. This requires that this domain is already set up and points to your site root.',
311 'jch-optimize'
312 );
313
314 echo SettingsPageLayout::addSection($title, $description);
315 }
316
317 public static function globalSection(): void
318 {
319 echo SettingsPageLayout::addTab('optimize-image-tab');
320
321 $title = __('General', 'jch-optimize');
322 $description = __(
323 'Use our API to optimize the images on your server. You can either let the plugin find the images on your page to optimize or manually select them in the file tree explorer. Be sure to save your \'Download ID\' in the plugin before trying to optimize images as that will authenticate you to access the API. These settings apply to both methods.',
324 'jch-optimize'
325 );
326
327 echo SettingsPageLayout::addSection($title, $description);
328 }
329
330 public static function nextGenImages(): void
331 {
332 $title = __('Next Generation Images', 'jch-optimize');
333 $description = __('Next generation image options');
334
335 echo SettingsPageLayout::addSection($title, $description);
336 }
337
338 public static function responsiveImages(): void
339 {
340 $title = __('Responsive Images', 'jch-optimize');
341 $description = __('Responsive images options');
342
343 echo SettingsPageLayout::addSection($title, $description);
344 }
345
346 public static function optimizationConfigurations(): void
347 {
348 $title = __('Optimization Configurations', 'jch-optimize');
349 $description = __('The configurations settings used by the API to determine how the images are processed');
350
351 echo SettingsPageLayout::addSection($title, $description);
352 }
353
354 public static function uploadSettings(): void
355 {
356 $title = __('Upload Settings', 'jch-optimize');
357 $description = __(
358 'Images are packaged in batches for upload to speed up the process. These settings determine how these batches are packaged and handled.',
359 'jch-optimize'
360 );
361
362 echo SettingsPageLayout::addSection($title, $description);
363 }
364
365 public static function autoApiSection(): void
366 {
367 $title = __('Optimize Images By URLs');
368 $description = __(
369 'The plugin will scan the pages of your website for you to find the images to optimize. You don\'t need to select them beforehand.',
370 'jch-optimize'
371 );
372
373 echo SettingsPageLayout::addSection($title, $description);
374 }
375
376 public static function manualApiSection(): void
377 {
378 $title = __('Optimize Images By Folders');
379 $description = __(
380 'Use the file tree to select the subfolders and files you want to optimize. Files will be optimized in subfolders recursively. If you want to rescale your images while optimizing, enter the new width and height in the respective columns beside each image on the right hand side.',
381 'jch-optimize'
382 );
383
384 echo SettingsPageLayout::addSection($title, $description);
385 }
386
387 public static function reduceDomSection(): void
388 {
389 echo SettingsPageLayout::addTab('miscellaneous-tab');
390
391 $title = __('Reduce DOM', 'jch-optimize');
392 $description = __(
393 'HTML5 sectioning related elements such as header, footer, section, aside, and nav that fall below the fold will be commented out if the number of DOM elements exceed 600. These sections will be inserted back into the DOM using JavaScript after the page has been loaded. <span class="alert alert-warning" style="padding: 1px 3px;"> Warning: Use with care. Can interfere with sections that use JavaScript to render.</span>',
394 'jch-optimize'
395 );
396
397 echo SettingsPageLayout::addSection($title, $description);
398 }
399
400 public static function modeSwitcherSection(): void
401 {
402 $title = __('Mode Switcher Menu', 'jch-optimize');
403 $description = __(
404 'The Pro version adds a menu item via a mu-plugin that gives easy access to activate/deactivate the plugin from the menu and provides a visual indicator of what mode the plugin is in. This is useful if you are doing any development work on the site and want to temporarily deactivate the plugin so you can see the changes immediately. The cache will be automatically flushed and a different cache key generated when the plugin is toggled between Production/Development mode using the Mode Switcher.'
405 );
406
407 echo SettingsPageLayout::addSection($title, $description);
408 }
409
410 private static function new(): string
411 {
412 return <<<HTML
413 <span class="badge bg-danger">New!</span>
414 HTML;
415 }
416 }
417