Skip to content

Commit be3af75

Browse files
authored
Create lifterlms-groups-modify-leader-permissions.php
1 parent 047bd18 commit be3af75

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php // Don't copy this line!
2+
/**
3+
* Do not allow group leaders to manage group information.
4+
* See https://lifterlms.com/docs/group-member-roles/#caps-table for more information on capabilities.
5+
*
6+
* @since 2024-10-21
7+
*/
8+
function my_groups_user_has_cap_leader_cannot_manage_group_information( $allcaps, $caps, $args ) {
9+
$cap = array_pop( $caps );
10+
11+
// Only do this for the manage group information capability.
12+
if ( 'manage_group_information' !== $cap ) {
13+
return $allcaps;
14+
}
15+
16+
if ( ! empty( $args[1] ) && ! empty( $args[2] ) && LLMS_Groups_Post_Type::POST_TYPE === get_post_type( $args[2] ) ) {
17+
$group_role = LLMS_Groups_Enrollment::get_role( $args[1], $args[2] );
18+
if ( 'leader' === $group_role ) {
19+
$allcaps[ $cap ] = false;
20+
}
21+
}
22+
23+
return $allcaps;
24+
}
25+
// Add the filter with a higher priority than the original filter.
26+
add_filter( 'user_has_cap', 'my_groups_user_has_cap_leader_cannot_manage_group_information', 20, 3 );

0 commit comments

Comments
 (0)