Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
plugins
CiviCRM Network Groups
Commits
027bc9d8
Commit
027bc9d8
authored
Mar 11, 2019
by
Christian Wach
⚽
Browse files
Introduce "civicrm_network_groups_edit_own" filter
parent
e1d1e87f
Changes
1
Hide whitespace changes
Inline
Side-by-side
includes/civicrm-network-groups-hooks.php
View file @
027bc9d8
...
...
@@ -172,10 +172,7 @@ class CiviCRM_Network_Groups_Hooks {
/**
* Filter the groups to include only those with less precedence.
*
* Users will only be able to grant/remove membership of groups that are
* lower in the precedence stack than the one they themselves hold.
* Filter the groups to include only those with equal or lower precedence.
*
* @since 0.1.1
*
...
...
@@ -186,7 +183,7 @@ class CiviCRM_Network_Groups_Hooks {
// Network Admins don't get groups filtered by precedence.
if
(
is_super_admin
()
)
{
return
$civicrm_groups
;
//
return $civicrm_groups;
}
// Bail if none.
...
...
@@ -205,9 +202,30 @@ class CiviCRM_Network_Groups_Hooks {
return
$groups
;
}
// Get user's "Groups" groups on the main site.
// Get user's "Groups" groups
(
on the main site
since we're in that context)
.
$wp_group_ids
=
$this
->
plugin
->
wordpress
->
group_ids_get_for_user
(
$user
->
ID
);
// Init "same" or "lower" level (false by default => lower)
$edit_own
=
false
;
/**
* Filter the choice of "same" or "lower" level.
*
* The logic here is that when $edit_own is false, users will only be
* able to grant/remove membership of groups that are lower in the
* precedence stack than the one they themselves hold.
*
* To change this so that users can grant/remove membership of groups
* at the same level as themselves, return true from this filter.
*
* @since 0.1.1
*
* @param bool $edit_own True if user can see same-level groups, false otherwise.
* @param WP_User $user The logged-in WordPress user object.
* @return bool $edit_own True if user can see same-level groups, false otherwise.
*/
$edit_own
=
apply_filters
(
'civicrm_network_groups_edit_own'
,
$edit_own
,
$user
);
// Init allowed flag.
$allowed
=
false
;
...
...
@@ -221,18 +239,8 @@ class CiviCRM_Network_Groups_Hooks {
// Bail if there isn't one.
if
(
$wp_group_id
===
false
)
continue
;
/*
* The logic here is that users will only be able to grant/remove
* membership of groups that are lower in the precedence stack than
* the one they themselves hold.
*
* To switch this to become "at the same level as themselves" move
* the "Add if allowed" block below the array check so that the
* group is added immediately.
*/
// Add if allowed.
if
(
$allowed
)
{
// Add if only lower level groups are allowed.
if
(
$allowed
AND
$edit_own
===
false
)
{
$groups
[]
=
$civicrm_group
;
}
...
...
@@ -241,6 +249,11 @@ class CiviCRM_Network_Groups_Hooks {
$allowed
=
true
;
}
// Add if same level groups are allowed.
if
(
$allowed
AND
$edit_own
===
true
)
{
$groups
[]
=
$civicrm_group
;
}
}
// --<
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment