: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace Smush\Core\Webp;
* Code to use on Nginx servers.
* @param bool $marker whether to wrap code with marker comment lines.
public function get_rewrite_rules( $marker = true ) {
$webp_dir = new Webp_Dir();
$upload_relpath = $webp_dir->get_upload_rel_path();
$webp_path = trailingslashit( $webp_dir->get_webp_path() );
$webp_rel_path = trailingslashit( $webp_dir->get_webp_rel_path() );
$base = trailingslashit( dirname( $upload_relpath ) );
$directory = trailingslashit( basename( $upload_relpath ) );
$regex_base = ltrim( $base, '/\\' ) . '(' . $directory . ')';
$regex_base = str_replace( '/', '\/', $regex_base );
* We often need to remove WebP file extension from Nginx cache rule in order to make Smush WebP work,
* so always add expiry header rule for Nginx.
* @see https://incsub.atlassian.net/browse/SMUSH-1072
location ~* "{$regex_base}(.*\.(?:png|jpe?g))" {
if (-f "{$webp_path}disable_smush_webp") {
if (\$http_accept !~* "webp") {
try_files {$webp_rel_path}\$image_path.webp \$uri =404;
if ( true === $marker ) {
$code = "# BEGIN SMUSH-WEBP\n" . $code;
$code .= "\n# END SMUSH-WEBP";
return apply_filters( 'smush_nginx_webp_rules', $code );