HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/delta/wp-content/plugins/wpml-string-translation/classes/shortcode/Hooks.php
<?php

namespace WPML\ST\Shortcode;

use WPML\FP\Fns;
use WPML\FP\Obj;
use function WPML\FP\curryN;
use function WPML\FP\invoke;
use function WPML\FP\partial;

class Hooks implements \IWPML_DIC_Action, \IWPML_Backend_Action, \IWPML_AJAX_Action, \IWPML_REST_Action {
	/** @var \WPML_ST_DB_Mappers_Strings */
	private $stringMapper;

	public function __construct( \WPML_ST_DB_Mappers_Strings $stringMapper ) {
		$this->stringMapper = $stringMapper;
	}


	public function add_hooks() {
		/**
		 * @see \WPML\ST\Shortcode\TranslationHandler::appendId
		 */
		add_filter( 'wpml_tm_xliff_unit_field_data', $this->appendId() );

		$this->defineRetrievingATEJobHooks();
		$this->defineRetrievingProxyJobHooks();
		$this->defineCTEHooks();
	}

	private function defineRetrievingATEJobHooks() {
		$lens = LensFactory::createLensForJobData();

		/**
		 * @see \WPML\ST\Shortcode\TranslationHandler::restoreOriginalShortcodes
		 */
		add_filter( 'wpml_tm_ate_job_data_from_xliff', TranslationHandler::registerStringTranslation( $lens ), 9, 2 );

		/**
		 * @see \WPML\ST\Shortcode\TranslationHandler::restoreOriginalShortcodes
		 */
		add_filter( 'wpml_tm_ate_job_data_from_xliff', $this->restoreOriginalShortcodes( $lens ), 10, 1 );
	}

	private function defineRetrievingProxyJobHooks() {
		$lens = LensFactory::createLensForProxyTranslations();

		$registerStringTranslation = $this->registerStringTranslation( $lens, invoke( 'get_target_language' ) );

		/**
		 * @see \WPML\ST\Shortcode\TranslationHandler::restoreOriginalShortcodes
		 */
		add_filter( 'wpml_tm_proxy_translations', $registerStringTranslation, 9, 1 );

		/**
		 * @see \WPML\ST\Shortcode\TranslationHandler::restoreOriginalShortcodes
		 */
		add_filter( 'wpml_tm_proxy_translations', $this->restoreOriginalShortcodes( $lens ), 10, 1 );
	}

	private function defineCTEHooks() {
		$appendStringIdToFieldsData = Obj::over(
			LensFactory::createLensForAssignIdInCTE(),
			Fns::map( $this->appendId() )
		);

		add_filter( 'wpml_tm_adjust_translation_fields', $appendStringIdToFieldsData, 10, 1 );

		$lens = LensFactory::createLensForJobData();

		$registerStringTranslation = $this->registerStringTranslation( $lens, Obj::prop( 'target_lang' ) );

		/**
		 * @see \WPML\ST\Shortcode\TranslationHandler::restoreOriginalShortcodes
		 */
		add_filter( 'wpml_translation_editor_save_job_data', $registerStringTranslation, 9, 1 );

		/**
		 * @see \WPML\ST\Shortcode\TranslationHandler::restoreOriginalShortcodes
		 */
		add_filter( 'wpml_translation_editor_save_job_data', $this->restoreOriginalShortcodes( $lens ), 10, 1 );
	}

	/**
	 * @return callable
	 */
	private function appendId() {
		return TranslationHandler::appendId( [ $this->stringMapper, 'getByDomainAndValue' ] );
	}

	private function restoreOriginalShortcodes( callable $lens ) {
		return TranslationHandler::restoreOriginalShortcodes( [ $this->stringMapper, 'getById' ], $lens );
	}

	private function registerStringTranslation( callable $lens, callable $getTargetLang ) {
		return TranslationHandler::registerStringTranslation( $lens, Fns::__, $getTargetLang );
	}
}