PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Needing To Attach Unique Post ID To Uploaded Image and Add to Media Library

  1. My clients are taking pictures on their mobile devices and submitting them to my site via gravity forms, but I need to be able to grab the EXIF data from images to get the GPS coords from the image data...

    I am using http://wordpress.org/plugins/thesography/ and it works using its shortcode only on images uploaded to the media library by taking its post id and spitting out all the EXIF data of that attachment's post id. I want to hack this plugin and make it work with a Gform hook or something or else make Gforms add the uploaded image automatically to the Media Library upon form submission, so that I can just use the other plugin's shortcode data to take over from there as Gravity Forms assigns a post id to that newly added Media attachment. What's the best way to go about this?

    Posted 6 years ago on Friday May 24, 2013 | Permalink
  2. Here is a snippet of code from the EXIF plugin:

    //render shortcode
    		function shortcode($atts, $content = null) {
    			global $post;
    			$post_options = get_post_meta($post->ID, '_use_exif', true);
    			if ($post_options)
    				$post_options = $post_options;
    			else
    				$post_options = "all";
    
    			extract(shortcode_atts(array(
    				'show' => $post_options,
    				'id' => '',
    			), $atts));
    
    			$images = get_children(array(
    				'post_parent' => $post->ID,
    				'post_type' => 'attachment',
    				'numberposts' => 1,
    				'post_mime_type' => 'image',
    				'orderby' => 'ID',
    				'order' => 'ASC'
    				));
    			if ($images) {
    				foreach ($images as $image) {
    					$imageID = $image->ID;
    				}
    			}
    
    			if ($id == '')
    				$imgID = $imageID;
    			else
    				$imgID = $id;
    
    			$display = $show;
    
    			return $this->display_exif($display,$imgID);
    		}
    
    		//auto insert
    		function auto_insert($content) {
    			$options = $this->get_options();
    			if (isset($options['auto_insert']) && (!is_page()))
    				return $content . $this->display_exif();
    			else
    				return $content;
    		}
    Posted 6 years ago on Monday May 27, 2013 | Permalink
  3. David Peralty
    Administrator

    Yea, so you would have to combine that with our gform_after_submission hook, and have fields already available (hidden fields?) to take the data. http://www.gravityhelp.com/documentation/page/Gform_after_submission

    Posted 6 years ago on Monday May 27, 2013 | Permalink
  4. In addition to this topic, I replied to the priority support request which was submitted. I will leave this open though since there is good information here.

    Posted 6 years ago on Tuesday May 28, 2013 | Permalink
  5. David, could you elaborate exactly how that works? I've been reading up on it and know that's what I need, just not sure about the "how." Also, how do I check priority support messages?

    Posted 6 years ago on Wednesday May 29, 2013 | Permalink
  6. So here's my updated code that seems to be working, but then the thumbnail isn't showing up in media library and then the link is created as a a href to the image instead of the image itself showing when viewing the attachment page:

    //Add upload field images to media library
    add_action("gform_after_submission", "set_post_content", 10, 2);
    	function set_post_content($entry, $form){
    
    	    if($_FILES['input_5']) {
    
    			require_once(ABSPATH . 'wp-admin/includes/file.php');
    
    			require_once(ABSPATH . 'wp-admin/includes/image.php');
    
    			require_once(ABSPATH . 'wp-admin/includes/media.php');
    
    			$filename = $entry[5];
    
    			$attachment = array(
    				'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
    				'post_mime_type' => $wp_filetype['type'],
    				'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
    			);
    
    			$attach_id = wp_insert_attachment($attachment, $filename);;
    
    			$attach_data = wp_generate_attachment_metadata($attach_id, $filename);
    
    			wp_update_attachment_metadata($attach_id, $attach_data);
    		}
    }
    Posted 6 years ago on Wednesday May 29, 2013 | Permalink

This topic has been resolved and has been closed to new replies.