Due to the large volume of support requests you may experience longer wait until a supporter handles your request. We apologize for the inconvenience this causes. We encourage you to please search the forum for other support topics that may be helpful and to review our documentation. A supporter will respond to you as soon as possible.

[Closed] Calling icl_get_languages with WP 3.5 and resetting query

Home Support English Support [Closed] Calling icl_get_languages with WP 3.5 and resetting query

This topic contains 4 replies, has 3 voices, and was last updated by  johan 2 years, 2 months ago. The support staff assigned to this topic is Harshad.

Author Posts
Author Posts
December 17, 2012 at 1:59 am #91050

JasonB1

Hi Guys,

I think I may have found a slight bug with WP 3.5 and the get_ls_languages function of the main SitePress class, and I just wanted to let you guys know about it.

I have a plugin where I register different sets of options based on the WPML languages the user has setup, and so I have a function that is hooked to admin_init where I call icl_get_languages.

function my_options(){
	$langs = icl_get_languages();
	// do stuff with $langs...
}
add_action( 'admin_init', 'my_options' );

Since upgrading to WP 3.5, any page in the admin panel that has a query of posts is now broken. For example, when I go to the "Posts" admin panel, it tells me there are no posts on my site (see attached screenshot).

So, I had a look at the get_ls_languages of the SitePress class, and it appears to be some kind of issue with how the query is being reset after determining the languages. I was able to fix the issue from my plugin by calling wp_reset_query after retrieving the languages:

function my_options(){
	$langs = icl_get_languages();
	wp_reset_query();
	// do stuff with $langs...
}
add_action( 'admin_init', 'my_options' );
December 17, 2012 at 7:06 am #91066

Harshad
Forum moderator

Dear Jason,

Thanks for sharing this information, I will pass this information to our development team and check it gets fixed.

December 21, 2012 at 10:50 pm #92745

JasonB1

So after the upgrade to v2.6.3, it appears the icl_get_languages function no longer works within the admin panel at all. It simply returns a blank array no matter where it's hooked in.

This is how I'm able to retrieve the languages in v2.6.3, but I'm not sure if making icl_get_languages not work was WPML's intention.

function example(){
	global $sitepress;
	$langs = $sitepress->get_active_languages();
}
add_action( 'admin_init', 'example' );
December 22, 2012 at 9:22 am #92780

Harshad
Forum moderator

We have updated the get_ls_languages function of the main SitePress class.

December 27, 2012 at 10:19 pm #93326

johan

Hello!

Is the new behaviour of icl_get_languages (not returning languages inside admin panel) intended or is it a bug?

If intended: Is JasonB1's method the recommended way to retrieve languages?

Need to know, one of my plugins uses icl_get_languages and will stop working if I upgrade!

best regards Johan Linderoth

The topic ‘[Closed] Calling icl_get_languages with WP 3.5 and resetting query’ is closed to new replies.