| @@ -1,31 +1,45 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace TableBuilder\Traits; | |
| 4 | - | |
| 5 | -/** | |
| 6 | - * Trait for making singleton instance | |
| 7 | - * This is a factory singleton | |
| 8 | - * | |
| 9 | - * @package TableBuilder\Traits | |
| 10 | - */ | |
| 11 | -trait PluginHelper{ | |
| 12 | - public static function is_plugin_active( $plugin ) { | |
| 13 | - return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) || self::is_plugin_active_for_network( $plugin ); | |
| 14 | - } | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * Check for network plugin active | |
| 18 | - */ | |
| 19 | - public static function is_plugin_active_for_network( $plugin ) { | |
| 20 | - if ( ! is_multisite() ) { | |
| 21 | - return false; | |
| 22 | - } | |
| 23 | - | |
| 24 | - $plugins = get_site_option( 'active_sitewide_plugins' ); | |
| 25 | - if ( isset( $plugins[ $plugin ] ) ) { | |
| 26 | - return true; | |
| 27 | - } | |
| 28 | - | |
| 29 | - return false; | |
| 30 | - } | |
| 31 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Shared plugin-status helper methods | |
| 4 | + * | |
| 5 | + * @package TableKit | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace TableBuilder\Traits; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * Trait for making singleton instance | |
| 12 | + * This is a factory singleton | |
| 13 | + * | |
| 14 | + * @package TableBuilder\Traits | |
| 15 | + */ | |
| 16 | +trait PluginHelper { | |
| 17 | + /** | |
| 18 | + * Checks whether a plugin is active, site-wide or network-wide. | |
| 19 | + * | |
| 20 | + * @param string $plugin Plugin basename, e.g. "table-builder-block-pro/table-builder-block-pro.php". | |
| 21 | + * @return bool True if the plugin is active on this site or network-wide. | |
| 22 | + */ | |
| 23 | + public static function is_plugin_active( $plugin ) { | |
| 24 | + return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) || self::is_plugin_active_for_network( $plugin ); | |
| 25 | + } | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * Checks whether a plugin is network-activated on a multisite install. | |
| 29 | + * | |
| 30 | + * @param string $plugin Plugin basename, e.g. "table-builder-block-pro/table-builder-block-pro.php". | |
| 31 | + * @return bool True if the plugin is network-active; always false on non-multisite. | |
| 32 | + */ | |
| 33 | + public static function is_plugin_active_for_network( $plugin ) { | |
| 34 | + if ( ! is_multisite() ) { | |
| 35 | + return false; | |
| 36 | + } | |
| 37 | + | |
| 38 | + $plugins = get_site_option( 'active_sitewide_plugins' ); | |
| 39 | + if ( isset( $plugins[ $plugin ] ) ) { | |
| 40 | + return true; | |
| 41 | + } | |
| 42 | + | |
| 43 | + return false; | |
| 44 | + } | |
| 45 | +} | |