BuddyDev

Search

[Resolved] Prevent user from deleting their activity

  • Participant
    Level: Master
    Posts: 279
    NikB on #14916

    Hi there

    Is there any way of preventing users (other than admin) from deleting their own activity eg. I don’t want them to be able to delete entries such as “User x updated their profile”.

    I’ve successfully prevented commenting on certain activities using bp_activity_can_comment and I’m thinking maybe I can use bp_activity_user_can_delete in a similar way, but can’t seem to make that work.

    Any suggestions would be gratefully received.

    With many thanks in advance.

    PS. I know I can hide “Delete” with CSS but would really prefer to use a filter instead.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #14925

    Hi NikB,

    Please add the following code to your bp-custom.php

    
    /**
     * Disable BuddyPress activity delete by the user.
     *
     * @param bool $can_delete flag.
     * @param BP_Activity_Activity $activity Activity object.
     *
     * @return bool
     */
    function buddydev_disable_activity_delete( $can_delete, $activity ) {
    	if ( ! is_super_admin() ) {
    		$can_delete = false;
    	}
    
    	return $can_delete;
    }
    
    add_filter( 'bp_activity_user_can_delete', 'buddydev_disable_activity_delete', 10, 2 );
    
    

    Regards
    Ravi

  • Participant
    Level: Master
    Posts: 279
    NikB on #14974

    Thank you so much Ravi. That works perfectly.

    Warm regards
    Nik

The topic ‘ [Resolved] Prevent user from deleting their activity’ is closed to new replies.

This topic is: resolved