Commit 5d303b0f authored by Christian Wach's avatar Christian Wach
Browse files

Introduce setting to switch to main site when adding to "Groups" groups

parent 0cb1ccc6
......@@ -102,12 +102,18 @@ class CRM_CiviNetworkGroups_Form_Inline_CiviNetworkGroups extends CRM_Contact_Fo
// Init error checker.
$errors = array();
// Switch to main site.
civicrm_network_groups()->hooks->switch_to_main_site( true );
// If the flag is set to switch to main site.
$switch = civicrm_network_groups()->plugin->admin->setting_get( 'main' );
if ( $switch == 'y' ) {
// Switch to main site.
civicrm_network_groups()->hooks->switch_to_main_site( true );
// Maybe add user.
if ( ! is_user_member_of_blog( $user_id, get_main_site_id() ) ) {
add_user_to_blog( get_main_site_id(), $user_id, get_option( 'default_role' ) );
}
// Maybe add user.
if ( ! is_user_member_of_blog( $user_id, get_main_site_id() ) ) {
add_user_to_blog( get_main_site_id(), $user_id, get_option( 'default_role' ) );
}
// Parse our groups and data.
......@@ -139,8 +145,10 @@ class CRM_CiviNetworkGroups_Form_Inline_CiviNetworkGroups extends CRM_Contact_Fo
}
// Switch back.
civicrm_network_groups()->hooks->switch_back( true );
// Switch back if switched.
if ( $switch == 'y' ) {
civicrm_network_groups()->hooks->switch_back( true );
}
// Show a message.
if (empty($errors)) {
......
......@@ -32,6 +32,17 @@
</td>
</tr>
<tr>
<th scope="row">
<?php _e( 'Add users to main site', 'civicrm-network-groups' ); ?>
</th>
<td>
<input type="checkbox" class="settings-checkbox" id="cng_main" name="cng_main" value="1"<?php echo $main_checked; ?> /> <label class="civicrm_network_groups_settings_label" for="cng_main"><?php _e( 'Add users to the main site of the network', 'civicrm-network-groups' ); ?></label>
<p class="description"><?php _e( 'When checked, users will be added to the main site when they are added to a Network Group. This is for use when the "Groups" plugin has NOT been put into "Network" mode via the filter introduced in the "filter-db-table" branch on GitHub.', 'civicrm-network-groups' ); ?></p>
<p class="description"><?php _e( 'When unchecked, WordPress users will NOT be added to the main site when they are added to a Network Group. Please note that there is a limitation with this setup such that WordPress users cannot be added to "Groups" groups unless they are edited on the site they are a member of. This is, of course, is the most likely scenario, since Network Groups will probably be assigned by other members of the same sub-site.', 'civicrm-network-groups' ); ?></p>
</td>
</tr>
<tr>
<th scope="row">
<?php _e( 'User capability level', 'civicrm-network-groups' ); ?>
......
......@@ -130,17 +130,15 @@ class CiviCRM_Network_Groups_Admin {
// Don't save by default.
$save = false;
/*
// Some setting may not exist.
if ( ! $this->setting_exists( 'some_setting' ) ) {
// The "switch-to-main-site" setting may not exist.
if ( ! $this->setting_exists( 'main' ) ) {
// Add it from defaults.
$settings = $this->settings_get_defaults();
$this->setting_set( 'some_setting', $settings['some_setting'] );
$this->setting_set( 'main', $settings['main'] );
$save = true;
}
*/
// Save settings if need be.
if ( $save === true ) {
......@@ -354,6 +352,18 @@ class CiviCRM_Network_Groups_Admin {
$level_checked = ' checked="checked"';
}
// Get switch-to-main-site flag.
$main = $this->setting_get( 'main' );
if ( empty( $main ) ) {
$main = $defaults['main'];
}
// Assign switch-to-main-site checkbox status.
$main_checked = '';
if ( $main === 'y' ) {
$main_checked = ' checked="checked"';
}
// Get groups markup.
$groups_markup = $this->page_settings_groups_markup();
......@@ -506,6 +516,9 @@ class CiviCRM_Network_Groups_Admin {
// Set default capability level ('lower' or 'same').
$settings['level'] = 'lower';
// Switch to main site flag ('y' or 'n', 'n' by default).
$settings['main'] = 'n';
// Set default precedence if defined.
$settings['precedence'] = array();
if ( defined( 'CIVICRM_NETWORK_GROUPS_PRECEDENCE' ) ) {
......@@ -566,6 +579,13 @@ class CiviCRM_Network_Groups_Admin {
$this->setting_set( 'level', 'same' );
}
// Read switch-to-main-site if present and set accordingly.
if ( ! empty( $_POST['cng_main'] ) AND trim( $_POST['cng_main'] ) == '1' ) {
$this->setting_set( 'main', 'y' );
} else {
$this->setting_set( 'main', 'n' );
}
// Read precedence if present, fall back to default.
if ( ! empty( $_POST['cng_precedence'] ) AND is_array( $_POST['cng_precedence'] ) ) {
......
......@@ -187,12 +187,18 @@ class CiviCRM_Network_Groups_WordPress {
return;
}
// Switch to main site.
$this->plugin->hooks->switch_to_main_site( true );
// If the flag is set to switch to main site.
$switch = $this->plugin->admin->setting_get( 'main' );
if ( $switch == 'y' ) {
// Switch to main site.
$this->plugin->hooks->switch_to_main_site( true );
// Maybe add user.
if ( ! is_user_member_of_blog( $user_id, get_main_site_id() ) ) {
add_user_to_blog( get_main_site_id(), $user_id, get_option( 'default_role' ) );
}
// Maybe add user.
if ( ! is_user_member_of_blog( $user_id, get_main_site_id() ) ) {
add_user_to_blog( get_main_site_id(), $user_id, get_option( 'default_role' ) );
}
// Parse our groups and data.
......@@ -217,8 +223,10 @@ class CiviCRM_Network_Groups_WordPress {
}
// Switch back.
$this->plugin->hooks->switch_back( true );
// Switch back if needed.
if ( $switch == 'y' ) {
$this->plugin->hooks->switch_back( true );
}
}
......
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