• I wrote some functions that strip IPTC metadata from a post thumbnail, then use that metadata to automatically populate the post title, content, and excerpt. It works fine except for the last function, which saves the title, makes the “Use as Featured Image” button disappear when adding an image. If the thumbnail was already added, then all three functions do their jobs perfectly. Removing the photo_auto_title function keeps the “Use as Featured Image” button in tact and the other two functions work perfectly. Any ideas as to why the photo_auto_title function would break the “Use as Featured Image” button?

    add_action('content_save_pre', 'photo_auto_content');
    function photo_auto_content( $content ){
    		global $post_type;
    		if( $post_type == "photos") {
    			$image_id = get_post_thumbnail_id();
    			$irl = wp_get_attachment_image_src($image_id,'full', true);
    			$irl_url = $irl[0];
    			$size = GetImageSize($irl_url,&$info);
    			$iptc = iptcparse($info['APP13']);
    			$keywordcount = count($iptc["2#025"]);
    				for ($i=0; $i<$keywordcount; $i++) $keywords .= $iptc["2#025"][$i] . " ";
    
    				$content = $keywords;
    
    				if ($keywordcount>0) {
    	  				return $content;
    	  			}
    	  	}
    }
    
    add_action('excerpt_save_pre', 'photo_auto_excerpt');
    function photo_auto_excerpt( $excerpt ){
    		global $post_type;
    		if( $post_type == "photos") {
    			$image_id = get_post_thumbnail_id();
    			$irl = wp_get_attachment_image_src($image_id,'full', true);
    			$irl_url = $irl[0];
    			$size = GetImageSize($irl_url,&$info);
    			$iptc = iptcparse($info['APP13']);
    			$captioncount = count($iptc["2#120"]);
    				for ($i=0; $i<$captioncount; $i++) $caption .= $iptc["2#120"][$i] . " ";
    					$excerpt = $caption;
    
    					if ($captioncount>0) {
    	  					return $excerpt;
    	  				}
    	  	}
    }
    
    add_action('title_save_pre', 'photo_auto_title');
    function photo_auto_title( $name ){
    		global $post_type;
    		if( $post_type == "photos") {
    			$image_id = get_post_thumbnail_id();
    			$irl = wp_get_attachment_image_src($image_id,'full', true);
    			$irl_url = $irl[0];
    			$size = GetImageSize($irl_url,&$info);
    			$iptc = iptcparse($info['APP13']);
    			$graphic_name_count = count($iptc["2#005"]);
    				for ($i=0; $i<$graphic_name_count; $i++) $graphic_name .= $iptc["2#005"][$i] . " ";
    					$name = $graphic_name;
    
    					if ($graphic_name_count>0) {
    	  					return $name;
    	  				}
    	  	}
    }

The topic ‘title_save_pre breaking thumbnail function’ is closed to new replies.