File "wpml.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/advanced-custom-fields/includes/wpml.php
File size: 4.78 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

if (!defined('ABSPATH')) {
    exit;
}
if (!class_exists('ACF_WPML_Compatibility')) {
    class ACF_WPML_Compatibility
    {
        function __construct()
        {
            global $sitepress;
            acf_update_setting('default_language', $sitepress->get_default_language());
            acf_update_setting('current_language', $sitepress->get_current_language());
            acf_localize_data(array('language' => $sitepress->get_current_language()));
            add_action('acf/verify_ajax', array($this, 'verify_ajax'));
            add_filter('get_translatable_documents', array($this, 'get_translatable_documents'));
            if ($this->is_translatable()) {
                add_action('acf/upgrade_500_field_group', array($this, 'upgrade_500_field_group'), 10, 2);
                add_action('icl_make_duplicate', array($this, 'icl_make_duplicate'), 10, 4);
                add_filter('acf/settings/save_json', array($this, 'settings_save_json'));
                add_filter('acf/settings/load_json', array($this, 'settings_load_json'));
            }
        }
        function is_translatable()
        {
            global $sitepress;
            $post_types = $sitepress->get_setting('custom_posts_sync_option');
            if (!acf_is_array($post_types)) {
                return false;
            }
            if (!empty($post_types['acf-field'])) {
                $post_types['acf-field'] = 0;
                $sitepress->set_setting('custom_posts_sync_option', $post_types);
            }
            if (!empty($post_types['acf']) && !isset($post_types['acf-field-group'])) {
                $post_types['acf-field-group'] = 1;
                $sitepress->set_setting('custom_posts_sync_option', $post_types);
            }
            if (!empty($post_types['acf-field-group'])) {
                return true;
            }
            return false;
        }
        function upgrade_500_field_group($field_group, $ofg)
        {
            global $wpdb;
            $old_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_translations WHERE element_type=%s AND element_id=%d", 'post_acf', $ofg->ID), ARRAY_A);
            $new_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_translations WHERE element_type=%s AND element_id=%d", 'post_acf-field-group', $field_group['ID']), ARRAY_A);
            if (!$old_row || !$new_row) {
                return;
            }
            if (empty($this->trid_ref)) {
                $this->trid_ref = array();
            }
            if (isset($this->trid_ref[$old_row['trid']])) {
                $new_row['trid'] = $this->trid_ref[$old_row['trid']];
            } else {
                $this->trid_ref[$old_row['trid']] = $new_row['trid'];
            }
            $table = "{$wpdb->prefix}icl_translations";
            $data = array('trid' => $new_row['trid'], 'language_code' => $old_row['language_code']);
            $where = array('translation_id' => $new_row['translation_id']);
            $data_format = array('%d', '%s');
            $where_format = array('%d');
            if ($old_row['source_language_code']) {
                $data['source_language_code'] = $old_row['source_language_code'];
                $data_format[] = '%s';
            }
            $result = $wpdb->update($table, $data, $where, $data_format, $where_format);
        }
        function settings_save_json($path)
        {
            if (!is_writable($path)) {
                return $path;
            }
            $path = untrailingslashit($path) . '/' . acf_get_setting('current_language');
            if (!file_exists($path)) {
                mkdir($path, 0777, true);
            }
            return $path;
        }
        function settings_load_json($paths)
        {
            if ($paths) {
                foreach ($paths as $i => $path) {
                    $paths[$i] = untrailingslashit($path) . '/' . acf_get_setting('current_language');
                }
            }
            return $paths;
        }
        function icl_make_duplicate($master_post_id, $lang, $postarr, $id)
        {
            if ($postarr['post_type'] != 'acf-field-group') {
                return;
            }
            acf_update_setting('current_language', $lang);
            acf_duplicate_field_group($master_post_id, $id);
            global $iclTranslationManagement;
            $iclTranslationManagement->reset_duplicate_flag($id);
        }
        function verify_ajax()
        {
            if (isset($_REQUEST['lang'])) {
                global $sitepress;
                $sitepress->switch_lang($_REQUEST['lang']);
            }
        }
        function get_translatable_documents($icl_post_types)
        {
            unset($icl_post_types['acf-field']);
            return $icl_post_types;
        }
    }
    acf_new_instance('ACF_WPML_Compatibility');
}