HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: //proc/self/cwd/wp-content/plugins/wpml-string-translation/classes/MO/Hooks/PreloadThemeMoFile.php
<?php

namespace WPML\ST\MO\Hooks;

use WPML\Collect\Support\Collection;

class PreloadThemeMoFile implements \IWPML_Action {
	/** @var \SitePress */
	private $sitepress;

	/** @var \wpdb */
	private $wpdb;

	public function __construct( \SitePress $sitepress, \wpdb $wpdb ) {
		$this->sitepress = $sitepress;
		$this->wpdb      = $wpdb;
	}


	public function add_hooks() {
		$domains = $this->sitepress->get_setting( 'gettext_theme_domain_name' );
		$domains = \wpml_collect( array_map( 'trim', explode( ',', $domains ) ) );

		if ( (bool) $this->sitepress->get_setting( 'theme_localization_load_textdomain' ) && $domains->count() ) {

			\wpml_collect( $domains )->each( function ( $domain ) {
				$this->getListOfFiles( $domain, get_locale() )->map( function ( $file ) use ( $domain ) {
					load_textdomain( $domain, $file );
				} );
			} );
		}
	}

	/**
	 * @param string $domain
	 * @param string $locale
	 *
	 * @return Collection
	 */
	private function getListOfFiles( $domain, $locale ) {
		$sql = "
			SELECT file_path
			FROM {$this->wpdb->prefix}icl_mo_files_domains
			WHERE domain = %s and file_path LIKE %s
		";

		$sql = $this->wpdb->prepare( $sql, $domain, '%' . $locale . '%' );

		return \wpml_collect( $this->wpdb->get_row( $sql ) );
	}
}