| Server IP : 85.155.190.233 / Your IP : 216.73.216.103 Web Server : nginx/1.24.0 System : Linux antigravity-cli 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64 User : wp-moonbloom ( 1001) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/moonbloom/wp-content/plugins/webp-converter-for-media/src/Action/ |
Upload File : |
<?php
namespace WebpConverter\Action;
use WebpConverter\Conversion\Method\MethodFactory;
use WebpConverter\Conversion\Method\MethodIntegrator;
use WebpConverter\HookableInterface;
use WebpConverter\PluginData;
/**
* Initializes conversion of all images in list of paths.
*/
class ConvertPathsAction implements HookableInterface {
private PluginData $plugin_data;
private MethodFactory $method_factory;
public function __construct( PluginData $plugin_data, MethodFactory $method_factory ) {
$this->plugin_data = $plugin_data;
$this->method_factory = $method_factory;
}
/**
* {@inheritdoc}
*/
public function init_hooks(): void {
add_action( 'webpc_convert_paths', [ $this, 'convert_files_by_paths' ], 10, 3 );
}
/**
* Converts all given images to output formats.
*
* @param string[] $paths Server paths of images.
* @param bool $regenerate_force .
* @param int|null $quality_level .
*
* @internal
*/
public function convert_files_by_paths( array $paths, bool $regenerate_force = false, ?int $quality_level = null ): void {
( new MethodIntegrator( $this->plugin_data, $this->method_factory ) )
->init_conversion(
$this->remove_paths_from_excluded_paths( $paths ),
$regenerate_force,
$quality_level,
true
);
}
/**
* Removes paths of source images from excluded paths.
*
* @param string[] $source_paths Server paths of images.
*
* @return string[]
*/
private function remove_paths_from_excluded_paths( array $source_paths ): array {
foreach ( $source_paths as $path_index => $path ) {
if ( ! apply_filters( 'webpc_supported_source_file', true, basename( $path ), $path ) ) {
unset( $source_paths[ $path_index ] );
}
}
return $source_paths;
}
}