How to find attachment by it’s name?

You have to write custom code to get the attachment id and post_parent by name/ slug or filename(if it has not been changed during the uploading of files). Put the below code in your theme’s functions.php file if( ! ( function_exists( ‘wp_get_attachment_by_post_name’ ) ) ) { function wp_get_attachment_by_post_name( $post_name ) { $args = array( ‘posts_per_page’ … Read more

Trying to hide buttons from Attachment window

Jose, give this a shot and see if that’s the kind of thing you had in mind.. EDIT: Done a little bit of testing and copying of core code to archieve this, but i think the new example i’ve added below should do what you’ve described, remove the buttons, “Insert into Post”, etc…, but keep … Read more

Are captions stored anywhere?

Yes, it stores the caption in it’s own place in the DB. I can’t quote the exact location but in WordPress, “Attachments” are a post type and it stores each attachment just like a post. For an attachment post type, it treats the Image Caption as the_excerpt the Image Description as the_content and the Image … Read more

Is it possible to Schedule Attachments in WordPress?

My idea is that you can setup a post date for the attachments. This can be done using attachment_fields_to_edit to show the UI (is possible use the touch_time internal function). After that, you can filter all the attachments query to show only the attachments with a past or current date. So add_action(‘load-post.php’, ‘setup_attachment_fields’); function setup_attachment_fields() … Read more

Can I use the wp media uploader for my own plugin?

You can use wp_enqueue_media() in your admin_enqueue_scripts hook. In a javascript file hook it into a button and use insert event to capture the selected image’s details $(‘.media-button’).click(function() { var media_uploader = wp.media({ frame: “post”, text : “Add image”, state: “insert”, multiple: false }); media_uploader.on(“insert”, function(){ var json = media_uploader.state().get(“selection”).first().toJSON(); var image_name = json.filename; var … Read more

Changing attachment urls?

You can do the following: /* add new rewrite rule */ function attachment_rewrite( $wp_rewrite ) { $rule = array( ‘media/(.+)’ => ‘index.php?attachment=” . $wp_rewrite->preg_index(1) ); $wp_rewrite->rules = $rule + $wp_rewrite->rules; } add_filter( “generate_rewrite_rules’, ‘attachment_rewrite’ ); /* redirect standard wordpress attachments urls to new format */ function redirect_old_attachment() { global $wp; if( !preg_match( ‘/^media\/(.*)/’, $wp->request ) … Read more