Hi there!
WP Offload Media Support Team here, Thanks for reaching out with your query we would be happy to assist.
There’s currently no easy way to mark media items to avoid offloading. But we do have a filter that you could use, to avoid the automatic offloading of certain files.
You would need to install our Tweaks plugin. Then edit the pre_upload_attachment function and replace ‘mp4’ and ‘mov’ with the file extensions that you don’t want offloaded. You can add as many file extensions in the array as you want.
$abort = true; // abort all offloads
if ( is_string( $extension ) && in_array( $extension, array( 'png' ) ) ) {
$abort = false; // offload only these types
}
Then finally, to actually get WP Offload Media to start using this functionality, uncomment the add_filter( 'as3cf_pre_upload_attachment', ... line in the __construct function.
To avoid very specific files, you could use the file’s path with the filter –
function pre_upload_attachment( $abort, $post_id, $metadata ) {
$file = get_post_meta( $post_id, '_wp_attached_file', true );
if ( is_string( $file ) && false !== strpos( $file, 'https://www.example.com/wp-content/uploads/2023/02/sample.jpg' ) ) {
$abort = true; // abort the upload
}
return $abort;
}
Hope this helps!
great thanks.
what if I want exclude multiple images please?
where or how should input the image URL’s in above code please?
Thanks in advance.
Should I input multiple images URLs and seperate them by comma?
function pre_upload_attachment( $abort, $post_id, $metadata ) { $file = get_post_meta( $post_id, '_wp_attached_file', true ); if ( is_string( $file ) && false !== strpos ( $file,
'https://www.example.com/wp-content/uploads/2023/02/sample.jpg',
'https://www.example.com/wp-content/uploads/2023/02/sample2.jpg',
'https://www.example.com/wp-content/uploads/2023/02/sample3.jpg'
) ) { $abort = true; // abort the upload } return $abort; }
-
This reply was modified 2 years, 6 months ago by
alexliii.
-
This reply was modified 2 years, 6 months ago by
alexliii.
-
This reply was modified 2 years, 6 months ago by
alexliii.
Hi @alexliii,
I think you can use a code like the one below:
function pre_upload_attachment( $abort, $post_id, $metadata ) {
$file = get_post_meta( $post_id, '_wp_attached_file', true );
$excluded_files = array( 'file.jpg', 'file2.jpg', 'file3.jpg' );
if ( is_string( $file ) ) {
foreach ( $excluded_files as $exc ) {
if ( false !== strpos( $file, $exc ) ) {
$abort = true; // abort the upload
break; // we can stop the loop now
}
}
}
return $abort;
}
The $excluded_files array should contain the filenames of the images that you want to exclude from the offload process.
I hope this helps. Let us know how it goes for you.