The upload directory and URL paths are stored in the options database. You can change them using update_option()
:
update_option( 'upload_path', ABSPATH . '/path/to/uploads' );
update_option( 'upload_path_url', site_url( '/uploads/' ) );
However, it’s best not to use this in a publiuc plugin, as it will cause numerous issues. We can instead hook into the filters that control the result of getting these options and set them to our custom paths:
function wpse_84046_upload_path( $path ) {
return '/path/to/uploads';
}
add_filter( 'pre_option_upload_path', 'wpse_84046_upload_path' );
function wpse_84046_upload_path_url( $url ) {
return site_url( '/uploads/' );
}
add_filter( 'pre_option_upload_path_url', 'wpse_84046_upload_path_url' );
Related Posts:
- Remote upload file to server B
- wp_generate_attachment_metadata is creating an empty array
- Redirect to another page using contact form 7? [closed]
- Move plugin upload folder from mywebsite.com/wp-content/uploads/pdfuploads to mywebsite.com/pdfs?
- How to structure a plugin
- is_plugin_active function doesn’t exist
- Proper Way to Modify Plugin
- “Add Media” button in custom plugin
- Consuming an external API in WordPress?
- How to edit a wordpress plugin without break its update process
- Looking for a Table of Contents (TOC) plugin for WordPress
- WordPress Plugin Development In MVC Architecture, How?
- Where should I use get_option in a plugin
- GPL and plugins
- Disable Specific Widgets on Selected Pages of a WordPress Website?
- Create page when plugin is activated
- Integrating plugins in themes
- How to show custom message once on plugin activation?
- Post source link plugin – small modification
- How to add users roles dropdown in registration in wordpress
- wp_schedule_event / cron_schedules – custom recurrence time not working in Plugin
- How to load a new template page according to a particular URL?
- WordPress network: set themes and plugins for new blog
- Themes VS Plugins [duplicate]
- Failed to invoke other hook from the init hook
- How to edit plugin’s html? [closed]
- How can I add a custom meta value on file upload?
- Can a plugin add to header/footer/body content?
- Advanced Integration – WordPress + YOURLS
- How can I use a video header that’s over 8MB?
- Admin page: form with enctype=”multipart/form-data” does not transfer its data
- Organising the plugins folder in wordpress
- Upload file inside plugins options page
- force customers to add only single item to card per purchase EDD [closed]
- Preventing BFA in WordPress without using a plugin
- Output HTML only on individual post view
- Manually add order item with fixed product_id in WooCommerce
- ‘Customize’ button in admin bar for CSS
- Auto delete WordPress users according to time
- How to use get_theme_mod in gutenberg editor wordpress?
- How to show Recent Page instead of Post?
- How organize uploaded media in WP?
- How would I go about creating a user ranked post popularity page?
- Overide plugin files from child theme (/inc/ ) folder
- Calling an attribute from a plugin shortcode
- wp.media javascript issue with on select
- External Domain on WordPress Multisite
- Add ALT attribute to Pin It Button image to pass HTML5 validation
- Customize The Events Calendar to Include an Option to Expand for More Events Listings
- changing posts layout in ultimate member profile plugin
- Login Customizer doesn’t change the background of the register form
- How do i get file_get_contents to work in wordpress
- Plugin Development – Functions or Hooks?
- Is there a function to list all uploaded images? How can I add one?
- When I try to de-activate any plugin it gives error “Warning: call_user_func_array() [function.call-user-func-array]”
- How to create plugin in wordpress [closed]
- File Uploader – Upload without adding to Media Library
- I want to filter my products with attributes [closed]
- Action on WordPress Install
- Delete data from custom table when deleting a post
- What is the best way to make a custom page from a plugin?
- Simple sildeshow/image-upload plugin?
- Automatic recurring payment using YITH subscription and Dokan Stripe
- How to customize maintenance mode notification in wordpress?
- Hide fields in woocommerce settings
- Elementor: How to design Dropdown Select Box Navigation page like Chegg
- implement custom roles in custom plugin
- How to copy the all WordPress media items to another custom plugin folder?
- How to access a wordpress plugin page or add posts without doing it from the WordPress dashboard?
- Adding LOAD MORE on a page
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- Is it possible to pull all featured images from WP database only?
- How to assign a specific service to a specific provider based on location
- the content of the uploads folder gets deleted periodically, how to figure out what causes it?
- Creating custom “player-objects”
- 500 Internal server error wp_handle_upload_prefilter
- Cannot display wordpress thumbnail
- Cron job shedules replace?
- upload multiple images using wp_handle_upload
- How wordpress handle urls present in db for external wp-content directory
- woocommerce with external ftp site
- Installation failed, trying to install ANY plugin
- Customize plugin templates
- Media library and Upload media problem
- Widget display in theme
- How to use custom footer template in a site-plugin?
- Multi-site error wordpress after migration
- Media Upload to custom database and Custom Directory
- WP default file upload hook not working if used in a plugin
- Customize a widget position
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- Problems with installing and deleting plugins
- include plugin folder directly in theme folder to load faster page n wp
- Pronamic Info Window
- From a legal perspective, is it okay to customize a plugin’s code?
- Is there a WP-Plugin to convert PNG to GIF? [closed]
- Child Plugin Admin Panel
- Does anyone have the Custom Post Permalinks plugin from John P. Bloch? [closed]
- How to display content depending on the Woocommerce Product Category
- WordPress isn’t sending welcome email with the password reset