• I am using a plugin to extract EXIF image data from images uploaded using a form on my wordpress site. As of now it properly uploads and inserts the image into the media library, but I dont think it is generating any metadata information and updating it. I know this because it used to work with another method I was using, but after I upgraded some plugins, it all stopped working and I can’t seem to fix it… What is wrong below that might not be allowing the metadata info to generate from the uploaded image? I get this error when viewing the attachment page:

    Notice: Undefined variable: metadata in /mnt/soco-app/forms/wp-content/themes/twentytwelve/image.php on line 25

    //Add uploaded image to media library
    add_action("gform_after_submission", "post_submission", 10, 2);
    
    function post_submission($entry) {
    
        if($_FILES['input_5']) {/**TURN WP_DEBUG OFF WHEN FIXED**/
    
            $filename = $entry[5];
            $wp_filetype = wp_check_filetype(basename($filename), null );
            $wp_upload_dir = wp_upload_dir();
            $attachment = array(
                'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
                'post_mime_type' => $wp_filetype['type'],
                'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
                'post_content' => '',
                'post_status' => 'inherit'
            );
    
            $parent_post_id = 9; //ID of Parent Page
    
            $attach_id = wp_insert_attachment( $attachment, $filename, $parent_post_id );
    
            require_once(ABSPATH . 'wp-admin/includes/image.php');
    
            $attach_data = wp_generate_attachment_metadata( $attach_id, $filename   );
    
            //require_once(ABSPATH . 'wp-includes/post.php');
            //update_post_meta( $parent_post_id, '_wp_attachment_metadata', $attach_data );
            wp_update_attachment_metadata( $attach_id,  $attach_data );
        }
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter jflayhart

    (@jflayhart)

    Anyone know what the heck is wrong here because I can’t get anywhere with this even though I feel I’ve done it correctly according to Codex ?? I get all these errors saying missing metadata etc when viewing attachment.

    What’s the website? And do you have an example image that is getting these errors?

    Is the image definitely attached to page ID 9?

    Thread Starter jflayhart

    (@jflayhart)

    Moderator bcworkz

    (@bcworkz)

    The error in the theme has to be a red herring, it makes no sense. I would investigate the $image_meta errors in thesography/exifography.php

    Thread Starter jflayhart

    (@jflayhart)

    the issue is that it USED to work, now it doesn’t ha. It is SO strange….

    I am using the short code from the exifography plugin that kristerella made

    Thread Starter jflayhart

    (@jflayhart)

    So it seemed the issuse, mainly, was gravity forms method of “gform”after”submission” I needed to change it to PRE submission and the following:

    //Add uploaded image to media library
    add_action("gform_pre_submission", "image_submission", 10, 2);//changed from gform_*after*_submission
    
    	function image_submission() {
    
    		if($_FILES['input_5']) {
    
    			$parent_post_id = 9; // change it to your desired post id
    
    			require_once(ABSPATH . 'wp-admin/includes/file.php');
    
    			require_once(ABSPATH . 'wp-admin/includes/image.php');
    
    			require_once(ABSPATH . 'wp-admin/includes/media.php');
    
    			$attach_id = media_handle_upload('input_5', $parent_post_id);
    
    			update_post_meta($parent_post_id,'_thumbnail_id',$attach_id);
    
    		}

    However I am still getting an exifography error and I don’t know what it is and why the location isn’t showing up even though I have it selected to do so.

    Moderator bcworkz

    (@bcworkz)

    Progress at least. Update cycles can be so frustrating when things change unbeknownst to you.

    Sounds like some sort of array indexing isn’t working right anymore. Even though your code worked fine previously, something changed somewhere, but you probably cannot unchange that, rather you need to adapt your code to the new order of things. Perhaps a name collision has cropped up? Or yet another unknown change in method you need to adapt to? Difficult to say.

    Is this still a problem?

    If so please post the Exifography error that you were getting in this thread since the link above is no longer working.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How To Properly Generate and Update Metadata Image Information In WordPress’ is closed to new replies.