Skip to content

Commit

Permalink
Merge pull request #594 from x-team/issue-582
Browse files Browse the repository at this point in the history
Add network activated utility method, show in network menu when true
  • Loading branch information
lukecarbis committed Jul 14, 2014
2 parents 4476e22 + 3bf83d5 commit bf12bba
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions includes/network.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() {
Expand All @@ -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'] ) {
Expand Down Expand Up @@ -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' ),
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -538,6 +550,7 @@ function hide_blogs_connector( $connectors ) {
if ( ! is_network_admin() ) {
return array_diff( $connectors, array( 'WP_Stream_Connector_Blogs' ) );
}

return $connectors;
}
}

0 comments on commit bf12bba

Please sign in to comment.