• Resolved Pratham

    (@pratham2003)


    We have many such filters as follows that classify files into their own unique directories based on filename patterns.

    add_filter('wp_handle_upload_prefilter', 'icons_upload_filter' );
    
    function icons_upload_filter( $file ){
    		$is_icon = stripos($file['name'], 'icon-');
    		if( $is_icon !== false ){
    			add_filter('upload_dir', 'icons_post_upload_dir');
    		}
    
        return $file;
    }
    
    function icons_post_upload_dir($path){
    	$custom_dir = '/icons';
    	$path['path']    = str_replace($path['subdir'], '', $path['path']); //remove default subdir (year/month)
    	$path['url']     = str_replace($path['subdir'], '', $path['url']);
    	$path['subdir']  = $custom_dir;
    	$path['path']   .= $custom_dir;
    	$path['url']    .= $custom_dir;
    	return $path;
    }

    The issue is that when W3TC tries to sync files to S3 it uses the wrong path and we end up seeing the following error.
    wp-content/uploads/icon-ad1.png Source file not found.

    But when I check the path of the file in wp_posts or wp_postmeta we see the corrent URL.
    Screenshots:

    View post on imgur.com

    View post on imgur.com

    Is there a filter in W3TC we can use to correct the path while uploading to S3?

    • This topic was modified 7 years, 8 months ago by Pratham.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello,

    W3 Total Cache has a way to control paths it uses for uploaded files.
    $files = apply_filters( 'w3tc_cdn_update_attachment', $files );
    Your code modifies wp behavior but written such a way that it doesn’t modify W3 Total Cache upload logic.

    Thread Starter Pratham

    (@pratham2003)

    Thanks!

    I had assumed W3TC would use the paths found in wp_posts / wp_postmeta tables.

    I’ll try this filter out.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Bug: CDN S3 Sync’ is closed to new replies.