Attach Files Metabox

For the part of opening a lightbox, browse for something and then performing something on an action within: WordPress has this already build in. For what you ask is basically the thickbox that opens up like in the post editor when you browse for an image in the gallery. You find all the code you … Read more

Upload file to remote storage

Two options: Hook into ‘wp_handle_upload’, a filter provided by the function wp_handle_upload() in wp-admin/includes/file.php: apply_filters( ‘wp_handle_upload’, array( ‘file’ => $new_file, ‘url’ => $url, ‘type’ => $type ), ‘upload’ ) Replace the new file URI with your remote URI. The function wp_insert_attachment() in wp-includes/post.php offers two actions: do_action(‘edit_attachment’, $post_ID); do_action(‘add_attachment’, $post_ID); You can get the attachment … Read more

WordPress Media Manager – limit to specific mime type

This is not full solution, it’s only a direction for you to work with media uploader Firstly, you need to know how to implement Media Uploader in your plugin/theme. You can learn that from the file: wp-admin/js/custom-background.js which is used by WP for custom background page. If that’s too hard to understand, then read this … Read more

Changing upload directory for plugin uploads only

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” . $args[‘subdir’]; } return $args; } After some investigation, the only things I … Read more

Password protect some uploaded files, so only logged-in users can view them

See my question and answer again, you linked it already in your question: simple solution for restricting access to (some) uploads/downloads The solution isn’t that hairy the only necessity – besides configuring the plugin correct – is to create a .htaccess, which you could do programmatically. For that you have to automate the creation of … Read more

Prevent image upload unless exact size

Haven’t tested it, but this should work: // check for file upload size // { if( !current_user_can( ‘administrator’) ) add_filter( ‘wp_handle_upload_prefilter’, ‘mdu_validate_image_size’ ); } add_filter(‘wp_handle_upload_prefilter’,’mdu_validate_image_size’); function mdu_validate_image_size( $file ) { if ( mime_content_type($file) == ‘application/zip’ ) { mdu_validate_zip_image_size($file); return $file; } $image = getimagesize($file[‘tmp_name’]); $minimum = array( ‘width’ => ‘800’, ‘height’ => ‘450’ ); $maximum … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)