Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codearachnid/9537604 to your computer and use it in GitHub Desktop.
Save codearachnid/9537604 to your computer and use it in GitHub Desktop.
It seems that with WordPress 3.8.1 or greater has an issue with wp_get_attachment_metadata() it now throws an error (or on some servers no result) when trying to get the details of an attachment which is not an image.
<?php
$attachment_ids = (array) $attachment_ids;
$wp_upload_dir = wp_upload_dir();
$attachments = array();
// THIS WILL NOT WORK > WPv3.8.1
foreach( $attachment_ids as $attachment_id ){
$attachment = wp_get_attachment_metadata( $attachment_id );
if( !empty( $attachment['file'] ) ){
$attachments[] = trailingslashit( $wp_upload_dir['basedir'] ) . $attachment['file'];
}
}
// THIS WORKS
foreach( $attachment_ids as $attachment_id ){
$attachment_url = wp_get_attachment_url( $attachment_id );
if( !empty( $attachment ) ){
$attachments[] = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $attachment_url );
}
}
@derickeppendahl
Copy link

Hi,
I have installed your attachement plugin on my wordpress 3.9 with gravityforms duly registered, and I hope this is the right place to ask my question.

my concern is the following :

I have a form which contains 3 checkboxes.
I want to be able to display, download and email to the user the pdf file(s) corresponding to the checked box(es).
Is there any kind of conditional requests I could use so that i can set it up in the GF confirmation or notification pages ?
Thanks a lot and kind regards...
Derick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment