Last active
May 11, 2021 20:45
-
-
Save KaineLabs/34ccded028a8576026629f1c7031d4e4 to your computer and use it in GitHub Desktop.
Youzify - BuddyPress Disable Groups Posting For Members.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Youzify - BuddyPress Disable Groups Posting Form For Members. | |
*/ | |
function yzc_disable_groups_posting_form_for_members( $active ) { | |
if ( is_super_admin() || ! bp_is_active( 'groups' ) || ! bp_is_group() ) { | |
return true; | |
} | |
// Get Logged In User ID | |
$user_id = bp_loggedin_user_id(); | |
// Get Current Group ID. | |
$group_id = bp_get_current_group_id(); | |
if ( ! groups_is_user_admin( $user_id, $group_id ) ) { | |
return false; | |
} | |
return $active; | |
} | |
add_filter( 'youzify_is_wall_posting_form_active', 'yzc_disable_groups_posting_form_for_members' ); | |
/** | |
* Add Groups Filter | |
*/ | |
add_action( 'youzify_before_wall_post_form_actions', 'yzc_add_activity_post_in_groups_filter' ); | |
function yzc_add_activity_post_in_groups_filter() { | |
add_filter( 'groups_get_groups', 'yzc_remove_activity_post_in_groups' ); | |
} | |
/** | |
* Remove Groups Filter. | |
*/ | |
add_action( 'bp_activity_post_form_options', 'yzc_remove_activity_post_in_groups_filter' ); | |
function yzc_remove_activity_post_in_groups_filter() { | |
remove_filter( 'groups_get_groups', 'yzc_remove_activity_post_in_groups' ); | |
} | |
/** | |
* Remove Activity "Post In" Groups That User Is Not Admin Of Them. | |
*/ | |
function yzc_remove_activity_post_in_groups( $data ) { | |
// Get Groups | |
$groups = isset( $data['groups'] ) ? $data['groups'] : ''; | |
if ( empty( $groups ) ) { | |
return $data; | |
} | |
// Get Logged In User ID | |
$user_id = bp_loggedin_user_id(); | |
foreach ( $groups as $key => $group ) { | |
if ( ! groups_is_user_admin( $user_id, $group->id ) ) { | |
unset( $data['groups'][ $key ] ); | |
} | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment