Title: How to use this programmatically
Last modified: August 19, 2020

---

# How to use this programmatically

 *  Resolved [GeddeDev](https://wordpress.org/support/users/ggedde/)
 * (@ggedde)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/how-to-use-this-programmatically/)
 * I am needing to do this programmatically and was curious if you have any documentation
   to your code as to how I can do this with code instead of requiring my clients
   to do this through the Admin Panel.
 * If you don’t have documentation for this can you share some code snippets on 
   how to do this or point me to your code where it is being done.
 * I know do to upload images and attach them with code already using WP best practices
   so I don’t need the a-z tutorial. Just how to manage the replacement part. Thanks.

Viewing 1 replies (of 1 total)

 *  Plugin Support [Gerard Blanco](https://wordpress.org/support/users/sixaxis/)
 * (@sixaxis)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/how-to-use-this-programmatically/#post-13299217)
 * Hi [@ggedde](https://wordpress.org/support/users/ggedde/),
 * In views/upload.php you can find the script that runs after a file has been uploaded.
   The script does a lot of checks and prepares the replacer class for doing its
   job. You can find these functions:
 *     ```
       $replacer = new Replacer($post_id);
       $replacer->setMode(\EnableMediaReplace\Replacer::MODE_REPLACE);
       $replacer->setTimeMode($timestamp_replace, $datetime);
   
       [optionally] $result = $replacer->setNewTargetLocation($new_location_dir);
   
       $result = $replacer->replaceWith($_FILES["userfile"]["tmp_name"], $new_filename);
       ```
   
 * Cheers,

Viewing 1 replies (of 1 total)

The topic ‘How to use this programmatically’ is closed to new replies.

 * ![](https://ps.w.org/enable-media-replace/assets/icon-256x256.png?rev=1940728)
 * [Enable Media Replace](https://wordpress.org/plugins/enable-media-replace/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/enable-media-replace/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/enable-media-replace/)
 * [Active Topics](https://wordpress.org/support/plugin/enable-media-replace/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/enable-media-replace/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/enable-media-replace/reviews/)

## Tags

 * [programmatically](https://wordpress.org/support/topic-tag/programmatically/)

 * 1 reply
 * 2 participants
 * Last reply from: [Gerard Blanco](https://wordpress.org/support/users/sixaxis/)
 * Last activity: [5 years, 9 months ago](https://wordpress.org/support/topic/how-to-use-this-programmatically/#post-13299217)
 * Status: resolved