HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/www/wp-content/plugins/acfml/classes/strategy/repeater-sync/CheckboxHooks.php
<?php

namespace ACFML\Repeater\Sync;

use ACFML\Repeater\Shuffle\Strategy;
use WPML\LIB\WP\Hooks;
use function WPML\FP\spreadArgs;

class CheckboxHooks implements \IWPML_Backend_Action {

	const STORE_SYNC_OPTION_PRIORITY = 4;

	/**
	 * @var Strategy
	 */
	private $shuffled;

	/**
	 * @param Strategy $shuffled
	 */
	public function __construct( Strategy $shuffled ) {
		$this->shuffled = $shuffled;
	}

	/**
	 * @return void
	 */
	public function add_hooks() {
		Hooks::onAction( 'acf/save_post', self::STORE_SYNC_OPTION_PRIORITY )
			->then( spreadArgs( [ $this, 'storeSynchroniseOption' ] ) );
	}

	/**
	 * Save repeater synchronisation option in wp_options table.
	 *
	 * @param int $elementID Processed element (post, taxonomy) ID.
	 */
	public function storeSynchroniseOption( $elementID ) {
		if ( $this->shuffled->hasTranslations( $elementID ) ) {
			$trid = $this->shuffled->getTrid( $elementID );
			if ( $trid && CheckboxUI::isOptionSent() ) {
				$synchroniseOption = CheckboxOption::get();
				if ( CheckboxUI::isSelected() ) {
					$synchroniseOption[ $trid ] = true;
				} else {
					$synchroniseOption[ $trid ] = false;
				}
				CheckboxOption::update( $synchroniseOption );
			}
		}
	}
}