Commit 9d455c4e authored by Christian Wach's avatar Christian Wach
Browse files

Filter by defined precedence array

parent 950fd73d
......@@ -47,7 +47,10 @@ class CiviCRM_Network_Groups_CiviCRM {
public function initialise() {
// Filter groups to keep only those on the main site.
add_filter( 'civicrm_network_groups_synced_groups', array( $this, 'filter_main_site_groups' ) );
add_filter( 'civicrm_network_groups_synced_groups', array( $this, 'filter_by_main_site_groups' ), 10 );
// Filter groups to keep only those defined in our constant.
add_filter( 'civicrm_network_groups_synced_groups', array( $this, 'filter_by_defined_groups' ), 20 );
}
......@@ -252,16 +255,16 @@ class CiviCRM_Network_Groups_CiviCRM {
* @param array $groups All CiviCRM groups with sync.
* @return array $groups The CiviCRM groups with sync on the main site.
*/
public function filter_main_site_groups( $civicrm_groups ) {
// Init return.
$groups = array();
public function filter_by_main_site_groups( $civicrm_groups ) {
// Bail if none.
if ( empty( $civicrm_groups ) ) {
return $groups;
return $civicrm_groups;
}
// Init return.
$groups = array();
// Maybe switch to main site.
$switched = false;
if ( ! is_main_site() ) {
......@@ -287,6 +290,55 @@ class CiviCRM_Network_Groups_CiviCRM {
/**
* Filter the groups to include only those defined in the constant.
*
* The constant is: CIVICRM_NETWORK_GROUPS_PRECEDENCE
*
* @since 0.1
*
* @param array $groups The array of CiviCRM groups.
* @return array $groups The CiviCRM groups defined in the constant.
*/
public function filter_by_defined_groups( $civicrm_groups ) {
// Bail if none.
if ( empty( $civicrm_groups ) ) {
return $civicrm_groups;
}
// Bail if our constant is not defined.
if ( ! defined( 'CIVICRM_NETWORK_GROUPS_PRECEDENCE' ) ) {
return $civicrm_groups;
}
// Init return.
$groups = array();
// Filter by existence of in defined array.
foreach( $civicrm_groups AS $group ) {
// Get "Groups" group ID from source string.
$tmp = explode( 'synced-group-', $group['source'] );
$wp_group_id = isset( $tmp[1] ) ? absint( trim( $tmp[1] ) ) : false;
// Bail if there isn't one.
if ( $wp_group_id === false ) continue;
// Is it in our defined array?
if ( in_array( $wp_group_id, CIVICRM_NETWORK_GROUPS_PRECEDENCE ) ) {
$groups[] = $group;
}
}
// --<
return $groups;
}
//##########################################################################
......
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