update_attached_file example


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 );

    

            } elseif ( isset( $meta['width']$meta['height'] ) ) {
                $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 ) {

                    
$wpdb->posts,
                array(
                    'post_status'    => 'attachment',
                    'post_mime_type' => $object->post_type,
                    'post_type'      => '',
                ),
                array( 'ID' => $object->ID )
            );

            $meta = get_post_meta( $object->ID, 'imagedata', true );
            if ( ! empty( $meta['file'] ) ) {
                update_attached_file( $object->ID, $meta['file'] );
            }
        }
    }
}

/** * Execute changes made in WordPress 2.1. * * @ignore * @since 2.1.0 * * @global int $wp_current_db_version The old (current) database version. * @global wpdb $wpdb WordPress database abstraction object. */


    $current_guid = get_post_field( 'guid', $post_id );

    // Set GUID.     if ( ! $update && '' === $current_guid ) {
        $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post_id ) )$where );
    }

    if ( 'attachment' === $postarr['post_type'] ) {
        if ( ! empty( $postarr['file'] ) ) {
            update_attached_file( $post_id$postarr['file'] );
        }

        if ( ! empty( $postarr['context'] ) ) {
            add_post_meta( $post_id, '_wp_attachment_context', $postarr['context'], true );
        }
    }

    // Set or remove featured image.     if ( isset( $postarr['_thumbnail_id'] ) ) {
        $thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;

        
Home | Imprint | This part of the site doesn't use cookies.