Closed Mai-Saad closed 2 months ago
I don't get what's wrong here,
The expected behavior:
htaccess is rewritten and it's timestamp is updated
Right now when we save the settings it gets rewritten and the file timestamp is updated. Isn't it what we want ?
The htaccess should only be updated if the display next-gen and the method value change
To reproduce the issue, follow these steps:
There are two root causes, First one is located here: https://github.com/wp-media/imagify-plugin/blob/5684433e2a7d126b312de47ed05d21022483374c/classes/Webp/Display.php#L63
The issue is the same for both, we are only checking if this is enabled or not, and the remove()
cause the modification of the htaccess even tho we did not change anything to the settings.
Scope a solution To solve the issue, we must check if it was enabled before or not. To do that, we can add
$was_enabled = (bool) get_imagify_option( 'display_nextgen' );
here: https://github.com/wp-media/imagify-plugin/blob/5684433e2a7d126b312de47ed05d21022483374c/classes/Avif/Display.php#L49 and https://github.com/wp-media/imagify-plugin/blob/5684433e2a7d126b312de47ed05d21022483374c/classes/Webp/Display.php#L55
and change the condition to
if ( $enabled && ! $was_enabled ) {
// Add the WebP file type.
$result = $this->get_server_conf()->add();
} elseif ( ! $enabled && $was_enabled ) {
// Remove the WebP file type.
$result = $this->get_server_conf()->remove();
}
Development steps:
Effort estimation: XS Is a refactor needed in that part of the codebase? No
Shouldn't we add the same condition to imagify-plugin/classes/Avif/Display.php
?
LGTM
Before submitting an issue please check that you’ve completed the following steps:
Describe the bug When we enable/disable avif or unselect thumbnail then save, htaccess is rewritten
To Reproduce Steps to reproduce the behavior:
Expected behavior htaccess isnot rewritten and it's timestamp isnot updated
Screenshots If applicable, add screenshots to help explain your problem.
Additional context Add any other context about the problem here.
Acceptance Criteria (for WP Media team use only) Clear instructions for developers, to be added before the grooming