Created
July 19, 2022 05:19
-
-
Save vdwijngaert/a7d4bd038e5e524ebb487468f76827fa to your computer and use it in GitHub Desktop.
Check whether WPML is active for current site in a Multisite environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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