• Resolved Nate Mackey

    (@mackeyngmailcom)


    We uncovered an issue uploading images after upgrading to WP 3.3. The issue is caused by WP calling wp_update_post twice when saving a post. The first call correctly moves the uploaded file to the permanent location, but during the second call (called via _fix_attachment_links()), the file is not seen as an valid uploaded file (because is_uploaded_file() fails in wp_handle_upload()). Therefore, Verve Meta Boxes removes the meta field as it thinks the user is trying to delete the file.

    Here’s the patch to fix the issue:

    --- verve-meta-boxes.php.original	2011-12-16 07:02:16.000000000 -0800
    +++ verve-meta-boxes.php	2011-12-16 07:04:09.000000000 -0800
    @@ -587,12 +587,14 @@
     				/////////////////// HANDLE FILE UPLOAD and POPULATE VALUE VARIABLE
     				$overrides 	= array('test_form' => false); //WHY DOES THIS NEED TO BE HERE?
     				$image 		= wp_handle_upload($_FILES[$key],$overrides);
    -				$value 		= $image["url"];
    
    -				if( vmb_is_empty($value) ){
    -					delete_post_meta($post_id, $key);
    -				}else{
    -					update_post_meta($post_id, $key, $value);
    +				if (empty($image['error'])) {
    +					$value 		= $image["url"];
    +					if( vmb_is_empty($value) ){
    +						delete_post_meta($post_id, $key);
    +					}else{
    +						update_post_meta($post_id, $key, $value);
    +					}
     				}
     			}
     		}

    https://www.ads-software.com/extend/plugins/verve-meta-boxes/

Viewing 2 replies - 1 through 2 (of 2 total)
  • No luck implementing this solution.

    The following is line 585 to 605 in my verve-meta-boxes.php

    Did I miss something?

    if( isset($_FILES[$key]) && !vmb_is_empty($_FILES[$key]['name']) ){
    
    				/////////////////// HANDLE FILE UPLOAD and POPULATE VALUE VARIABLE
    				$overrides 	= array('test_form' => false); //WHY DOES THIS NEED TO BE HERE?
    				$image 		= wp_handle_upload($_FILES[$key],$overrides);
    				$value 		= $image["url"];
    
    				if( vmb_is_empty($value) ){
    					delete_post_meta($post_id, $key);
    				}else{
    					update_post_meta($post_id, $key, $value);
    					if (empty($image['error'])) {
    						$value = $image["url"];
    						if( vmb_is_empty($value) ){
    							delete_post_meta($post_id, $key);
    						}else{
    							update_post_meta($post_id, $key, $value);
    						}
     					}
    				}
    			}
    Thread Starter Nate Mackey

    (@mackeyngmailcom)

    The code snippet I uploaded is diff or patch. The – and + signs at the front of each line indicate what changed between the original and updated versions. The final code block for uploading files and images should be the following:

    if( $field_type == 'image' || $field_type == 'file' ){
    
                            if( isset($_FILES[$key]) && !vmb_is_empty($_FILES[$key]['name']) ){
    
                                    /////////////////// HANDLE FILE UPLOAD and POPULATE VALUE VARIABLE
                                    $overrides      = array('test_form' => false); //WHY DOES THIS NEED TO BE HERE?
                                    $image          = wp_handle_upload($_FILES[$key],$overrides);
    
                                    if (empty($image['error'])) {
                                            $value          = $image["url"];
                                            if( vmb_is_empty($value) ){
                                                    delete_post_meta($post_id, $key);
                                            }else{
                                                    update_post_meta($post_id, $key, $value);
                                            }
                                    }
                            }
                    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Verve Meta Boxes] Issue uploading images’ is closed to new replies.