How to add subfolders in media library for better organisation?

I too use have been using the Custom Upload Dir plugin that @sr83 mentioned to organise images and other upload files. It’s a useful solution, although not as flexible as I would like. It does provide a really great range of placeholders to build the folder path dynamically – including %file_ext%, %post_id%, %author%, %postname%, %post_type%, … Read more

Upload Multiple Files With media_handle_upload

here if you use custom template past this in the begining <?php if( ‘POST’ == $_SERVER[‘REQUEST_METHOD’] ) { if ( $_FILES ) { $files = $_FILES[“my_file_upload”]; foreach ($files[‘name’] as $key => $value) { if ($files[‘name’][$key]) { $file = array( ‘name’ => $files[‘name’][$key], ‘type’ => $files[‘type’][$key], ‘tmp_name’ => $files[‘tmp_name’][$key], ‘error’ => $files[‘error’][$key], ‘size’ => $files[‘size’][$key] ); … Read more

How do I select an image from Media Library in my plugin?

You should use wp.media to use the WordPress Media Manager dialog. First, you need to enqueue the scritps: // As you are dealing with plugin settings, // I assume you are in admin side add_action( ‘admin_enqueue_scripts’, ‘load_wp_media_files’ ); function load_wp_media_files( $page ) { // change to the $page where you want to enqueue the script … Read more

Physical organization of wordpress media library (Real Media Library plugin)

Free solution extension “Physical Custom Upload Folder” A long time ago I started to open this thread and now there is a usable extension plugin for Real Media Library which allows you to physically manage your uploads folder. Check out this plugin: https://wordpress.org/plugins/physical-custom-upload-folder/ Do you know the wp-content/uploads folder? There, the files are stored in … Read more

Programmatically adding images to media library

$image_url=”adress img”; $upload_dir = wp_upload_dir(); $image_data = file_get_contents( $image_url ); $filename = basename( $image_url ); if ( wp_mkdir_p( $upload_dir[‘path’] ) ) { $file = $upload_dir[‘path’] . “https://wordpress.stackexchange.com/” . $filename; } else { $file = $upload_dir[‘basedir’] . “https://wordpress.stackexchange.com/” . $filename; } file_put_contents( $file, $image_data ); $wp_filetype = wp_check_filetype( $filename, null ); $attachment = array( ‘post_mime_type’ => … Read more

Trigger refresh for new media manager in 3.5

The correct way of refreshing the content of the frame, as found in the WP core, is as below: if(wp.media.frame.content.get()!==null){ wp.media.frame.content.get().collection.props.set({ignore: (+ new Date())}); wp.media.frame.content.get().options.selection.reset(); }else{ wp.media.frame.library.props.set({ignore: (+ new Date())}); } You should always check of the content is available, else refresh the library. Cheers!