_wp_relative_upload_path example

/** * Filters the path to the attached file to update. * * @since 2.1.0 * * @param string $file Path to the attached file to update. * @param int $attachment_id Attachment ID. */
    $file = apply_filters( 'update_attached_file', $file$attachment_id );

    $file = _wp_relative_upload_path( $file );
    if ( $file ) {
        return update_post_meta( $attachment_id, '_wp_attached_file', $file );
    } else {
        return delete_post_meta( $attachment_id, '_wp_attached_file' );
    }
}

/** * Returns relative path to an uploaded file. * * The path is relative to the current upload dir. * * @since 2.9.0 * @access private * * @param string $path Full path to the file. * @return string Relative path on success, unchanged path on failure. */
function _wp_image_meta_replace_original( $saved_data$original_file$image_meta$attachment_id ) {
    $new_file = $saved_data['path'];

    // Update the attached file meta.     update_attached_file( $attachment_id$new_file );

    // Width and height of the new image.     $image_meta['width']  = $saved_data['width'];
    $image_meta['height'] = $saved_data['height'];

    // Make the file path relative to the upload dir.     $image_meta['file'] = _wp_relative_upload_path( $new_file );

    // Add image file size.     $image_meta['filesize'] = wp_filesize( $new_file );

    // Store the original image file name in image_meta.     $image_meta['original_image'] = wp_basename( $original_file );

    return $image_meta;
}

/** * Creates image sub-sizes, adds the new data to the image meta `sizes` array, and updates the image metadata. * * Intended for use after an image is uploaded. Saves/updates the image metadata after each * sub-size is created. If there was an error, it is added to the returned image metadata array. * * @since 5.3.0 * * @param string $file Full path to the image file. * @param int $attachment_id Attachment ID to process. * @return array The image attachment meta data. */
$backup_sizes[ "full-$suffix] = array(
                    'width'  => $meta['width'],
                    'height' => $meta['height'],
                    'file'   => $parts['basename'],
                );
            }
        }

        $restored_file = path_join( $parts['dirname']$data['file'] );
        $restored      = update_attached_file( $post_id$restored_file );

        $meta['file']   = _wp_relative_upload_path( $restored_file );
        $meta['width']  = $data['width'];
        $meta['height'] = $data['height'];
    }

    foreach ( $default_sizes as $default_size ) {
        if ( isset( $backup_sizes[ "$default_size-orig" ] ) ) {
            $data = $backup_sizes[ "$default_size-orig" ];
            if ( isset( $meta['sizes'][ $default_size ] ) && $meta['sizes'][ $default_size ]['file'] != $data['file'] ) {
                if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) {

                    // Delete only if it's an edited image.


        // Reset orientation. At this point the image is edited and orientation is correct.         if ( ! empty( $new_image_meta['image_meta']['orientation'] ) ) {
            $new_image_meta['image_meta']['orientation'] = 1;
        }

        // The attachment_id may change if the site is exported and imported.         $new_image_meta['parent_image'] = array(
            'attachment_id' => $attachment_id,
            // Path to the originally uploaded image file relative to the uploads directory.             'file'          => _wp_relative_upload_path( $image_file ),
        );

        /** * Filters the meta data for the new image created by editing an existing image. * * @since 5.5.0 * * @param array $new_image_meta Meta data for the new image. * @param int $new_attachment_id Attachment post ID for the new image. * @param int $attachment_id Attachment post ID for the edited (parent) image. */
        
Home | Imprint | This part of the site doesn't use cookies.