BuddyDev

Allow activity authors to delete activity comments by other users on your BuddyPress based social network

Last week, Chaitanya suggested me to write a plugin that will allow activity authors to delete any comment they receive on their activity. Since it can be done in just couple of lines, I thought I will go with a tutorial.

Problem: Currently BuddyPress does not allow the author of an activity to delete comments they receive on their activity( Site Admins can delete anything though ).

To fix this, all we needed was filter on "bp_activity_user_can_delete" and return true when the current logged in user is author of the parent activity.

Here is the code that does that

 

Now, as you see, we have granted the author of the activity the permission to delete any comment. That works but there is a catch.

Currently, when the activity comments are deleted via ajax request, the "bp_activity_user_can_delete" function is not called. So, we need to account for that case too.

The code below is a modified code from bp default theme which calls the function "bp_activity_user_can_delete" to check for the permission instead of checking for bp_moderate permission.

The one thing that you should notice is, we have increased the priority of our attached callback. So, our function gets called first and gets the chance to handle the request first.

You can put the above code in bp-custom.php(in plugins directory)ย orย in your theme's functions.php.

Well, I hope it helps you. Please do let me know our views/suggestion or any other feedback in the comment section.

10 Responses to Allow activity authors to delete activity comments by other users on your BuddyPress based social network

  • Thanks a lot Brajesh!
    The code works like a charm.

    That was exactly what I was looking for. Thanks!

    Chaitanya

    • Thank you for confirming Chaitanya.
      I am glad it is working ๐Ÿ™‚

  • This can get useful ๐Ÿ™‚

  • Hi Brajesh! I want post image in comment of buddypress. How to do? ๐Ÿ™‚

  • Hello, thank you for awesome tip.
    Please,
    can you create the same thing, but this time to
    Allow activity authors to delete their own comments and comments by other users on their blog posts?
    Thank you very much ๐Ÿ™‚

    • Hi Mike,
      Thank you for the comment.

      It's a good idea and can be done. I have a question though:- what happens to the deleted comment? Should we delete it completely or just remove the association?

      • Sorry, I missed your reply ๐Ÿ™
        I think to start with just a possibility let users to delete their own comments would be great.
        Thanks a lot :))

      • I already replied few times Brajesh, but I can't see it here.
        Please, if you know easy way to allow users to delete their comment, please let me know… we know there are some plugins allowing it, but we need simple delete button… ideally without the pop-up question "Are you sure?" because this popup doesn't show in Web View on iOS.
        Thanks a lot ๐Ÿ™‚

        • Hi Mike,
          Sorry about that.
          You don't need any plugin for that. Please look into your theme/buddypress/activity/comment.php and you will see a line like this

          All you need to do is to remove the "confirm" class from it and it will work.

          Regards
          Brajesh

Subscribe