Webp and CDN support
-
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)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Webp and CDN support’ is closed to new replies.