• Resolved alanmj

    (@alanmj)


    Hi I need to upload webp images created from EWWW image optimizer plugin to amazon s3 cdn.Currenly cdn has been set on w3total cache but it’s not uploading webp images to cdn. How can I upload custom files in w3 total cache need the code or hook to integrate.

    https://www.ads-software.com/support/topic/webp-and-cdn-support/ – Can’t find a solution to fix this issue for me

    /**
    	 * Upload assets to CDN
    	 *
    	 * @param array   $args
    	 */
    	function export_cdn_assets( $args = array() ) {
    		try {
    			$w3_plugin_cdn = Dispatcher::component( 'Cdn_Plugin' );
    			$common = Dispatcher::component( 'Cdn_Core' );
    				
    			if( $args ) {
    				switch( $args[0] ) {
    					case 'includes':
    						$files = $w3_plugin_cdn->get_files_includes();
    						break;
    					case 'theme':
    						$files = $w3_plugin_cdn->get_files_theme();
    						break;
    					case 'minify':
    						$files = $w3_plugin_cdn->get_files_minify();
    						break;
    					default:
    					case 'custom':
    						$files = $w3_plugin_cdn->get_files_custom();
    						break;
    				}	
    			} else {
    				\WP_CLI::log( 'Please select one of the groups of assets to upload: \'includes\', \'theme\', \'minify\' or \'custom\' ');
    				exit;
    			}
    			
    			$upload = array();
    			$results = array();
    
    			foreach ( $files as $file ) {
    				$local_path = $common->docroot_filename_to_absolute_path( $file );
    				$remote_path = $common->uri_to_cdn_uri( $common->docroot_filename_to_uri( $file ) );
    				$d = $common->build_file_descriptor( $local_path, $remote_path );
    				$d['_original_id'] = $file;
    				$upload[] = $d;
    			}
    
    			$common->upload( $upload, false, $results, time() + 5 );
    
    			foreach ($results as $result) {
    				\WP_CLI::log( sprintf( 'File: %s => %s', $result['local_path'], $result['error'] ) );	
    			}
    
    		} catch( \Exception $e ) {
    			\WP_CLI::error( __( 'Export CDN assets did failed: %s',
    				'w3-total-cache' ), $e );
    		}
    	}

    How to use this code in my custom theme

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @alanmj

    Thank you for reaching out and I am happy to help.
    YOu should try adding *.webp to
    wp-includes file types to upload:
    Theme file types to upload:
    File types to import:
    At this point this only can be done manually so you can also try adding the files to the Custom file list:
    and if on the CDN push, click the upload custom files and add the files manually.
    Thanks!

    Thread Starter alanmj

    (@alanmj)

    Is there any way or code in w3 total cache to automatically upload custom files to CDN?

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @alanmj

    Not at the moment no. Since you are using the CDN push, some files need to be uploaded manually and in this case, the webp files.
    Thanks!

    Thread Starter alanmj

    (@alanmj)

    Can you please give me custom file upload the hook or filter?

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @alanmj

    THere is a filter in /wp-content/plugins/w3-total-cache/Cdn_Core_Admin.php#L251
    $post_files = apply_filters( 'w3tc_cdn_add_attachment', $post_files );
    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Webp and CDN support’ is closed to new replies.