Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 13:00 9:00 – 13:00 9:00 – 13:00 8:00 – 12:00 8:00 – 12:00 -
- 14:00 – 17:00 14:00 – 18:00 14:00 – 18:00 13:00 – 17:00 13:00 – 17:00 -

Supporter timezone: Europe/Zagreb (GMT+02:00)

Tagged: 

This topic contains 17 replies, has 2 voices.

Last updated by Bruno Kos 1 year, 6 months ago.

Assisted by: Bruno Kos.

Author Posts
December 28, 2023 at 11:35 am #15134333

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

We found that this depends upon _generate_element_display_conditions, _generate_element_exclude_conditions, and _generate_hook that should be set as "copy-once."

To have this working with automatic translation and synchronization, we recommend the following steps:

1. **Change Field Settings:**

- Modify the settings of _generate_element_display_conditions, _generate_element_exclude_conditions, and _generate_hook to "copy" instead of "copy-once."

2. **Code Modification:**

- Open the file `wp-content/plugins/gp-premium/elements/class-conditions.php`.
- Locate the `show_data()` function around line 314.
- Replace:

[php]public static function show_data( $conditionals, $exclude, $roles ) {
	$current_location = self::get_current_location();
	$show = false;

	// Show depending on location conditionals.
	if ( ! $show ) {

with:

public static function show_data( $conditionals, $exclude, $roles ) {
	$current_location = self::get_current_location();
	$show = false;

	// WPMl Workaround for compsupp-7109
	if ( class_exists('Sitepress') ) {
		// Conditionals
		foreach ((array) $conditionals as $key => $conditional) {
			if (isset( $conditional['object'] ) && ! empty( $conditional['object'] && is_numeric($conditional['object']) )) {
				
				// If ID is a post
				if (get_post_status( $conditional['object'] ) ) {
					$post_type = get_post_type($conditional['object']);
					$conditionals[$key]['object'] = apply_filters( 'wpml_object_id', $conditional['object'], $post_type , TRUE  );
				}	

				// If ID is a term
				elseif (get_term($conditional['object'])) {
					// Terms are automatically translated when using get_term;
					$term = get_term($conditional['object']);
					$conditionals[$key]['object'] = $term->term_id;
				}
			}
		}

		// Exclude conditions
		foreach ((array) $exclude as $key => $conditional) {
			// Same logic for $exclude, it would be better to have a separate function for that, but I want to simplify the workaround steps
			if (isset( $conditional['object'] ) && ! empty( $conditional['object'] && is_numeric($conditional['object']) )) {
				
				// If ID is a post
				if (get_post_status( $conditional['object'] ) ) {
					$post_type = get_post_type($conditional['object']);
					$exclude[$key]['object'] = apply_filters( 'wpml_object_id', $conditional['object'], $post_type , TRUE  );
				}	

				// If ID is a term
				elseif (get_term($conditional['object'])) {
					// Terms are automatically translated when using get_term;
					$term = get_term($conditional['object']);
					$exclude[$key]['object'] = $term->term_id;
				}
			}
		}
	}

	// Show depending on location conditionals.
	if ( ! $show ) {

Some notes about this though:

- This change will allow condition IDs to be automatically translated
- Please note that the ID translations will occur on the front-end only; the back-end settings will remain unchanged (so will say "vi" e.g. on both languages).
- we are unsure whether this will affect other parts of the site

Please report this to GeneratePress authors so they could have a look.

December 31, 2023 at 12:42 am #15138359

robinB-8

Thanks.

But if GeneratePress update plugin, I will lose my custom code.

January 2, 2024 at 8:00 am #15140331

Bruno Kos
WPML Supporter since 12/2018

Languages: English (English ) German (Deutsch ) French (Français )

Timezone: Europe/Zagreb (GMT+02:00)

Yes, these will be overwritten, that's why you need to contact GeneratePress so they could assist with this, we cannot add this into our plugin.

The topic ‘[Closed] Conflict between "GeneratePress premium" and "WPML String Translation"’ is closed to new replies.