qtranslate / qtranslate-xt

qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
553 stars 104 forks source link

ACF Pro 6.0 #1227

Closed salt-istanbul closed 1 year ago

salt-istanbul commented 1 year ago

Hi, qtranslate-xt / acf integration not working with ACF Pro 6.0.

Komarovski commented 1 year ago

Here's a quick fix for front-end, add this function to your functions.php file:

function qtranslate_filter_acf_fields($value, $post_id, $field){ $value = qtranxf_useCurrentLanguageIfNotFoundUseDefaultLanguage($value); return $value; } add_filter('acf/format_value/type=file', 'qtranslate_filter_acf_fields', 10, 3); add_filter('acf/format_value/type=image', 'qtranslate_filter_acf_fields', 10, 3); add_filter('acf/format_value/type=post_object', 'qtranslate_filter_acf_fields', 10, 3); add_filter('acf/format_value/type=text', 'qtranslate_filter_acf_fields', 10, 3); add_filter('acf/format_value/type=textarea', 'qtranslate_filter_acf_fields', 10, 3); add_filter('acf/format_value/type=url', 'qtranslate_filter_acf_fields', 10, 3); add_filter('acf/format_value/type=wysiwyg', 'qtranslate_filter_acf_fields', 10, 3);

salt-istanbul commented 1 year ago

Thanks @Komarovski but the most important problem there's no any qtranslate-xt field option on ACF field group page.

acf-pro-v6 0 0

MKRD-SUPPORT commented 1 year ago

Version 6 is currently not supported, so I would recommend not using it just yet. In addition, many problems with version 5 still need to be fixed. To this day I still don't understand why the QTX plugin clones the ACF fields.

If you still want to use ACF(-PRO) 6+, you must first allow this in the acf_qtranslate_plugin class:

init() acf_enabled()

herrvigg commented 1 year ago

Version 6 is currently not supported, so I would recommend not using it just yet. If you still want to use ACF(-PRO) 6+, you must first allow this in the acf_qtranslate_plugin class: init() acf_enabled()

All of this is obsolete with qTranslate-XT 3.12.1 released Sept 4. The acf_qtranslate_plugin class doesn't exist anymore (see #1191 and #1187). The new qtranxf_acf_init allows any ACF >= 5.0.0. But it's possible some things are broken with ACF 6, I haven't tried it yet. Please update your QT-XT to latest version.

herrvigg commented 1 year ago

@salt-istanbul @Komarovski @MKRD-SUPPORT Which qTranslate-XT version are you using?

I can't reproduce the problem with ACF 6.0.3 Free. It should work already with qTranslate-XT 3.12.1 that was released September 4 so it's been already available for quite some time. It wasn't an intentional fix for ACF6 that I wasn't even aware of at that time but I extended the support of any ACF >= 5.0.0. I don't think it should be different with ACF 6 Pro for the main functionalities. There's a specific issue for custom ACF option pages reported in #1233 but I'm not able to see this with ACF free.

To this day I still don't understand why the QTX plugin clones the ACF fields.

I'm not the original author, but I guess the main reason was because the rendering of translated fields is specific to the current language. Perhaps that could be handled differently with hooks instead of registering new fields?

herrvigg commented 1 year ago

To this day I still don't understand why the QTX plugin clones the ACF fields.

In fact there's an option in the qTranslate / ACF tab called "Enable translation for Standard Field Types". If you tick that, it will enable the ML support for ACF fields: text, textarea, wysiwyg - though there's a known problem with wysiwyg reported in #1186. I don't know yet why it's only for those fields, perhaps it could be extended.

MKRD-SUPPORT commented 1 year ago

In the production environment I will not update to the current state of the plugin: ACF(-Pro) 5.12.3, QTX 3.11.0

I'm sorry, but I don't have time to deal with the plugin in the near future.

herrvigg commented 1 year ago

To me there's no major problem with ACF6, it works but you need QTX 3.12.1 or later. Let's see what the others say.

herrvigg commented 1 year ago

However I will keep this ticket open for this problem with the ACF group title. image

There's a regression with ACF6 because they removed the form... so QT-XT can't send the current language being edited... the switching buttons have move down, they seem to work but only the last language is saved and it overwrites the others 😕

Error in the console log No form found for translatable field id= title

Fortunately it's only for the title so it's a minor issue. The switching buttons work and the hidden fields are created correctly though, so there's some hope to fix that.

herrvigg commented 1 year ago

Just in case, if you want a quicker and simpler fix on an older version of QT-XT just change these lines: https://github.com/qtranslate/qtranslate-xt/blob/fbe27655694dc48af155e183a15d6755971e54c6/modules/acf/src/plugin.php#L35 https://github.com/qtranslate/qtranslate-xt/blob/fbe27655694dc48af155e183a15d6755971e54c6/modules/acf/src/plugin.php#L50 Replace the check

 $this->acf_major_version() === 5

with

 $this->acf_major_version() >= 5

That should do the job to keep most of the QT-XT module for ACF working without adding any code. You can even remove the version checks completely for temporary tests. I realized it was artificially limited so I changed that in 3.12.1 along with a lot of code refactoring. The rest should not impact the existing functionalities at all.

herrvigg commented 1 year ago

Since this topic was created for another reason about the ACF version, better have a separate issue for field title: #1252 . The current issue should be solved already with QTX 3.12.1. Note there was also a regression with the LSB #1233 but it's unrelated to ACF6, already fixed in master.