How can you limit the number of images / videos that can be uploaded to a WordPress post

try this: add_filter(‘wp_handle_upload_prefilter’, ‘limit_wp_handle_upload_prefilter’); function yoursite_wp_handle_upload_prefilter($file) { // This bit is for the flash uploader if ($file[‘type’]==’application/octet-stream’ && isset($file[‘tmp_name’])) { $file_size = getimagesize($file[‘tmp_name’]); if (isset($file_size[‘error’]) && $file_size[‘error’]!=0) { $file[‘error’] = “Unexpected Error: {$file_size[‘error’]}”; return $file; } else { $file[‘type’] = $file_size[‘mime’]; } } if ($post_id = (isset($_REQUEST[‘post_id’]) ? $_REQUEST[‘post_id’] : false)) { if (count(get_posts(“post_type=attachment&post_parent={$post_id}”))>3) $file[‘error’] … Read more

How can I prevent uploading bmp image?

The magic is in get_allowed_mime_types() which calls the upload_mimes filter. That is filtering a default array consisting of keys as a non-terminated regular expression of file-extensions and the mapped mime-type as values: array( ‘jpg|jpeg|jpe’ => ‘image/jpeg’, ‘gif’ => ‘image/gif’, ‘png’ => ‘image/png’, ‘bmp’ => ‘image/bmp’, ‘tif|tiff’ => ‘image/tiff’, ‘ico’ => ‘image/x-icon’, …. } so hooking … Read more

How to prevent upload of a multiple sizes of images

I believe those are probably generated by the default WordPress sizes – thumbnail, medium and large. (See Appearance > Media for where those sizes are set). If you want to eliminate the extra image sizes the simplest way might be to eliminate some of your theme’s custom image sizes and use the defaults instead. OR, … Read more

Manipulating Media uploader

what i ended up doing was launching the thickbox uploaded manually via a jquery click event. then with setInterval i was able to hide the pieces i wanted. jQuery(document).ready(function($) { $(‘.specialclass’).click(function() { //get post id from somewhere (for me this was the row column string = $(this).parents(‘tr.type-portfolio’).attr(‘id’); if(/post-(\d+)/.exec(string)[1]) post_id = parseInt(/post-(\d+)/.exec(string)[1], 10); tbframe_interval = setInterval(function() … Read more

Media Uploader: get deleted files

Without seeing your “list editor” code I can only provide a theoretical answer. when a file is deleted in the media uploader, I also want it removed from the list the user is currently editing, so the files can’t be saved to my custom database table when it no longers exists in the “media environment”. … Read more

upload_mimes filter has no effect

I would use: add_filter( ‘upload_mimes’, ‘theme_restrict_mime_types’ ); function theme_restrict_mime_types( $mime_types ) { $mime_types = array( ‘wif’ => ‘text/plain’, ‘doc|docx’ => ‘application/msword’, ‘jpg|jpeg’ => ‘image/jpeg’, ‘gif’ => ‘image/gif’, ‘png’ => ‘image/png’ ); return $mime_types; } In this example I list all types that I allow (with WIF included). So you would need to add whats missing … Read more

How to protect uploads in multisite if user is not logged in?

Nice Question! Poking around it a little bit, this seems to be working (further tests and a more qualified look are much welcome:). Tested only in a localhost development install with subdomains. No domain mapping. Change the following .htaccess rewrite rule: # uploaded files # RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L] RewriteRule ^files/(.+) dl-files.php?file=$1 [L] Make a … Read more

wp_editor with media buttons

You can use following code to achieve this if ( is_user_logged_in() ) { // Editor without media buttons wp_editor( $content, ‘editorname’, array(‘media_buttons’ => false) ); } else { // Editor with media buttons wp_editor( $content, ‘editorname’); }

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