PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 4.1.2
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v4.1.2
4.1.2 4.1.1 4.1.0 4.0.1 4.0.0 3.3.1 3.3.0 trunk 1.0.0 2.0.0 2.1.0 3.0.0 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8
← All changes | admin/rewrite-rules/class-nginx.php +33 -21 3.3.14.1.2 View file →
@@ -1,9 +1,10 @@
1 1 <?php
2 +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2 3
3 4 include_once QUICKWEBP_PLUGIN_PATH . 'admin/rewrite-rules/class-rewrite-rules-abstract.php';
4 5
5 -class Nginx extends Rewrite_Rules_Abstract {
6 +class Quickwebp_Nginx extends Quickwebp_Rewrite_Rules_Abstract {
6 7
7 8 /**
8 9 * Get the path to the file.
9 10 */
@@ -22,28 +23,39 @@
22 23 *
23 24 * @return string
24 25 */
25 26 protected function get_raw_new_contents() {
26 - $extensions = 'jpg|jpeg|jpe|png';
27 - $home_root = wp_parse_url( home_url( '/' ) );
28 - $home_root = $home_root['path'];
27 + $home_root = wp_parse_url( home_url( '/' ) );
28 + $home_root = $home_root['path'];
29 29
30 - return trim( '
31 -# BEGIN ' . $this->tag_name . '
32 -location ~* ^(' . $home_root . '.+)\.(' . $extensions . ')$ {
33 - add_header Vary Accept;
30 + $content = "# BEGIN " . $this->tag_name . "\n";
31 + $content .= "location ~* ^($home_root.+)\\.(jpg|jpeg|jpe|png)$ {";
32 + $content .= "\n\tadd_header Vary Accept;";
33 +
34 + // Check for AVIF support and file existence
35 + $content .= "\n\n\tif (\$http_accept ~* \"avif\") {";
36 + $content .= "\n\t\tset \$imavif A;";
37 + $content .= "\n\t}";
38 + $content .= "\n\tif (-f \$request_filename.avif) {";
39 + $content .= "\n\t\tset \$imavif \"\${imavif}B\";";
40 + $content .= "\n\t}";
41 + $content .= "\n\tif (\$imavif = AB) {";
42 + $content .= "\n\t\trewrite ^(.*) \$1.avif break;";
43 + $content .= "\n\t}";
44 +
45 + // Check for WebP support and file existence
46 + $content .= "\n\n\tif (\$http_accept ~* \"webp\") {";
47 + $content .= "\n\t\tset \$imwebp A;";
48 + $content .= "\n\t}";
49 + $content .= "\n\tif (-f \$request_filename.webp) {";
50 + $content .= "\n\t\tset \$imwebp \"\${imwebp}B\";";
51 + $content .= "\n\t}";
52 + $content .= "\n\tif (\$imwebp = AB) {";
53 + $content .= "\n\t\trewrite ^(.*) \$1.webp break;";
54 + $content .= "\n\t}";
55 +
56 + $content .= "\n}";
57 + $content .= "\n# END " . $this->tag_name;
34 58
35 - if ($http_accept ~* "webp"){
36 - set $imwebp A;
59 + return trim( $content );
37 60 }
38 - if (-f $request_filename.webp) {
39 - set $imwebp "${imwebp}B";
40 - }
41 - if ($imwebp = AB) {
42 - rewrite ^(.*) $1.webp;
43 - }
44 61 }
45 -# END ' . $this->tag_name . '');
46 - }
47 -
48 -
49 -}