Skip to content
Docs
Get RestroPress

Filter

rpress_import_pre_sideload_image

Updated
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#

ParameterTypeDescription
$attachment_idnull|int|WP_ErrorAttachment to use instead. null by default.
$urlstringImage URL.
$post_idintMenu 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), in RPress_Importer_Engine::attach_image()
Was this page helpful?