_copy_image_file

The timeline below displays how wordpress function _copy_image_file has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Copies an existing image file.
 *
 * @since 3.4.0
 * @access private
 *
 * @param int $attachment_id Attachment ID.
 * @return string|false New file path on success, false on failure.
 */
function _copy_image_file($attachment_id)
{
    $dst_file = get_attached_file($attachment_id);
    $src_file = $dst_file;
    if (!file_exists($src_file)) {
        $src_file = _load_image_to_edit_path($attachment_id);
    }
    if ($src_file) {
        $dst_file = str_replace(wp_basename($dst_file), 'copy-' . wp_basename($dst_file), $dst_file);
        $dst_file = dirname($dst_file) . '/' . wp_unique_filename(dirname($dst_file), wp_basename($dst_file));
        /*
         * The directory containing the original file may no longer
         * exist when using a replication plugin.
         */
        wp_mkdir_p(dirname($dst_file));
        if (!copy($src_file, $dst_file)) {
            $dst_file = false;
        }
    } else {
        $dst_file = false;
    }
    return $dst_file;
}

WordPress Version: 5.6

/**
 * Copy an existing image file.
 *
 * @since 3.4.0
 * @access private
 *
 * @param int $attachment_id Attachment ID.
 * @return string|false New file path on success, false on failure.
 */
function _copy_image_file($attachment_id)
{
    $dst_file = get_attached_file($attachment_id);
    $src_file = $dst_file;
    if (!file_exists($src_file)) {
        $src_file = _load_image_to_edit_path($attachment_id);
    }
    if ($src_file) {
        $dst_file = str_replace(wp_basename($dst_file), 'copy-' . wp_basename($dst_file), $dst_file);
        $dst_file = dirname($dst_file) . '/' . wp_unique_filename(dirname($dst_file), wp_basename($dst_file));
        /*
         * The directory containing the original file may no longer
         * exist when using a replication plugin.
         */
        wp_mkdir_p(dirname($dst_file));
        if (!copy($src_file, $dst_file)) {
            $dst_file = false;
        }
    } else {
        $dst_file = false;
    }
    return $dst_file;
}

WordPress Version: 5.3

/**
 * Copy an existing image file.
 *
 * @since 3.4.0
 * @access private
 *
 * @param string $attachment_id Attachment ID.
 * @return string|false New file path on success, false on failure.
 */
function _copy_image_file($attachment_id)
{
    $dst_file = get_attached_file($attachment_id);
    $src_file = $dst_file;
    if (!file_exists($src_file)) {
        $src_file = _load_image_to_edit_path($attachment_id);
    }
    if ($src_file) {
        $dst_file = str_replace(wp_basename($dst_file), 'copy-' . wp_basename($dst_file), $dst_file);
        $dst_file = dirname($dst_file) . '/' . wp_unique_filename(dirname($dst_file), wp_basename($dst_file));
        /*
         * The directory containing the original file may no longer
         * exist when using a replication plugin.
         */
        wp_mkdir_p(dirname($dst_file));
        if (!copy($src_file, $dst_file)) {
            $dst_file = false;
        }
    } else {
        $dst_file = false;
    }
    return $dst_file;
}

WordPress Version: 5.2

/**
 * Copy an existing image file.
 *
 * @since 3.4.0
 * @access private
 *
 * @param string $attachment_id Attachment ID.
 * @return string|false New file path on success, false on failure.
 */
function _copy_image_file($attachment_id)
{
    $dst_file = $src_file = get_attached_file($attachment_id);
    if (!file_exists($src_file)) {
        $src_file = _load_image_to_edit_path($attachment_id);
    }
    if ($src_file) {
        $dst_file = str_replace(wp_basename($dst_file), 'copy-' . wp_basename($dst_file), $dst_file);
        $dst_file = dirname($dst_file) . '/' . wp_unique_filename(dirname($dst_file), wp_basename($dst_file));
        /*
         * The directory containing the original file may no longer
         * exist when using a replication plugin.
         */
        wp_mkdir_p(dirname($dst_file));
        if (!@copy($src_file, $dst_file)) {
            $dst_file = false;
        }
    } else {
        $dst_file = false;
    }
    return $dst_file;
}

WordPress Version: 4.0

/**
 * Copy an existing image file.
 *
 * @since 3.4.0
 * @access private
 *
 * @param string $attachment_id Attachment ID.
 * @return string|false New file path on success, false on failure.
 */
function _copy_image_file($attachment_id)
{
    $dst_file = $src_file = get_attached_file($attachment_id);
    if (!file_exists($src_file)) {
        $src_file = _load_image_to_edit_path($attachment_id);
    }
    if ($src_file) {
        $dst_file = str_replace(basename($dst_file), 'copy-' . basename($dst_file), $dst_file);
        $dst_file = dirname($dst_file) . '/' . wp_unique_filename(dirname($dst_file), basename($dst_file));
        /*
         * The directory containing the original file may no longer
         * exist when using a replication plugin.
         */
        wp_mkdir_p(dirname($dst_file));
        if (!@copy($src_file, $dst_file)) {
            $dst_file = false;
        }
    } else {
        $dst_file = false;
    }
    return $dst_file;
}

WordPress Version: 3.7

/**
 * Copy an existing image file.
 *
 * @since 3.4.0
 * @access private
 *
 * @param string $attachment_id Attachment ID.
 * @return string|false New file path on success, false on failure.
 */
function _copy_image_file($attachment_id)
{
    $dst_file = $src_file = get_attached_file($attachment_id);
    if (!file_exists($src_file)) {
        $src_file = _load_image_to_edit_path($attachment_id);
    }
    if ($src_file) {
        $dst_file = str_replace(basename($dst_file), 'copy-' . basename($dst_file), $dst_file);
        $dst_file = dirname($dst_file) . '/' . wp_unique_filename(dirname($dst_file), basename($dst_file));
        // The directory containing the original file may no longer exist when
        // using a replication plugin.
        wp_mkdir_p(dirname($dst_file));
        if (!@copy($src_file, $dst_file)) {
            $dst_file = false;
        }
    } else {
        $dst_file = false;
    }
    return $dst_file;
}