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/zaklada/wp-content/plugins/acfml/classes/class-wpml-acf-pro.php
<?php

/**
 * Created by PhpStorm.
 * User: konrad
 * Date: 12.01.17
 * Time: 12:36
 */
class WPML_ACF_Pro {

	public function __construct() {
		add_action('icl_make_duplicate', array($this, 'make_duplicate_action'), 10, 4);
		add_filter('acf/duplicate_field/type=clone', array($this, 'duplicate_clone_field'), 10, 1);
	}

	public function make_duplicate_action($master_post_id, $lang, $post_array, $id) {
		if (isset($post_array['post_type']) && 'acf-field-group' == $post_array['post_type']) {
			$args = array(
				'post_parent' => $id,
				'post_type'   => 'acf-field',
				'numberposts' => -1
			);

			$posts = get_posts($args);

			if (is_array($posts) && count($posts) > 0) {
				foreach($posts as $post) {
					wp_delete_post($post->ID, true);
				}
			}
		}

	}

	/**
	 * Filter: Update clloned field names to translated version
	 *
	 * @param $field
	 *
	 * @return array Updated field
	 */
	public function duplicate_clone_field($field) {
		$parent_language = apply_filters('wpml_post_language_details', null, $field['parent']);
		foreach ($field['clone'] as $id => $key_post_name) {
			if (strpos($key_post_name, 'group_') === 0) {
				$original_id = $this->get_post_id_by_name($key_post_name);
				$translated_id = apply_filters('wpml_object_id', $original_id, 'acf-field-group', false, $parent_language['language_code']);
				if ($translated_id) {
					$post = get_post($translated_id);
					if (isset($post->post_name)) {
						$field['clone'][$id] = $post->post_name;
					}
				}
			}
		}

		return $field;
	}

	private function get_post_id_by_name($post_name, $output = OBJECT) {
		global $wpdb;
		$post_id = null;
		$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s", $post_name ));

		return $post_id;
	}

}