Skip to content

Instantly share code, notes, and snippets.

@isuke01
Last active February 3, 2023 11:56
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 isuke01/dbe24412ab71d1cb74bf6571c5c056c4 to your computer and use it in GitHub Desktop.
Save isuke01/dbe24412ab71d1cb74bf6571c5c056c4 to your computer and use it in GitHub Desktop.
(WordPress/T2) Helper function to check if T2 feature is activated.
<?php
/**
* Helper functio nto check if there is T2 feature activated.
* Example usage: t2_is_feature_activated( 't2/newsletter' )
*
* @param string $feature The t2 feature e.g t2/newsletter.
* @return bool
*/
function t2_is_feature_activated( string $feature ): bool {
if ( ! \is_plugin_active( 't2/t2.php' ) ) {
return false;
}
$t2_features = [];
if ( function_exists( '\T2\Extensions\get_active_extensions' ) ) {
$t2_features = array_merge( $t2_features, \T2\Extensions\get_active_extensions() );
}
if ( function_exists( '\T2\Blocks\get_active_blocks' ) ) {
$t2_features = array_merge( $t2_features, \T2\Blocks\get_active_blocks() );
}
return in_array( $feature, $t2_features, true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment