Tag Info

Hot answers tagged

8

Philipp, anything is possible if you set your mind to it. You can solve your issue by extending the WordPress image editor class. Note I'm using WordPress 3.7 - I haven't checked any of the below code in earlier versions and in the latest 3.8 release. Image Editor basics WordPress has two built in classes that handle image manipulation: ...


7

A simple answer is that you can remove 2 unused sizes by enter 0 for their width or height. For example, you need only the small thumbnail 150x150 and full-sized image, so enter 0 for width and height of Medium and Large sizez.


6

Following Justice Is Cheap lead, I ended adapting the functions from this plugin: http://wordpress.org/extend/plugins/custom-upload-dir/ <?php /* * Change upload directory for PDF files * Only works in WordPress 3.3+ */ add_filter('wp_handle_upload_prefilter', 'wpse47415_pre_upload'); add_filter('wp_handle_upload', 'wpse47415_post_upload'); ...


6

I would advise against un-ticking 'Organize Media' unless in a situation where you are handling storage elsewhere. Having a large amount of files in one directory is flawed for many reasons, though there is some situations where this is unavoidable but for a website this is always unavoidable. I inherited a Wordpress website and was tasked with moving it ...


5

In addition to what Joseph suggested, you can also define the upload path in the wp-config.php file like this: define( 'UPLOADS', 'wp-content/'.'files' ); If you'd like it outside the wp-content folder, specify path like this: define( 'UPLOADS', ''.'uploads' ); For uploading to a folder like example.com/images, use this code: //Custom upload path ...


5

Another chance to recommend two plugins I created that together will do what you want. Virtual intermediate images will intercept the creation of the intermediate image sizes: they will not be created on disk, but still exist in the metadata array. This makes WordPress think they exist so you can use them like normal images. The companion plugin, On-Demand ...


4

Images sizes for the purpose of creating/deleting attachments seem to be retrieved with get_intermediate_image_sizes() function, that isn't documented in Codex (only briefly mentioned in 3.0 release notes). That function passes result (combined set of default and custom image sizes) through intermediate_image_sizes filter, so you can likely use that hook to ...


4

You can add a filter to upload_dir. Here is a simple class I wrote to do this for a project. Use the protected $filter_path variable to define the alternate uploads directory (*will be relative to wp-content/uploads) class UGC_Attachment { protected $upload_dir; protected $upload_url; protected $filter_path = ...


4

Go to Dashboard -> Settings -> Media Enter the desired location in Store uploads in this folder Uncheck Organize my uploads into month- and year-based folders This will specify the global upload location. To specify a per-file upload location, you'll need to use a Plugin, such as WP Easy Uploader (not an endorsement, per se; it was just the first ...


4

Both of these are possible. Insert Attachment into Media Library By using the wp_insert_attachment function, you can insert your uploaded images to the Media Library. This is the example code from the Docs: <?php $wp_filetype = wp_check_filetype(basename($filename), null ); $wp_upload_dir = wp_upload_dir(); $attachment = array( 'guid' => ...


3

It turns out I was barking up the wrong (or at least a slightly different) tree by using wp_insert_attachment. media_sideload_image managed to pull attachments from other blogs on the same multisite install, copy them to the aggregating blog's uploads directory, and generate thumbnails, while wp_insert_attachment was doing what it was supposed to, which just ...


3

If i understand your question right you want a function within your theme that adds directories for the current post_type? like: uploads/post_type_name. if so here is a function for that: function wpse_16722_type_upload_dir( $args ) { // Get the current post_id $id = ( isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : '' ); if( $id ) { ...


3

Yes, it does. I had to do something similar just yesterday and worked out this solution. About the same as the linked solution, but with a bit more error checking. <?php add_filter('upload_dir', 'cgg_upload_dir'); function cgg_upload_dir($dir) { // xxx Lots of $_REQUEST usage in here, not a great idea. // Are we where we want to be? if ...


3

if you need to change default media upload location,you need to edit the wp-config.php file located in the root directory of your WordPress installation. If you want upload directory to be wp-content/files then you will need to place the following code in wp-config.php define( 'UPLOADS', 'wp-content/'.'files' ); If you want the upload directory to be ...


2

You can work on the idea that Joost provided and use the upload_dir filter to temporarily set the upload path to somewhere else. /** * Override the default upload path. * * @param array $dir * @return array */ function wpse_141088_upload_dir( $dir ) { return array( 'path' => $dir['basedir'] . '/mycustomdir', 'url' ...


2

I believe by default these folders are created by user interaction, however, it's possible that a plugin may be calling a function to create these monthly upload folders. Note that using this function will create a subfolder in your Uploads folder corresponding to the queried month (or current month, if no $time argument is provided), if that folder is ...


2

Well, after lots of digging (before and after posting this question), I think I figured it out. As @s_ha_dum suggests, the reason behind the odd directory placement is likely a personal preference of the person who created the Ubuntu "wordpress" package. Perhaps it makes for easier partitioning of permissions, or it makes updates more safe (in case the ...


2

Analyze From the plugins source: it uses wp_upload_dir() and wp_insert_attachment(), which uses update_attached_file(). So basically the plugin should just incorporate your media settings. If it is not doing this, it has a conflict with either some other plugin, or your wp-config.php settings. Filter callback for the rescue You can still use the ...


2

add_filter( 'option_uploads_use_yearmonth_folders', '__return_false', 100 ); That's all you need, seriously!


2

Another solution to this problem: Go to Dashboard → Settings → Media and uncheck "Organize my uploads into month- and year-based folders". So now every file you upload will be placed in "wp-content\uploads" [optional step, but recomended to find easily new uploads for moving to another folder]. Install "Media File Manager" plugin. Go to Dashboard → Media → ...


2

When you uploaded an image within the Edit Page screen for a page with a date of 06/01/2013, the media uploader will use the date of the page to set the sub-directory within the uploads folder. This is expected behavior because the media uploader passes the post_date to the wp_upload_dir() function. See ...


2

Can't this simply be done with media_sideload_image() ? Seems pretty simple. Only catch is if you aren't on admin area, you must include some libraries from within WordPress includes: // only need these if performing outside of admin environment require_once(ABSPATH . 'wp-admin/includes/media.php'); require_once(ABSPATH . 'wp-admin/includes/file.php'); ...


2

Sorry if you have tried this already, but I go for the simplest answer first ;) In dashboard, Settings -> Media -> Uploading Files section to set path. Screenshot: https://skitch.com/mrsdrwife/8myu1/media-settings-elitemom.net-wordpress


2

Code based in other Answer of mine and this SO Answer. It uses the post/page/cpt publish date to build the paths. Note that $the_post->post_date_gmt is also available. add_filter('wp_handle_upload_prefilter', 'wpse_70946_handle_upload_prefilter'); add_filter('wp_handle_upload', 'wpse_70946_handle_upload'); function wpse_70946_handle_upload_prefilter( ...


2

You can find it at /wp-admin/options.php, which lists all options alphabetically. It'll be near the bottom.


2

That's a server permission problem. According to the WP docs: Any file that needs write access from WordPress should be owned or group-owned by the user account used by the WordPress (which may be different than the server account). For example, you may have a user account that lets you FTP files back and forth to your server, but your server ...


2

If I remember it right, this happened to me once. I deleted my /uploads directory (to delete all the images) and went back to posting thinking that WordPress will automatically create an /uploads directory and any necessary sub-directories for me. And yes, that's how it works. But here's the catch -- WordPress doesn't set proper permissions for the /uploads ...


2

Typo: ' not is ‘ You have a weired Editor. You're simply using the wrong type of quotes: “ should be " ‘ should be ' Here's the changed function: function wpse43013_custom_upload_directory( $args ) { // If the parent_base is "members", upload to plugin directory if ( 'members' === get_current_screen()->parent_base ) return ...


2

There must be something identifiable about your form data, such as your input names. Check for one or more of those and process accordingly. function custom_upload_dir($args) { if (isset($_POST['something'])) { $args['path'] = $args['basedir'] . "/mypath" . $args['subdir']; $args['url'] = $args['baseurl'] . "/mypath" . ...


1

I created a symbolic link in the /var/www/ directory. ln -s /srv/www/wp-uploads/ wp-uploads and then (in settings-> media) set up the upload folder: wp-uploads and url path: http://<my-ip>/wp-uploads



Only top voted, non community-wiki answers of a minimum length are eligible