-
Notifications
You must be signed in to change notification settings - Fork 131
Closed as not planned
Closed as not planned
Copy link
Labels
[Plugin] Performance LabIssue relates to work in the Performance Lab Plugin onlyIssue relates to work in the Performance Lab Plugin only[Plugin] Regenerate Existing ImagesIssues for the Regenerate Existing Images moduleIssues for the Regenerate Existing Images module
Description
Create the perflab_job_regenerate_images
action to handle image regeneration within the background process. This action will be called by the background processing infrastructure. Code for the background job should be written in a new module file module/images/regenerate-existing-images/regenerate-existing-images-job.php
.
Acceptance Criteria
- Create a new function registered to the
perflab_job_regenerate_images
action. - The function will accept the following parameters
$job_id
- The term ID for the current Regenerate Images background job$job_data
- The job data array for the current Regenerate Images background job
- The function will run a WP_Query to retrieve the attachment IDs to run. The query will use the following parameters:
post_type
:attachment
fields
:ids
posts_per_page
:5
- The query will include the following
tax_query
array(
'taxonomy' => 'background_job',
'field' => 'term_id',
'terms' => $job_id,
'operator' => ‘NOT IN’,
)
- Using the attachment IDs returned from the WP_Query, the function will loop through the attachment IDs and regenerate each image one by one.
- Backup the
sizes
found in thewp_get_attachment_metadata
in a new_backup_image_sizes
post meta - Backup the
sources
found in thewp_get_attachment_metadata
in a new_backup_image_sources
post meta - Unset the sources and sizes metadata in the
wp_update_attachment_metadata
- Get an array of the images sizes using
wp_get_missing_image_subsizes
- Loop over each image size returned and do the following:
- Create the new image size using the
wp_get_image_editor
- Create additional sources for the image size using the image editor
- On success, update the newly created image size in the attachment metadata with
wp_update_attachment_metadata
- On failure, Update the attachment post meta
_regenerate_failures
and increment the count - If the
_regenerate_failures
meta count reaches 8 retries:- Add the job term to the attachment with
wp_set_object_terms
using the$job_id
- Backfill all previous sizes and sources metadata using the backup metadata (
_backup_image_sizes
and_backup_image_sources
)
- Add the job term to the attachment with
- Create the new image size using the
- Once all image sizes have been successfully updated
- Check the value of the
delete_images
key in the$job_data
. If the value is true, delete the old image files using the backup metadata for reference - Add the job term to the attachment with
wp_set_object_terms
using the$job_id
- Delete the backup metadata from the attachment (
_backup_image_sizes
and_backup_image_sources
)
- Check the value of the
- Backup the
Metadata
Metadata
Assignees
Labels
[Plugin] Performance LabIssue relates to work in the Performance Lab Plugin onlyIssue relates to work in the Performance Lab Plugin only[Plugin] Regenerate Existing ImagesIssues for the Regenerate Existing Images moduleIssues for the Regenerate Existing Images module