# Modifying Offload Media code in Wordpress

**URL:** <https://www.phphelp.com/t/modifying-offload-media-code-in-wordpress/31558>\
**Category:** Help with WordPress\
**Created:** [April 10, 2020, 9:32am UTC](https://www.phphelp.com/t/modifying-offload-media-code-in-wordpress/31558 "2020-04-10T09:32:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AdventurePro](https://www.phphelp.com/user_avatar/www.phphelp.com/adventurepro/32/3033_2.png) [@AdventurePro](https://www.phphelp.com/u/AdventurePro)\
**Post date:** [April 10, 2020, 9:32am UTC](https://www.phphelp.com/t/modifying-offload-media-code-in-wordpress/31558/1 "2020-04-10T09:32:17Z")

</div>

Hi - I am brand new to PHP and am trying to modify a small bit of code for the Offload Media plugin. The aim is to stop any media which has the work KEEP or KEEP. in its filename from being offloaded.

I have spent all day trying various methods and none work, although I am told it is possible easily. Any advise as to whats wrong with my code will be appreciated. This is the code snippet Offload Media says should do the job, which I have modified slightly.

```
function pre_upload_attachment( $abort, $post_id, $metadata ) {
			$file = get_post_meta( $post_id, '_wp_attached_file', true );
	$filename = is_string( $file ) ? pathinfo( $file, PATHINFO_FILENAME ) : false;
	if ( is_string( $filename ) && in_array( $filename, array( 'KEEP' ) ) ) {
		$abort = true;
	}
```

---

<div class="post-metadata">

**Author:** ![astonecipher](https://www.phphelp.com/user_avatar/www.phphelp.com/astonecipher/32/2797_2.png) [@astonecipher](https://www.phphelp.com/u/astonecipher)\
**Post date:** [April 10, 2020, 1:15pm UTC](https://www.phphelp.com/t/modifying-offload-media-code-in-wordpress/31558/2 "2020-04-10T13:15:52Z")

</div>

First thing I would do, have the function just do the abort false statement. See if that prevents it. If it does then start testing out how to limit it to exclude that in the filename.
