Is there a user-facing interface to edit an attachment’s permalink?

This’ll add a slug field to the edit attachment page, which’ll allow you to independently change it when and how you choose to. Drop it into a plugin or your theme’s functions.php; function wpse_12405_edit_attachment_name( $fields, $post ) { $fields[‘post_name’] = array( ‘label’ => __( ‘Slug’ ), ‘value’ => $post->post_name, ); return $fields; } add_filter( ‘attachment_fields_to_edit’, … Read more

get_attached_media() returns empty array if media file already used by another post

I ran into this problem and ended up creating a basic function to extract the “attached” media by URL from the body of the post (in my case a post of type document, but it should work with any kind of post): function get_first_link_url($post_id) { $content = get_post_field(‘post_content’, $post_id); if ($content == null) { return … Read more

What’s the easiest way to close comments on media/attachments?

This ought to do it: function wpse15750_comment_check( $id ){ if( get_post_type( $id ) == ‘attachment’ ) exit; } add_action( ‘pre_comment_on_post’, ‘wpse15750_comment_check’ ); EDIT Ignore the above. That will stop new comments, but to do what you want, this is much better: function wpse15750_comments_closed( $open, $id ){ if( get_post_type( $id ) == ‘attachment’ ) return false; … Read more

wp_generate_attachment_metadata returns empty array

I believe the following is happening here: As @Luke pointed out, wp_insert_attachment() takes an array of post data. The format of the array you are passing to it is not correct. The keys are different. What should be stored as the post_mime_type, is being passed with the key type. Because of this, no mime type … Read more