: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
/** @var WP_Filesystem_Direct */
* @param icl_cache $cache
* @param WP_Filesystem_Direct $filesystem
public function __construct( $wpdb, icl_cache $cache, WP_Filesystem_Direct $filesystem ) {
$this->filesystem = $filesystem;
public function get_flag( $lang_code ) {
$flag = $this->cache->get( $lang_code );
$flag = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT flag, from_template
FROM {$this->wpdb->prefix}icl_flags
WHERE lang_code=%s", $lang_code ) );
$this->cache->set( $lang_code, $flag );
public function get_flag_url( $lang_code ) {
$flag = $this->get_flag( $lang_code );
if ( $flag->from_template ) {
$wp_upload_dir = wp_upload_dir();
$base_url = $wp_upload_dir['baseurl'];
$base_url = $this->get_wpml_flags_url();
return $this->append_path_to_url( $base_url, $path );
public function clear() {
* @param array $allowed_file_types
public function get_wpml_flags( $allowed_file_types = null ) {
if ( null === $allowed_file_types ) {
$allowed_file_types = array( 'gif', 'jpeg', 'png', 'svg' );
$files = array_keys( $this->filesystem->dirlist( $this->get_wpml_flags_directory(), false ) );
$result = $this->filter_flag_files( $allowed_file_types, $files );
public final function get_wpml_flags_directory() {
return WPML_PLUGIN_PATH . '/res/flags/';
public final function get_wpml_flags_url() {
return ICL_PLUGIN_URL . '/res/flags/';
* @param array $allowed_file_types
private function filter_flag_files( $allowed_file_types, $files ) {
foreach ( $files as $file ) {
$path = $this->get_wpml_flags_directory() . $file;
if ( $this->filesystem->exists( $path ) ) {
$ext = pathinfo( $path, PATHINFO_EXTENSION );
if ( in_array( $ext, $allowed_file_types, true ) ) {
private function append_path_to_url( $base_url, $path ) {
$base_url_parts = wp_parse_url( $base_url );
$base_url_path_components = array();
if ( array_key_exists( 'path', $base_url_parts ) ) {
$base_url_path_components = explode( '/', untrailingslashit( $base_url_parts['path'] ) );
$sub_dir_path_components = explode( '/', trim( $path, '/' ) );
foreach ( $sub_dir_path_components as $sub_dir_path_part ) {
$base_url_path_components[] = $sub_dir_path_part;
$base_url_parts['path'] = implode( '/', $base_url_path_components );
return http_build_url( $base_url_parts );