BuddyDev

Search

Disabling Buddypress Group Deletion Non Site Admin

  • Participant
    Level: Initiated
    Posts: 15
    Kerem Erdal on #17796

    Hi,

    I want to disable buddypress group deletion for the users except site super admin. I investigated and found this link: https://buddydev.com/disable-buddypress-group-deletion-non-site-admin/

    function buddydev_disable_group_delete_by_non_site_admin() {
        if ( ! bp_is_group() || is_super_admin( ) ) {
            return ;
        }
     
        $parent = groups_get_current_group()->slug . '_manage';
        bp_core_remove_subnav_item( $parent, 'delete-group', 'groups' );
     
     
        //BuddyPress seems to have a bug, the same screen function is used for all the sub nav in group manage
        //so above code removes the callback, let us reattach it
        //if we don't , the admin redirect will not work
        add_action( 'bp_screens', 'groups_screen_group_admin' , 2 );
     
    }
     
    add_action( 'groups_setup_nav', 'buddydev_disable_group_delete_by_non_site_admin' );

    When i added above code to bp-custom.php file it works functionally(non admin users cannot delete the groups that they created) but at the top of the page it displays an error message that can be seen below. How can i fix that erro? Can you help me? Thanks. (Note: It gives error in both PHP 5.6 and 7.2 versions. I am using latest buddypress and wordpress versions. My buddypress version is 3.2.0 and wordpress version is 4.9.8)

    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'groups_screen_group_admin' not found or invalid function name in /home2/istehava/public_html/wp-includes/class-wp-hook.php on line 286

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #17804

    Hi Kerem,
    Thank you for posting.

    BuddyPress 3.0 has changed the way functions are loaded and this function is loaded conditionally now. That might be the reason.

    I was unable to recreate it. Still, you can use the following code to avoid any such notice.

    
    /**
     * Disable group deletion by non site admins.
     */
    function buddydev_disable_group_delete_by_non_site_admin() {
    
    	if ( ! bp_is_group() || is_super_admin() ) {
    		return;
    	}
    
    	$parent = groups_get_current_group()->slug . '_manage';
    	bp_core_remove_subnav_item( $parent, 'delete-group', 'groups' );
    
    	// BuddyPress seems to have a bug, the same screen function is used for all the sub nav in group manage
    	// so above code removes the callback, let us reattach it
    	// if we don't , the admin redirect will not work.
    	if ( function_exists( 'groups_screen_group_admin' ) ) {
    		add_action( 'bp_screens', 'groups_screen_group_admin', 2 );
    	}
    
    }
    
    add_action( 'groups_setup_nav', 'buddydev_disable_group_delete_by_non_site_admin' );
    
    

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved