Commit e97c20af authored by Christian Wach's avatar Christian Wach
Browse files

Add mu-plugin file

parent 657becb2
<?php /*
--------------------------------------------------------------------------------
Plugin Name: CiviCRM Network Groups Must Use
Plugin URI: https://develop.tadpole.cc/plugins/civicrm-network-groups
Description: Enables the CiviCRM Network Groups plugin to modify the behaviour of the Groups plugin.
Author: Christian Wach
Version: 0.3
Author URI: http://haystack.co.uk
--------------------------------------------------------------------------------
*/
/**
* CiviCRM Network Groups Must-Use Class.
*
* A class that that enables CiviCRM Network Groups to modify the behaviour of
* the Groups plugin.
*
* @since 0.3
*
* @package CiviCRM_Network_Groups
*/
class CiviCRM_Network_Groups_Must_Use {
/**
* Constructor.
*
* @since 0.3
*/
public function __construct() {
// Filter the table prefix early.
add_filter( 'groups_get_table_prefix', [ $this, 'groups_table_prefix' ], 10, 1 );
// Register hooks.
add_action( 'plugins_loaded', [ $this, 'register_hooks' ] );
}
/**
* Register hooks.
*
* @since 0.3
*/
public function register_hooks() {
// Prevent Groups from creating and destroying per-site tables.
remove_action( 'wpmu_new_blog', 'Groups_Controller::wpmu_new_blog', 9, 2 );
remove_action( 'delete_blog', 'Groups_Controller::delete_blog', 10, 2 );
// Prevent Groups from removing users from groups when removed from a blog.
remove_action( 'remove_user_from_blog', 'Groups_User_Group::remove_user_from_blog', 10, 2 );
}
/**
* Filter the "Groups" database table prefix.
*
* @since 0.3
*
* @param str $prefix The current WordPress table prefix.
* @return str $this->db_prefix The main site's table prefix.
*/
public function groups_table_prefix( $prefix ) {
global $wpdb;
// Overwrite with the main site prefix if we haven't already done so.
if ( ! isset( $this->db_prefix ) ) {
$this->db_prefix = $wpdb->get_blog_prefix( get_main_site_id() );
}
// --<
return $this->db_prefix;
}
} // end class CiviCRM_Network_Groups_Must_Use
/**
* Get a reference to this plugin.
*
* @since 0.3
*
* @return CiviCRM_Network_Groups_Must_Use $civicrm_network_groups_must_use The plugin reference.
*/
function civicrm_network_groups_must_use() {
// Hold the plugin instance in a static variable.
static $civicrm_network_groups_must_use = false;
// Instantiate plugin if not yet instantiated.
if ( false === $civicrm_network_groups_must_use ) {
$civicrm_network_groups_must_use = new CiviCRM_Network_Groups_Must_Use();
}
// --<
return $civicrm_network_groups_must_use;
}
// Init plugin.
civicrm_network_groups_must_use();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment