Hot answers tagged

11

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: ...


11

What date was/is the post published? Media uploads are added to the folder when the post/page was published, not the upload date. Was the post originally published in Feb 2015? https://core.trac.wordpress.org/ticket/10752


9

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 ...


8

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 ...


8

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'); ...


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.


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 ...


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

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 ) { ...


5

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'); ...


4

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 ...


4

It would be nice if WordPress had a standards based cache directory, but since it doesn't I think the best option is to keep it in the plugin folder itself. Uploads are in my opinion for actual uploads and cache files are not really considered as such. I think it easier to manage , reduces possible conflicts and to be honest it's where I would look if a ...


4

If uploaded to some content entity like e.g. post, page or custom post type, WordPress does arrange the attachments uploads by creation date of that entity - and not according to the upload, creation date of the attachment. That might just be the case for you, because otherwise I can't think of a reasonable, related to default behavior, explanation for what ...


4

This is how I understand the process: The wp_upload_dir() function is the main control room for the upload folder creation process and the wp_mkdir_p() function is the helpful assistant. Everytime wp_upload_dir() is called, it's actually running a file_exists() check on the current upload folder, through the wp_mkdir_p() function. If the folder doesn't ...


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

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

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

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


3

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 → ...


3

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 ...


3

About the assigned folders for uploaded photos - If a photo is uploaded within a post/page, it will be in the folder corresponding to the date of the post/page e.g. if post date is June 2015, uploaded photos will be in /uploads/2015/06 folder. If a photo is uploaded directly in the media library (not within any post/page), it will be in the folder ...


3

A small mistake, the return should be outside if add_filter("upload_dir", function ($args) { $id = (isset($_REQUEST["post_id"]) ? $_REQUEST["post_id"] : ""); if($id) { $newdir = "/" . get_post_type($id); ... } return $args; });


3

try to use get_temp_dir() to see if wordpress is using your WP_TEMP_DIR constant. i've tried this code in wp-config.php and it works define('WP_TEMP_DIR', dirname(__FILE__) . '/wp-content/temp/'); but you have to put it before the /* That's all, stop editing! Happy blogging. */ in your wp-config.php file.


3

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

You can rename your uploads directory in two ways: by defining the new directory name on your wp-config.php by writing a small function to change the directory dynamically. Here I explained both the ways. Just take a look at here. Also you can rename wp-content directory. Rename wp-content Folder and Uploads - WordPress


2

@Robbert's answer was a divine resource in my efforts to store alternate sizes generated by WordPress in separate directories. My code also changes the upload directory to ./media so make sure to edit these lines if you don't want that. It's not an exact answer to the first poster's question, but offers an alternative solution to the same problem: if ( ...


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

It was actually easier than I thought. function route_uploads_past_cdn( $url, $path ) { $upload_paths = array( 'async-upload.php', 'media-new.php' ); if( !in_array( $path, $upload_paths ) ) { return $url; } return str_replace('www.', '', $url); } add_filter( 'admin_url', 'pew_route_uploads_past_cdn', 10, 2 ); The URL for ...



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