Skip to content
Docs
Get RestroPress

Filter

restropress_rest_suppress_image_upload_error

Updated
On this page

Filters whether a failed image upload from a URL should be silently ignored.

Used in the ImageAttachment helper when uploading an image from a source URL fails with a WP_Error. Returning true makes the helper return quietly instead of throwing an exception.

Parameters#

ParameterTypeDescription
$suppressboolDefault false.
$uploadWP_ErrorThe upload error.
$object_idintID of the object the image belongs to.
$imagesmixedPassed as an undefined variable in the source, so it is null.

Return value#

bool. True to ignore the error.

Example#

function my_suppress_image_upload_error( $suppress, $upload, $object_id, $images ) {
	return true;
}
add_filter( 'restropress_rest_suppress_image_upload_error', 'my_suppress_image_upload_error', 10, 4 );

Notes#

This code is adapted from WooCommerce, calls wc_rest_upload_image_from_url() and throws WC_REST_Exception, and the ImageAttachment class is not used anywhere else in the plugin, so the hook is effectively unreachable.

Source#

Applied in:

  • includes/rest-api/Utilities/ImageAttachment.php (line 43), in ImageAttachment::upload_image_from_src()
Was this page helpful?