TestTimberImage::replace_image PHP Method

replace_image() static public method

* ---------------- Helper functions ----------------
static public replace_image ( $old_id, $new_id )
    static function replace_image($old_id, $new_id)
    {
        $uploadDir = wp_upload_dir();
        $newFile = $uploadDir['basedir'] . '/' . get_post_meta($new_id, '_wp_attached_file', true);
        $oldFile = $uploadDir['basedir'] . '/' . get_post_meta($old_id, '_wp_attached_file', true);
        if (!file_exists(dirname($oldFile))) {
            mkdir(dirname($oldFile), 0777, true);
        }
        copy($newFile, $oldFile);
        $meta = wp_generate_attachment_metadata($old_id, $oldFile);
        wp_update_attachment_metadata($old_id, $meta);
        wp_delete_post($new_id, true);
    }