Skip to content

Instantly share code, notes, and snippets.

@vdwijngaert
Created July 19, 2022 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdwijngaert/a7d4bd038e5e524ebb487468f76827fa to your computer and use it in GitHub Desktop.
Save vdwijngaert/a7d4bd038e5e524ebb487468f76827fa to your computer and use it in GitHub Desktop.
Check whether WPML is active for current site in a Multisite environment
<?php
/**
* Check whether WPML is active for current site. Checking for the availability of the SitePress class is not enough,
* because the plugin can be deactivated for a certain site. Also, this behavior is not consistent when switching blogs.
*
* How *NOT* to do it:
* - `class_exists( 'SitePress' )`
* - `defined('ICL_LANGUAGE_CODE')`
* - ...
*/
function my_prefix_wpml_is_active(): bool {
if ( ! class_exists( 'SitePress' ) ) {
return false;
}
if ( ! function_exists( 'wpml_is_setup_complete' ) ) {
return false;
}
if ( ! wpml_is_setup_complete() ) {
return false;
}
return true !== (bool) get_option( '_wpml_inactive', false );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment