| @@ -2,13 +2,15 @@ | ||
| 2 | 2 | namespace WP_Stream; |
| 3 | 3 | |
| 4 | 4 | class Plugin { |
| 5 | 5 | /** |
| 6 | - * Plugin version number | |
| 6 | + * Plugin version number. | |
| 7 | 7 | * |
| 8 | + * TODO Maybe pass this as a constructor dependency? | |
| 9 | + * | |
| 8 | 10 | * @const string |
| 9 | 11 | */ |
| 10 | - const VERSION = '3.2.3'; | |
| 12 | + const VERSION = '3.4.2'; | |
| 11 | 13 | |
| 12 | 14 | /** |
| 13 | 15 | * WP-CLI command |
| 14 | 16 | * |
| @@ -245,6 +247,49 @@ | ||
| 245 | 247 | if ( class_exists( $driver_class ) ) { |
| 246 | 248 | $driver = new $driver_class(); |
| 247 | 249 | $this->db = new DB( $driver ); |
| 248 | 250 | } |
| 251 | + } | |
| 252 | + | |
| 253 | + /** | |
| 254 | + * Returns true if Stream is network activated, otherwise false | |
| 255 | + * | |
| 256 | + * @return bool | |
| 257 | + */ | |
| 258 | + public function is_network_activated() { | |
| 259 | + | |
| 260 | + $is_network_activated = false; | |
| 261 | + | |
| 262 | + if ( $this->is_mustuse() ) { | |
| 263 | + $is_network_activated = true; | |
| 264 | + } else { | |
| 265 | + if ( ! function_exists( 'is_plugin_active_for_network' ) ) { | |
| 266 | + require_once ABSPATH . '/wp-admin/includes/plugin.php'; | |
| 267 | + } | |
| 268 | + $is_network_activated = is_plugin_active_for_network( $this->locations['plugin'] ); | |
| 269 | + } | |
| 270 | + | |
| 271 | + /** | |
| 272 | + * Filter allows the network activated detection to be overridden. | |
| 273 | + * | |
| 274 | + * @param string $is_network_activated Whether the plugin is network activated | |
| 275 | + * @param WP_Stream\Plugin $plugin The stream plugin object | |
| 276 | + */ | |
| 277 | + return apply_filters( 'wp_stream_is_network_activated', $is_network_activated, $this ); | |
| 278 | + } | |
| 279 | + | |
| 280 | + /** | |
| 281 | + * Returns true if Stream is a must-use plugin, otherwise false | |
| 282 | + * | |
| 283 | + * @return bool | |
| 284 | + */ | |
| 285 | + public function is_mustuse() { | |
| 286 | + | |
| 287 | + $stream_php = trailingslashit( WPMU_PLUGIN_DIR ) . $this->locations['plugin']; | |
| 288 | + | |
| 289 | + if ( file_exists( $stream_php ) && class_exists( 'WP_Stream\Plugin' ) ) { | |
| 290 | + return true; | |
| 291 | + } | |
| 292 | + | |
| 293 | + return false; | |
| 249 | 294 | } |
| 250 | 295 | } |