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
546 stars 103 forks source link

[ACF] Can't create more post types after installing qTranslate-XT #1342

Closed nykula closed 1 year ago

nykula commented 1 year ago

Describe the bug When I try to create a post type using Advanced Custom Fields (without a dedicated plugin, it's a new feature in ACF 6.1), and qTranslate-XT is enabled, I get a validation error about unsupported characters in the key, and no post type gets created.

To Reproduce Steps to reproduce the behavior:

  1. In ACF, create a post type "Послуга" with key "service"

  2. In qTranslate-XT, add languages: Ukrainian (set as default) and Russian

  3. Create a field group for the "service" post type, with a field "address", translating the field title as "Адреса" (uk) and "Адрес" (ru), and translating the field group title as "Поля послуги" (uk) and "Поля услуги" (ru). This isn't a required step but I do it to ensure that the field group creation page has a language switcher and that it works.

  4. Try create another post type with key "service-group", filling it in one language only (no language switcher appears on post type creation page).

Expected behavior When I add debug statements to PHP, it seems ajax_validate_values receives "[:uk]service-group[:]" as the post type key. I think the post type key should not be translated, it should remain "service-group". But the UI should show a language switcher allowing to translate the post type title. The same issues as with post types happens with taxonomies when I try to create them using ACF.

Debug info

Versions {
  "PHP_VERSION": "8.2.5",
  "WP_VERSION": "6.2.2",
  "QTX_VERSION": "3.15.1",
  "Plugins": [
    "Advanced Custom Fields 6.1.6",
    "Classic Editor 1.6.3",
    "Webcraftic Cyrlitera – transliteration of links and file names 1.1.7",
    "Git Updater 12.2.2",
    "ACF Photo Gallery Field 1.9",
    "ACF Post-2-Post 1.7.0",
    "qTranslate-XT 3.15.1"
  ]
}
Configuration {
  "default_language": "uk",
  "enabled_languages": [
    "uk",
    "en",
    "ru"
  ],
  "locale": {
    "uk": "uk",
    "en": "en_US",
    "ru": "ru_RU"
  },
  "date_format": {
    "uk": "%A %B %e%q, %Y",
    "en": "%A %B %e%q, %Y",
    "ru": "%A %B %e%q, %Y"
  },
  "time_format": {
    "uk": "%H:%M",
    "en": "%I:%M %p",
    "ru": "%H:%M"
  },
  "url_mode": "1",
  "use_strftime": 3,
  "filter_options_mode": 0,
  "language_name_case": 0,
  "detect_browser_language": true,
  "hide_untranslated": false,
  "show_menu_alternative_language": false,
  "show_displayed_language_prefix": true,
  "show_alternative_content": false,
  "hide_default_language": true,
  "use_secure_cookie": false,
  "header_css_on": true,
  "text_field_filters": [],
  "disable_client_cookies": false,
  "url_info": {
    "cookie_lang_front": "uk",
    "cookie_lang_admin": "uk",
    "cookie_front_or_admin_found": true,
    "scheme": "http",
    "host": "localhost",
    "path": "/wp-admin/admin-ajax.php",
    "query": "action=admin_debug_info",
    "path-base": "",
    "wp-path": "/wp-admin/admin-ajax.php",
    "language_neutral_path": true,
    "http_referer": "http://localhost/wp-admin/options-general.php?page=qtranslate-xt",
    "referer_admin": true,
    "doing_front_end": false,
    "lang_cookie_admin": "uk",
    "lang_admin": "uk",
    "language": "uk",
    "set_cookie": false
  },
  "language": "uk",
  "editor_mode": 0,
  "highlight_mode": 1,
  "auto_update_mo": true,
  "hide_lsb_copy_content": false,
  "lsb_style": "simple-buttons.css",
  "config_files": [
    "./i18n-config.json"
  ],
  "custom_fields": [],
  "custom_field_classes": [],
  "post_type_excluded": [],
  "admin_enabled_modules": {
    "acf": true,
    "all-in-one-seo-pack": false,
    "events-made-easy": false,
    "jetpack": false,
    "google-site-kit": false,
    "gravity-forms": false,
    "woo-commerce": false,
    "wp-seo": false,
    "slugs": false
  },
  "qtrans_compatibility": false
}
Browser - any
herrvigg commented 1 year ago

I'm already stuck in step 1 saying the post key is invalid. Perhaps what is missing in the description is that the "text" field must be enabled in the QTX-ACF options. I'm not sure exactly at what step it fails in your case? What QTX-ACF options do you have (settings / languages / ACF tab)?

nykula commented 1 year ago

On the ACF tab in my QTX settings, all standard field options are checked. Text, text area, editor, label, instructions, default value. All extended field options are unchecked.

In my case the step 4 fails. But I wrote the first steps from memory to describe my existing website, where I created some post types before setting up QTX and configuring languages. It makes sense that with a clean install of both ACF and QTX at the same time it fails as early as step 1.

herrvigg commented 1 year ago

@nykula I pushed a fix patch to master. Could you try it?

herrvigg commented 1 year ago

The LSB will appear twice because there's no post content, this is tricky to fix without impacting regular posts so I leave it like this for now, it's a minor problem. There's even a Metabox for LSB so there are shown 3 times in these ACF settings.

nykula commented 1 year ago

@herrvigg Thank you, trying the latest commit 7af9a31. The issue is more complex apparently. Saving post types now doesn't crash. However, editing and saving a post type with QTX enabled, for example translating its title, removes the post type from the wp-json API, meaning that /wp-json no longer lists /wp/v2/service in routes and the route itself says not found. I have to undo it by disabling QTX and saving the type without title translations again.

My guess is that more fields need special handling to be exempt from translation. Particularly those that become visible when the Advanced Configuration checkbox is checked for a given post type. For example, the Advanced Settings / REST API / Show In REST API checkbox. I noticed the REST checkbox similarly becoming unset sometimes when I edit field groups, but I couldn't debug that unfortunately.

Another more minor part of the issue is that the newly saved post type title translations don't appear in the sidebar, only the default language titles appear instead.

herrvigg commented 1 year ago

@nykula the REST issue looks like a different scope than the initial issue you sent. Can you create a separate ticket with that explaining how to reproduce the problem? So we can close this one about the admin edition. It will facilitate the follow-up.

herrvigg commented 1 year ago

Released in 3.15.2 for the first issue.