L ShS@LH@LX S8 S+SfqP SSBp SLppSAL0AL+SxPS SBSLSBLBL+S(SSBSLh)(SCLCLSHS+S`SSBSLS SpDLCLhSS+SSSBpSL SXELDL0S!S+S0!ShSS #SL#SLP$SLh`&S&SL8&S 'SL'S'SL(S(SL)S)SLX*S*SLmOSELoOSoOSELFL8FL`FLFLBpSL SXELpGL0S!S+S0!ShSmOSPLoOSoOSELFL8FL`FLFLLLL(LR|TV LEgLEgLHEgLEgL81O 1O SL2 @L0IL,L::@wzTV}=N ! LSLL@S7SyNIL SKL KLHsLShS@S+3xS SSLBPNIL S8X SLLLL0 S S@S:A S SH NIL7L@(SxMLLLPS@SIWSH SBXSILhSS`NLMLS@S^`SxSBSIL?LSHSHOLNLhSSXS@SiuSSBNIL#S8 S0PLOLp$S@S|$SS = \WP_CLI\Utils\make_progress_bar( __( 'Bulk Optimization', 'webp-converter-for-media' ), $count ); $size_before = 0; $size_after = 0; $files_all = 0; $files_converted = 0; foreach ( $paths_chunks as $chunk_data ) { foreach ( $chunk_data['files'] as $images_paths ) { $response = $conversion_method->init_conversion( $this->parse_files_paths( $images_paths, $chunk_data['path'] ), $force_flag, true ); if ( $response !== null ) { foreach ( $response['errors'] as $error_message ) { if ( ! $response['is_fatal_error'] ) { \WP_CLI::warning( $error_message ); } else { \WP_CLI::error( $error_message ); } } if ( $response['is_fatal_error'] ) { return; } $size_before = $response['size']['before']; $size_after = $response['size']['after']; $files_all = $response['files']['webp_available'] + $response['files']['avif_available']; $files_converted = $response['files']['webp_converted'] + $response['files']['avif_converted']; } $progress->tick(); } } $progress->finish(); \WP_CLI::success( __( 'The process was completed successfully. Your images have been converted!', 'webp-converter-for-media' ) ); if ( $size_before > $size_after ) { \WP_CLI::log( sprintf( /* translators: %s progress value */ __( 'Saving the weight of your images: %s', 'webp-converter-for-media' ), $this->format_bytes( $size_before - $size_after ) ) ); } \WP_CLI::log( sprintf( /* translators: %s images count */ __( 'Successfully converted files: %s', 'webp-converter-for-media' ), $files_converted ) ); \WP_CLI::log( sprintf( /* translators: %s images count */ __( 'Failed or skipped file conversion attempts: %s', 'webp-converter-for-media' ), ( $files_all - $files_converted ) ) ); } /** * @param string[] $paths . * @param string $path_prefix . * * @return string[] */ private function parse_files_paths( array $paths, string $path_prefix ): array { $items = []; foreach ( $paths as $path ) { $items[] = $path_prefix . '/' . $path; } return $items; } private function format_bytes( int $size ): string { $suffixes = [ 'B', 'KB', 'MB', 'GB' ]; $base = floor( log( $size ) / log( 1024 ) ); return sprintf( '%.2f ' . $suffixes[ $base ], ( $size / pow( 1024, floor( $base ) ) ) ); } }