From 3bf83d53e6491dfc2a3067cfb871a5b199e2852e Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Fri, 11 Jul 2014 12:22:21 -0500 Subject: [PATCH] Add network activated utility method, show in network menu when true --- includes/network.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/includes/network.php b/includes/network.php index ba516c013..4abf537c2 100644 --- a/includes/network.php +++ b/includes/network.php @@ -54,10 +54,28 @@ function ajax_network_admin() { } } + /** + * Returns true if Stream is network activated, otherwise false + * + * @return bool + */ + public static function is_network_activated() { + if ( ! function_exists( 'is_plugin_active_for_network' ) ) { + require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); + } + + return is_plugin_active_for_network( WP_STREAM_PLUGIN ); + } + /** * Adds Stream to the admin bar under the "My Sites > Network Admin" menu + * if Stream has been network-activated */ function network_admin_bar_menu( $admin_bar ) { + if ( ! self::is_network_activated() ) { + return; + } + $href = add_query_arg( array( 'page' => WP_Stream_Admin::RECORDS_PAGE_SLUG, @@ -77,6 +95,7 @@ function network_admin_bar_menu( $admin_bar ) { /** * Builds a stdClass object used when displaying actions done in network administration + * * @return stdClass */ public static function get_network_blog() { @@ -95,10 +114,7 @@ public static function get_network_blog() { * @return boolean */ public static function disable_admin_access( $disable_access ) { - if ( ! function_exists( 'is_plugin_active_for_network' ) ) { - require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); - } - if ( ! is_network_admin() && is_plugin_active_for_network( WP_STREAM_PLUGIN ) ) { + if ( ! is_network_admin() && self::is_network_activated() ) { $settings = (array) get_site_option( WP_Stream_Settings::NETWORK_KEY, array() ); if ( isset( $settings['general_enable_site_access'] ) && false === $settings['general_enable_site_access'] ) { @@ -142,7 +158,7 @@ function admin_menu_screens() { array( 'WP_Stream_Admin', 'render_page' ) ); } - if ( is_plugin_active_for_network( WP_STREAM_PLUGIN ) ) { + if ( self::is_network_activated() ) { WP_Stream_Admin::$screen_id['extensions'] = add_submenu_page( WP_Stream_Admin::RECORDS_PAGE_SLUG, __( 'Stream Extensions', 'stream' ), @@ -228,11 +244,7 @@ function settings_form_description( $description ) { * @return mixed */ function get_network_admin_fields( $fields ) { - if ( ! function_exists( 'is_plugin_active_for_network' ) ) { - require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); - } - - if ( ! is_plugin_active_for_network( WP_STREAM_PLUGIN ) ) { + if ( ! self::is_network_activated() ) { return $fields; } @@ -538,6 +550,7 @@ function hide_blogs_connector( $connectors ) { if ( ! is_network_admin() ) { return array_diff( $connectors, array( 'WP_Stream_Connector_Blogs' ) ); } + return $connectors; } }