Here is something i cooked up which was taken mainly from the plugin Overwrite Uploads
but without the extra stuff
add_filter('wp_handle_upload_overrides','noneUniqueFilename');
function noneUniqueFilename($overrides){
$overrides['test_form'] = false;
$overrides['unique_filename_callback'] = 'nonUniqueFilenameCallback';
return $overrides;
}
function nonUniqueFilenameCallback($directory, $name, $extension){
$filename = $name . strtolower($extension);
//remove old attachment
removeOldAttach($filename);
return $filename;
}
function removeOldAttach($filename){
$arguments = array(
'numberposts' => -1,
'meta_key' => '_wp_attached_file',
'meta_value' => $filename,
'post_type' => 'attachment'
);
$Attachments_to_remove = get_posts($arguments);
foreach($Attachments_to_remove as $a)
wp_delete_attachment($a->ID, true);
}
Related Posts:
- How can I stop WP media uploader from creating duplicates of my uploaded images?
- Get attachments by user
- Adding wp_enqueue_media(); causes problem
- Media Uploader in custom path
- wp.media issue with selected image
- WordPress uploads do not show up and I see the white screen of death in some cases
- Convert base64 string to WordPress attachment uploads multiple images instead of a single one
- Get url of thumbnail from the media uploader
- Import media to online WordPress from local development
- Plugging into the Media Library to upload images (NOT associated with any post)
- How wordpress handle upload images and how to use them in the code
- How to regenerate thumbnails when they’re stored on S3
- How can one update a theme on a live site without interruption?
- How to upload images using Settings API
- trying to use wp_handle_upload with ajax
- How to add a download link to a movie from WP media library?
- Attach media to multiple posts
- Featured Images are not able to be set
- Customizer: Unique identifier that distinguishes which image upload control is uploading an image
- Unable to check if image uploaded by wp_image_editor exists using file_exists function
- How can i attach the attachment-ID to the user profile image?
- WordPress Media Uploader in page template (On Front-end)
- Can I get the ID of an inserted / linked image?
- Add attachment for all images in post
- Redirect to another page using contact form 7? [closed]
- Can I add an icon & function to the “Upload/Insert” toolbar at the top of the content editor?
- zip unzip attachments in wordpress
- Is it possible to determine when user is at “Media > Add New” vs “Post > Add an Image”
- WordPress creating images if uploaded image is greater than 960px on one side?
- Callback Function Not Firing On Selection In Media Uploader
- Using the media library for theme customization
- HTTP Error when uploading images over specific dimensions
- “The REST API did not process the context query parameter correctly.” Custom theme conflicting with Media Library
- How to make the media library searchable by image title
- How to destroy or dispose wordpress uploder/manager?
- Can’t upload images on new theme
- Custom Theme functions.php – Using add_settings_field and input type=”file” to set custom logo
- Is there any halfway decent documentation on the wp.media JS class?
- How can I fix my theme header for my CSS stylesheet?
- Editor User Role can’t see other users media
- Whether an tag is required in header?
- Alternative solution for script_loader_tag?
- Change logo url by category and in some pages
- How to make menus, footer, sidebars multi language
- How do I remove header/page-title image in farvis theme? [closed]
- Theme is Enqueueing Everything in Footer
- Enqueue script for development purposes only?
- How to show Custom Field Value in Woocommerce Shop Page
- add class to all images inside the content
- How to echo inside the js file with wp_localize_script?
- Show all menu levels except top level. How to exclude top level of a menu?
- Unable to delete option
- Cold Fusion to WordPress
- How to display latest posts with authors image
- Different WP Rest API custom endpoints across different themes
- Menu is in Reversed order
- How to set different localization file for different users?
- How to test another theme in a live WordPress website instead of live preview?
- How to display only the first two elements from ten same elements
- Is hand coding required at all?
- Bulk upload images in upload folder does not show in media library
- custom js script is not loading
- How to show some of category in wordpress
- WordPress link to another page in site does not render a
- Template for front page (latest posts)
- using themename_the_custom_logo() in template-tags?
- WordPress Menu item > Sub menu Class update
- Avoiding do_shortcode() loops
- I don’t know why categories are showing below post
- Duplicate child theme incl. design changes
- Move the social media icons to the left of a WordPress nav menu for Soledad child Theme
- Why .widget-area is outside of .site-content in Underscores starter theme?
- remove_action(‘genesis_header’,’genesis_do_header’) hook not working
- Using wp_add_inline_style Inside a Template File
- Styling the website via the customizer – do the changes stay after theme update?
- Text View (Code View) in WordPress Customizer TinyMCE Editor
- Alt header logo and link for specific pages
- How to upload multiple images using WP rest API to media?
- Custom php template file only for mobile
- which template should I use for single category post?
- How to get next post and previous post URL in loop, single.php My WordPress 4.9.6
- home is not working in wordpreess
- how to edit woocommerce checkout page
- How to transfer all posts, pages and media
- Recall translations made with Poedit
- Standard technique for AJAX post endpoint: WP REST or WP API?
- Which theme PHP file should be edited in order to change Posts appearance
- Creating a theme just to deploy a single page
- .htaccess and proxy settings for routing a decoupled REST API consuming theme
- Menu names not getting translated
- Why does the theme of secondary site load the primary one in WordPress Multisite? [closed]
- Creating a Sub Category Template
- Image paths wrong after migrating with wp-migrate-db-pro media files add-on
- How can I convert a list of title-posts into a sequence of comma separated text? [closed]
- How to connect two child themes on different sub domains to the same base theme
- How to add an import widgets functionality to wordpress themes without a plugin
- Is it possible to issue a theme update that requires a new plugin?
- Find callback function of custom meta box
- Should I use template files or just use conditional tags in index.php?
- Is there a way to create sections under “Colors” panel in the Theme Customizer?