Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nykula opened this issue May 23, 2023 · 8 comments
Closed

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

nykula opened this issue May 23, 2023 · 8 comments
Labels
bug Something isn't working, reproducible enhancement New feature or request module: ACF Integration with ACF severity: minor Minor functionality

Comments

@nykula
Copy link

nykula commented May 23, 2023

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
@nykula nykula added the maybe bug Potential bug, to be investigated label May 23, 2023
@herrvigg herrvigg added module: ACF Integration with ACF bug Something isn't working, reproducible severity: minor Minor functionality and removed maybe bug Potential bug, to be investigated labels May 28, 2023
@herrvigg
Copy link
Collaborator

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
Copy link
Author

nykula commented May 30, 2023

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
Copy link
Collaborator

herrvigg commented Jun 6, 2023

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

@herrvigg
Copy link
Collaborator

herrvigg commented Jun 6, 2023

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
Copy link
Author

nykula commented Jun 7, 2023

@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
Copy link
Collaborator

@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
Copy link
Collaborator

Released in 3.15.2 for the first issue.

@bichonnages
Copy link

this might help:

add_action( 'admin_enqueue_scripts', function() {
	global $pagenow;

	// Check if it's an ACF options page
	if ( isset( $_GET['page'] ) && strpos( $_GET['page'], 'acf-options' ) !== false ) {
		
		// Enqueue the missing qTranslate-XT scripts
		wp_enqueue_script( 
			'qtranslate-admin-main-js', 
			plugins_url( 'qtranslate-xt/dist/main.js', 'qtranslate-xt' ), 
			[], 
			'3.12.1', 
			true 
		);

		wp_enqueue_script( 
			'qtranslate-acf-js', 
			plugins_url( 'qtranslate-xt/dist/modules/acf.js', 'qtranslate-xt' ), 
			[], 
			'3.12.1', 
			true 
		);

		wp_enqueue_script( 
			'post-exec-js', 
			plugins_url( 'qtranslate-xt/admin/js/post-exec.min.js', 'qtranslate-xt' ), 
			[], 
			'3.12.1', 
			true 
		);
	}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working, reproducible enhancement New feature or request module: ACF Integration with ACF severity: minor Minor functionality
Projects
None yet
Development

No branches or pull requests

3 participants