• I’m trying to replace a bad file because I believe the filename may have screwed some things up. Trying a straight replace gave me this error – which I’m not surprised because only one size has ever shown. Without looking too deep I just wanted to bring this to your attention.

    Backtrace from warning 'Invalid argument supplied for foreach()' at /html/mydomain.com/www/wp-content/plugins/enable-media-replace/upload.php 40:
    
    /html/mydomain.com/www/wp-content/plugins/enable-media-replace/upload.php 99 calling emr_delete_current_files()
    /html/mydomain.com/www/wp-content/plugins/enable-media-replace/enable-media-replace.php 88 calling require_once()
    calling emr_options()
    /html/mydomain.com/www/wp-includes/plugin.php 496 calling call_user_func_array()
    /html/mydomain.com/www/wp-admin/admin.php 212 calling do_action()
    /html/mydomain.com/www/wp-admin/upload.php 10 calling require_once()
    Backtrace from warning 'Cannot modify header information - headers already sent' at /html/mydomain.com/www/wp-includes/pluggable.php 1178:
    
    /html/mydomain.com/www/wp-includes/pluggable.php 1178 calling header()
    /html/mydomain.com/www/wp-content/plugins/enable-media-replace/upload.php 203 calling wp_redirect()
    /html/mydomain.com/www/wp-content/plugins/enable-media-replace/enable-media-replace.php 88 calling require_once()
    calling emr_options()
    /html/mydomain.com/www/wp-includes/plugin.php 496 calling call_user_func_array()
    /html/mydomain.com/www/wp-admin/admin.php 212 calling do_action()
    /html/mydomain.com/www/wp-admin/upload.php 10 calling require_once()

    https://www.ads-software.com/plugins/enable-media-replace/

Viewing 1 replies (of 1 total)
  • Thread Starter Jesse Graupmann

    (@jgraup)

    It looks like if you just do some null checks, you’ll be fine. I had an error where items did not correctly generate their size links and running replace would crash. Please add some checks to see if you can loop and it’ll fix the issue.

    Thanks.

    // Delete old resized versions if this was an image
    $suffix = substr($current_file, (strlen($current_file)-4));
    $prefix = substr($current_file, 0, (strlen($current_file)-4));
    $imgAr = array(".png", ".gif", ".jpg");
    if (in_array($suffix, $imgAr)) {
    	// It's a png/gif/jpg based on file name
    	// Get thumbnail filenames from metadata
    	$metadata = wp_get_attachment_metadata($_POST["ID"]);
    	if (is_array($metadata) && isset($metadata["sizes"]) && is_array($metadata["sizes"])) { // Added fix for error messages when there is no metadata (but WHY would there not be? I don't know…
    		foreach($metadata["sizes"] AS $thissize) {
    			if(!is_array($thissize))continue;
    			// Get all filenames and do an unlink() on each one;
    			$thisfile = $thissize["file"];
    			// Create array with all old sizes for replacing in posts later
    			$oldfilesAr[] = $thisfile;
    			// Look for files and delete them
    			if (strlen($thisfile)) {
    				$thisfile = $current_path . "/" . $thissize["file"];
    				if (file_exists($thisfile)) {
    					unlink($thisfile);
    				}
    			}
    		}
    	}
    	// Old (brutal) method, left here for now
    	//$mask = $prefix . "-*x*" . $suffix;
    	//array_map( "unlink", glob( $mask ) );
    }
Viewing 1 replies (of 1 total)
  • The topic ‘'Invalid argument supplied for foreach()'’ is closed to new replies.