Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow is_network_activated to be filtered #1003

Merged
merged 6 commits into from Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions classes/class-admin.php
Expand Up @@ -134,7 +134,7 @@ public function __construct( $plugin ) {
add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 );
add_filter( 'role_has_cap', array( $this, 'filter_role_caps' ), 10, 3 );

if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && ! is_network_admin() ) {
if ( is_multisite() && $plugin->is_network_activated() && ! is_network_admin() ) {
$options = (array) get_site_option( 'wp_stream_network', array() );
$option = isset( $options['general_site_access'] ) ? absint( $options['general_site_access'] ) : 1;

Expand Down Expand Up @@ -647,7 +647,7 @@ private function erase_stream_records() {

$where = '';

if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
$where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
}

Expand Down Expand Up @@ -675,12 +675,12 @@ public function purge_scheduled_action() {
&&
is_network_admin()
&&
! is_plugin_active_for_network( $this->plugin->locations['plugin'] )
! $this->plugin->is_network_activated()
) {
return;
}

if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
if ( is_multisite() && $this->plugin->is_network_activated() ) {
$options = (array) get_site_option( 'wp_stream_network', array() );
} else {
$options = (array) get_option( 'wp_stream', array() );
Expand All @@ -699,7 +699,7 @@ public function purge_scheduled_action() {
$where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) );

// Multisite but NOT network activated, only purge the current blog
if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
$where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
}

Expand All @@ -726,7 +726,7 @@ public function plugin_action_links( $links, $file ) {
}

// Also don't show links in Network Admin if Stream isn't network enabled
if ( is_network_admin() && is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
if ( is_network_admin() && is_multisite() && ! $this->plugin->is_network_activated() ) {
return $links;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/class-export.php
Expand Up @@ -164,7 +164,7 @@ public function expand_columns( $columns ) {
'ip' => $columns['ip'],
);

if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
if ( is_multisite() && $this->plugin->is_network_activated() ) {
$new_columns['blog_id'] = __( 'Blog ID', 'stream' );
}

Expand Down
4 changes: 2 additions & 2 deletions classes/class-install.php
Expand Up @@ -177,7 +177,7 @@ public function verify_db() {
);
}

if ( is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && current_user_can( 'manage_network_plugins' ) ) {
if ( $this->plugin->is_network_activated() && current_user_can( 'manage_network_plugins' ) ) {
$uninstall_message = sprintf(
// translators: Placeholders refer to HTML Link tags (e.g. "<a href="https://foo.com/wp-admin/">")
__( 'Please %1$suninstall%2$s the Stream plugin and activate it again.', 'stream' ),
Expand Down Expand Up @@ -219,7 +219,7 @@ public function register_update_hook( $file, $callback, $version ) {

$plugin = plugin_basename( $file );

if ( is_plugin_active_for_network( $plugin ) ) {
if ( $this->plugin->is_network_activated() ) {
$current_versions = get_site_option( $this->option_key . '_connectors', array() );
$network = true;
} elseif ( is_plugin_active( $plugin ) ) {
Expand Down
2 changes: 1 addition & 1 deletion classes/class-log.php
Expand Up @@ -190,7 +190,7 @@ public function is_record_excluded( $connector, $context, $action, $user = null,

$exclude_settings = isset( $this->plugin->settings->options['exclude_rules'] ) ? $this->plugin->settings->options['exclude_rules'] : array();

if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && ! is_network_admin() ) {
if ( is_multisite() && $this->plugin->is_network_activated() && ! is_network_admin() ) {
$multisite_options = (array) get_site_option( 'wp_stream_network', array() );
$multisite_exclude_settings = isset( $multisite_options['exclude_rules'] ) ? $multisite_options['exclude_rules'] : array();

Expand Down
26 changes: 1 addition & 25 deletions classes/class-network.php
Expand Up @@ -91,31 +91,7 @@ public function get_network_blog() {
* @return bool
*/
public function is_network_activated() {
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}

if ( $this->is_mustuse() ) {
return true;
}

return is_plugin_active_for_network( $this->plugin->locations['plugin'] );
}

/**
* Returns true if Stream is a must-use plugin, otherwise false
*
* @return bool
*/
public function is_mustuse() {

$stream_php = trailingslashit( WPMU_PLUGIN_DIR ) . $this->plugin->locations['plugin'];

if ( file_exists( $stream_php ) && class_exists( 'WP_Stream\Plugin' ) ) {
return true;
}

return false;
return $this->plugin->is_network_activated();
}

/**
Expand Down
43 changes: 43 additions & 0 deletions classes/class-plugin.php
Expand Up @@ -247,4 +247,47 @@ public function plugins_loaded() {
$this->db = new DB( $driver );
}
}

/**
* Returns true if Stream is network activated, otherwise false
*
* @return bool
*/
public function is_network_activated() {

$is_network_activated = false;

if ( $this->is_mustuse() ) {
$is_network_activated = true;
} else {
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
$is_network_activated = is_plugin_active_for_network( $this->locations['plugin'] );
}

/**
* Filter allows the network activated detection to be overridden.
*
* @param string $is_network_activated Whether the plugin is network activated
* @param WP_Stream\Plugin $plugin The stream plugin object
*/
return apply_filters( 'wp_stream_is_network_activated', $is_network_activated, $this );
}

/**
* Returns true if Stream is a must-use plugin, otherwise false
*
* @return bool
*/
public function is_mustuse() {

$stream_php = trailingslashit( WPMU_PLUGIN_DIR ) . $this->locations['plugin'];

if ( file_exists( $stream_php ) && class_exists( 'WP_Stream\Plugin' ) ) {
return true;
}

return false;
}
}
2 changes: 1 addition & 1 deletion classes/class-uninstall.php
Expand Up @@ -66,7 +66,7 @@ public function uninstall() {

// Drop everything on single site installs or when network activated
// Otherwise only delete data relative to the current blog
if ( ! is_multisite() || is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
if ( ! is_multisite() || $this->plugin->is_network_activated() ) {
$this->delete_all_records();
$this->delete_all_options();
$this->delete_all_user_meta();
Expand Down