Edit image / Delete image link

This isn’t 100% complete, but should be a good start for you. <a href=”https://wordpress.stackexchange.com/questions/31371/<?php echo wp_nonce_url(“/wp-admin/post.php?action=delete&amp;post=$post->ID”, ‘delete-attachment_’ . $post->ID ) ?>”><?php _e( ‘Delete Permanently’ ) ?></a> A couple notes on what you’ll have left to do: This will do no confirmation, so you’ll probably want to use JS to verify that it wasn’t clicked by … Read more

Change behavior of “Insert into Post” based on attachment metadata

In case it’s helpful to anyone else, here’s what my code looked like to achieve this. I didn’t end up saving the attachment data at all, per tbuteler’s suggestion, but rather than using $_REQUEST I found I could use the $attachment array directly: function my_attachment_fields_to_edit( $form_fields, $post ) { $supported_exts = supported_types(); // array of … Read more

complex restriction of items in media library

Good code. I think you could simplify by making direct SQL queries instead: — Featured Images SELECT `meta_value` FROM `wp_postmeta` WHERE `meta_key` = ‘_thumbnail_id’; –> $thumbnail_ids — Header Images SELECT `post_id` FROM `wp_postmeta` WHERE `meta_key` = ‘_wp_attachment_context’ and `meta_value` = ‘custom-header’; –> $header_ids Also, with your method, I think that if you call WP_Query with … Read more

Limit Media Library to Given Folder

A solution that works for me is to add a clause to the WordPress query when the media library is being displayed. From browsing my WordPress database I noticed that the full path to wp_posts.post_type=”attachment” is stored in the wp_posts.guid column. add_filter(‘posts_where’, ‘limitMediaLibraryItems_56456’, 10, 2 ); function limitMediaLibraryItems_56456($where, &$wp_query) { global $pagenow, $wpdb; // Do … Read more

Filter media library items by size

So far, the only workable solution I’ve come up with is to run a new query within the ajax_query_attachments_args filter. It’s definitely not ideal but works as expected in the absence of a more efficient alternative: function restrict_media_library_by_width($query) { $include = array(); $exclude = array(); $temp_query = new WP_Query($query); if($temp_query->have_posts()) { while($temp_query->have_posts()) { $temp_query->the_post(); $meta … Read more

What might cause a POST to wp-admin/async-upload.php to return JSON >and< HTML?

I had the same issue and did not find any information in my debug output. It worked out, that DOING_AJAX was not defined (I don’t know why). Changing the beginning of async-upload.php from if ( isset( $_REQUEST[‘action’] ) && ‘upload-attachment’ === $_REQUEST[‘action’] ) { define( ‘DOING_AJAX’, true ); } to define( ‘DOING_AJAX’, true ); worked … Read more

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