Filter
rpress_import_pre_sideload_image
On this page
Filters image sideloading to let a callback supply the attachment.
Runs before the importer downloads an item's image with media_sideload_image(). Returning anything other than null skips the download; return an attachment ID to use or a WP_Error or falsy value to count it as an image failure. Return null to let the importer download the image.
Parameters#
| Parameter | Type | Description |
|---|---|---|
$attachment_id | null|int|WP_Error | Attachment to use instead. null by default. |
$url | string | Image URL. |
$post_id | int | Menu item (fooditem) post ID. |
Return value#
null|int|WP_Error. An attachment ID, a WP_Error, or null to sideload normally.
Example#
add_filter( 'rpress_import_pre_sideload_image', 'my_pre_sideload_image', 10, 3 );
function my_pre_sideload_image( $attachment_id, $url, $post_id ) {
$existing = attachment_url_to_postid( $url );
return $existing ? $existing : $attachment_id;
}
Source#
Applied in:
includes/features/importer/class-rpress-importer-engine.php(line 1248), inRPress_Importer_Engine::attach_image()
Was this page helpful?
