function mbdb_update_images($new_images, $options_name) { $mbdb_options = get_option('mbdb_options'); $options = $mbdb_options[$options_name]; foreach ($new_images as $image) { // find the retailer that matches the uniqueID for ($x = 0; $x < count($options); $x++) { if ($options[$x]['uniqueID'] == $image['uniqueID']) { // save the original attachID $old_attachID = $options[$x]['imageID']; // delete the original image wp_delete_attachment($old_attachID, true); // upload the new image $new_attachID = mbdb_upload_image($image['image']); if ($new_attachID != 0) { // if the upload succeeded // update the attach id $options[$x]['imageID'] = $new_attachID; // update the image $img = wp_get_attachment_url($new_attachID); $options[$x]['image'] = $img; } else { // error message? } // item has been found, break out of loop break; } } } $mbdb_options[$options_name] = $options; // update the options with the new retailers update_option('mbdb_options', $mbdb_options); }
function mbdb_insert_image($key, $file, &$mbdb_options) { // check if the coming soon image exists and add it if necessary if (!array_key_exists($key, $mbdb_options)) { $attachID = mbdb_upload_image($file); $mbdb_options[$key . '-id'] = $attachID; if ($attachID != 0) { $img = wp_get_attachment_url($attachID); $mbdb_options[$key] = $img; } else { $mbdb_options[$key] = ''; } } }