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.

This topic contains 9 replies, has 3 voices.

Last updated by marchinO 3 years, 6 months ago.

Assigned support staff: Yuri.

Author Posts
January 9, 2018 at 2:29 pm #1478059

roxanneS

I am trying to: View a page

Link to a page where the issue can be seen:
hidden link

I expected to see: Language switcher displaying properly

Instead, I got:
Warning: max(): Array must contain at least one element in /home/vddgartu/public_html/richardbeliveau.org/wp-content/plugins/sitepress-multilingual-cms/classes/language-switcher/class-wpml-ls-render.php on line 175

January 9, 2018 at 3:42 pm #1478214

Yuri

Hi, it seems that after the upgrade there might be some data left in the cache. Let me run a quick checklist by you.

- disable the Cloudflare plugin to see if there is any external cache involved.
- disable all non-WPML plugins
- switch to one of the default WordPress themes like TwentySeventeen or TwentySixteen.

If after these procedures the issue still remains, you can try to clear the internal WPML cache. You will need to go to the admin on your site on WPML > Support. At the end of this page, there is a link labeled "troubleshooting". This page will contain multiple buttons to trigger maintenance routines. The ones you will need to run are the "Disable Cache for Language Switcher Templates" and the other one is "Clear the cache in WPML".

Let me know how it goes and if the issue persists.

January 14, 2018 at 1:54 pm #1484061

roxanneS

The problem seems to be with the Avada theme. This is a very popular theme. Have you had any other complaints about this problem. It occurs only with there is no translation for a post/page.

January 14, 2018 at 2:21 pm #1484073

roxanneS

I restored the wordpress files and database, then proceeded to update WPML plugins one by one (clearing the Cache and Cloudflare every time). I can confirm the problem appears when updating from WPML Multilingual CMS 3.8.4 to 3.9.1.

January 15, 2018 at 5:26 pm #1484990

marchinO

I followed the instruction but it does not help resolving this issue. Please let me know if there is anything I can do to fix this issue.

January 16, 2018 at 2:47 pm #1486214

Yuri

Hi, I've gotten word back from our developers and they are now aware of the issue. While we work on integrating a fix for this in our future releases I've been given a temporary fix to apply to your site.

Would it be possible for you to provide us with temporary FTP and wp-admin credentials so I can apply the patch to your site?

I'll set up your next reply to private.

January 16, 2018 at 3:41 pm #1486301

Yuri

@marchino I've applied a fix on your site. The file modified was: /wp-content/plugins/sitepress-multilingual-cms/classes/language-switcher/class-wpml-ls-render.php

Please test your site and let us know if there is anything out of place.

@roxannes If possible, please provide us with temporary wp-admin and FTP credentials so I can apply the patch fix to your server as well. I've enabled private fields for your next response.

January 16, 2018 at 5:52 pm #1486467

Yuri

Hi, I am unable to log on the FTP server since it is requiring my ssh key. To avoid taking too long in setting this up I'll give you the information required to update the code.

The target file is: /wp-content/plugins/sitepress-multilingual-cms/classes/language-switcher/class-wpml-ls-render.php

On line 165 you will need to change this:

	private function merge_menu_items( $items, $lang_items, $is_before ) {
		if ( $is_before ) {
			$items_to_prepend = $lang_items;
			$items_to_append  = $items;
		} else {
			$items_to_prepend = $items;
			$items_to_append  = $lang_items;
		}

		$menu_orders = wp_list_pluck( $items_to_prepend, 'menu_order' );
		$offset      = max( $menu_orders );

		foreach ( $items_to_append as $item ) {
			$item->menu_order = $item->menu_order + $offset;
		}

		return array_merge( $items_to_prepend, $items_to_append );
	}

for this:

    private function merge_menu_items( $items, $lang_items, $is_before ) {
        if ( $is_before ) {
            $items_to_prepend = $lang_items;
            $items_to_append  = $items;
        } else {
            $items_to_prepend = $items;
            $items_to_append  = $lang_items;
        }

        $menu_orders = wp_list_pluck( $items_to_prepend, 'menu_order' );
        if (!empty($menu_orders)) {
          $offset = max($menu_orders);
        } else {
     	   $offset = 0;
        };
        foreach ( $items_to_append as $item ) {
            $item->menu_order = $item->menu_order + $offset;
        }

        return array_merge( $items_to_prepend, $items_to_append );
    }

Let me know if everything goes according to plan and if you need further assistance.

January 16, 2018 at 7:50 pm #1486576

roxanneS

Thank you!

January 17, 2018 at 7:21 am #1486890

marchinO

Your fix was effective and I don't see any more error. Hopefully this is fixed in next version.