we have a multisite setup where we want to disable the available languages on a subsite programmatically.
per my knowledge, there is no function or hook available, so I checked the DB and found the wp_99_icl_languages table. we set the languages on inactive there. Additionally we adjusted the option_value "icl_sitepress_settings" in the wp_99_options table. But the languages are still shown/available.
Is there a way to programmatically disable languages?
Welcome to the WPML support forum. I will do my best to help you to resolve the issue.
We are not recommending disabling the language via code. Because there may be a chance of conflicts if we edit the option value "icl_sitepress_settings". So the best option is to hide the language from WPML>>Languages>>Hide Languages. Refer to the following doc for more details
Maybe you have to clear the WPML caches, after updating the wp_99_icl_languages table & "icl_sitepress_settings" option values. It works for us after trying the following code in the functions.php file of the theme.
global $wpdb;
$wpdb->query("UPDATE `wp_icl_languages` SET `active` = '0' WHERE `code` = 'fr'");
icl_cache_clear();
$cache_directory = new WPML_Cache_Directory( new WPML_WP_API() );
$cache_directory->remove();
But please note that we have limitations here because of customization and we are not recommending this due to the high risk for errors.