Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore Retina Support (via WP Retina 2x, aka Perfect Images, plugin compat) #656

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from

Commits on Jan 26, 2022

  1. Add code for WPR2x that was removed from 68c489b

    This is just grabbing the WPR2X code that was deleted. It's no longer wired into our stuff, so it won't do anything yet.
    iCaspar committed Jan 26, 2022
    Configuration menu
    Copy the full SHA
    6587bb3 View commit details
    Browse the repository at this point in the history

Commits on Jan 31, 2022

  1. Update namespacing, classnames and autoloading

    PHPCS - update minimum PHP version to 7.0
    Rename wp-retina-2x classes to PerfectImages and add namespace
    Add PerfectImages namespace to composer PSR4
    Use new class names in 3rd-party PerfectImages loader file
    Add PerfectImages fileloader to 3rd-party required files
    Stop using deprecated user_can() check - use WP context user check instead
    Update asset script localization to use updated enqueue
    iCaspar committed Jan 31, 2022
    Configuration menu
    Copy the full SHA
    de402a0 View commit details
    Browse the repository at this point in the history
  2. Use Imagify_Filesystem

    iCaspar committed Jan 31, 2022
    Configuration menu
    Copy the full SHA
    48bce9e View commit details
    Browse the repository at this point in the history
  3. Add back js assets previously removed

    The 3 assets here were included by the previous compatibility.
    (Not sure yet if we will still need them, but adding them back because they are still trying to be loaded on library page -- until we can sort it out.)
    iCaspar committed Jan 31, 2022
    Configuration menu
    Copy the full SHA
    4ffeb21 View commit details
    Browse the repository at this point in the history

Commits on Feb 2, 2022

  1. Use min WP version 5.3 for phpcs

    The WP min version is set in the plugin.php to 5.3 -- phpcs should match.
    iCaspar committed Feb 2, 2022
    Configuration menu
    Copy the full SHA
    33b21c3 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    77d4753 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    b45a06b View commit details
    Browse the repository at this point in the history
  4. Add PerfectImages methods for retina generation

    Add first a new property `$retina_sizes[]` to store some size info when Perfect Images generates a new retina file.
    
    Comment out (for now) the old ajax hooks, as Perfect Image no longer uses ajax.
    
    Add 3 methods:
    1. `add_retina_sizes(int $media_id, string $retina_file, string $size_name): void` hooked to Perfect Images `wr2x_retina_file_added `, will store the media ID, retina filepath, and size name in our new `$retina_sizes` property whenever Perfect Images generates a new retina file.
    
    2. `optimize_retina_sizes(int $media_id): void` hooked to Perfect Images `wr2x_generate_retina`, will find all the retina sizes added at the end of a Perfect Images retina generation process for a media ID (as stored in our class property) and start a new Imagify Optimization process for the newly generated retina files.
    
    3. `add_retina_sizes_meta(array $sizes): array` hooked to Imagify's `imagify_media_files` will filter the imagify Media size meta to include the retina sizes, and flag the new sizes as being allowed to optimize.
    iCaspar committed Feb 2, 2022
    Configuration menu
    Copy the full SHA
    f8e7761 View commit details
    Browse the repository at this point in the history

Commits on Feb 4, 2022

  1. Add methods for deleting retinas

    We add 4 methods here, 2 public, and 2 private helpers:
    The 2 public methods are both hooked on Perfect Images `wr2x_retina_file_removed` action.
    1. `remove_retina_webp_size(int $media_id, string $retina_file ): void` will check for any webp versions of the retina file that was deleted and remove it if it exists. Note we run this even if Imagify's webp option is not currently enabled, because it may have been enabled at the time the retina was generated, and disabled since. This uses the private helper method:
    2. `get_retina_webp_filepath(string $attachment_file, string $retina_file): string`. This method handles the subtask of getting the correct webp file path based on the attachment's original filepath and the retina image's filename.
    3. `remove_imagify_retina_data(int $media_id, string $retina_file): void` will purge optimization data imagify uses to track the status of retina images it has optimized. Two entries have to be checked and removed for each retina image size that's been deleted: the optimization data generated when we optimized the @2x image Perfect Images created, and the @2x@imagify-webp data for the webp version (if any) that Imagify created in connection with that retina size. This uses the private helper method:
    4. `get_retina_imagify_data_size_names(array $sizes, string $origina_size_name): array`. This method compares the sizes information (formatted per `wp_get_attachment_metadata()` to the original filename of an attachment that included a retina image size, and gives us an array of all the related size names that might be present in Imagify's optimization data for the attachment.
    iCaspar committed Feb 4, 2022
    Configuration menu
    Copy the full SHA
    1063b72 View commit details
    Browse the repository at this point in the history
  2. Add re-optimization of images after regeneration

    Adds a method to restore a full-size image from the backed up original.
    Adds a method to replace back the previously optimized full-size image after image regeneration.
    Adds a method to send regenerated images to the queue for re-optimization.
    
    We also hook the restore/replace before and after the generation of retina sizes to insure that the original is being used to generate the retinas as well.
    iCaspar committed Feb 4, 2022
    Configuration menu
    Copy the full SHA
    a4e0adb View commit details
    Browse the repository at this point in the history

Commits on Feb 7, 2022

  1. Remove unused js assets

    These were added back in on 4ffeb21  just in case. It turns out we don't need them any more.
    iCaspar committed Feb 7, 2022
    Configuration menu
    Copy the full SHA
    33c212f View commit details
    Browse the repository at this point in the history
  2. Remove PerfectImagesCore

    All Perfect Images functionality is handled in the PerfectImages class now. The PerfectImagesCore is dead code.
    iCaspar committed Feb 7, 2022
    Configuration menu
    Copy the full SHA
    3ee9a92 View commit details
    Browse the repository at this point in the history
  3. Remove PerfectImagesCore from main class

    Also, cleans up some phpcs spacing and comment formatting.
    iCaspar committed Feb 7, 2022
    Configuration menu
    Copy the full SHA
    773e60e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    1107dc0 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    05f3d8a View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    830c391 View commit details
    Browse the repository at this point in the history

Commits on Feb 8, 2022

  1. Configuration menu
    Copy the full SHA
    c8cc135 View commit details
    Browse the repository at this point in the history
  2. Use array_keys to get size names directly

    We're not going to use the related data in this case. Just get the keys and eliminate the unused variable inside foreach.
    iCaspar committed Feb 8, 2022
    Configuration menu
    Copy the full SHA
    e4eff0d View commit details
    Browse the repository at this point in the history
  3. Extract can_restore_original() method

    The cyclomatic complexity (and readability) of `restore_originally_uploaded_image()` was 10. All of that is due to checking the various conditions before doing the restore.
    
    This extracts all the checking to a helper method.
    iCaspar committed Feb 8, 2022
    Configuration menu
    Copy the full SHA
    a9ab001 View commit details
    Browse the repository at this point in the history
  4. Extract add_webp_sizes() to helper method

    Refactors the process for getting the needed webp sizes for optimization to it's own method.
    iCaspar committed Feb 8, 2022
    Configuration menu
    Copy the full SHA
    142fd83 View commit details
    Browse the repository at this point in the history

Commits on Feb 11, 2022

  1. Check for new upload before doing retina process

    For new uploads, we're going optimize everything after all the other things run their stuff.
    In this case we don't want to start a proces for this media now -- doing so will "Lock" the media when the full process tries to run in a few moments, and while retinas will be processed nothing else will be included!
    iCaspar committed Feb 11, 2022
    Configuration menu
    Copy the full SHA
    8fc613f View commit details
    Browse the repository at this point in the history