Imports a related image from the API and saves it to the Wordpress media library. Only supports after_create as we need the parent post's ID.
Located at culturehosts-importer/src/Service/Tasks/Fetch_Related_Image.php
| Methods |
public
|
__construct(string $source_field = 'image_id', boolean $set_as_featured = true, string $meta_key = null)
Create a task that grabs an image ID from a certain field, finds the image file in the
CultureHosts API, then sideloads it into the Wordpress media library.
Create a task that grabs an image ID from a certain field, finds the image file in the
CultureHosts API, then sideloads it into the Wordpress media library.
Parameters
| $source_field |
The field name where we find the image_id
|
| $set_as_featured |
Whether to set the imported image as a featured image of the
parent record that is currently the subject of the import.
|
| $meta_key |
Set a postmeta meta_key name where the image ID should be
saved, if desired. For example, for an ACF image field.
|
|
#
|
public
|
supports_when(string $when): boolean
Only supports after_x as we need the parent post's ID.
Only supports after_x as we need the parent post's ID.
Parameters
| $when |
The event to check we're valid for.
|
Returns
Only true for the after_create, after_update and after_auto_update events
Implements
|
#
|
public
|
run(Record $remote_record, array &$local_record, string $when): boolean
The importer calls this method for each record being imported.
The importer calls this method for each record being imported.
Parameters
| $remote_record |
The record as received from the CultureHosts API
|
| $local_record |
The post details, in the format accepted by wp_insert_post.
|
| $when |
The relevant event, e.g. before_create, after_create, before_update...
|
Returns
Whether the task succeeded
Implements
|
#
|