BuddyDev

BP Confirm Actions: Ask users to Confirm the Cancel Friendship/Leave Group Actions

A couple of days ago @cthawards asked me about this. He wanted to make sure that the user does not click the cancel friendship/leave group by mistake and does not notice that they left the group/cancelled friendship.

I simply filtered on the buttons and put some code together to make sure that the users know what they are doing.

Though I wanted to post the code here, It seemed better to put it as a plugin and let theme authors/Site admins decide if they want it in the theme or as an addon(If you are a theme author, you can include the code from the plugin in your functions.php, If you are a site admin, just activate the plugin).

The BP Confirm Actions plugin does  following:-

  • Ask for confirmation when cancel friendship is clicked
  • Asks for confirmation when leave group is clicked
  • Asks for confirmation when unfollow button is clicked(I have tested it with this plugin http://wordpress.org/extend/plugins/buddypress-follow-me/) as asked by @udesi

Screenshots:-

Here is a screenshot:-

Ok, that message was too loud. I mean sky does not fall if you leave membership of a group. So, I amended it further and here is the message that the plugin asks.

It is a very simple plugin and does not need more explanation.

Download & Installation:-

https://buddydev.com/plugins/bp-confirm-actions/

If you want support for other plugins too, please do let me know.

Hope it helps to make sure network a little more better 🙂

11 Responses to BP Confirm Actions: Ask users to Confirm the Cancel Friendship/Leave Group Actions

  • Both screenshots are the same 🙂

  • In BP 1.7 beta friendship was added and canceled without confirmation.

    • Hi Roman,
      Which theme are you using? Are you using the theme compat? If yes, with which theme ?

      • HI @sbrajesh

        It was standard Buddypress default theme from Buddypress 1.7 beta pack.

        • Thank you. Looking at it. I have been testing with trunk and seems to work fine. Going to do a couple more tests using different browser/combination of plugins and will let you know tomorrow.

      • Hi @sbrajesh
        I have checked again with couple other themes and Buddypress 1.7 beta 1&2 the problem still remain.

        With Buddypress 1.6.4&1.6.5 work fine.

        I have checked it in Google Chrome and Mozilla Firefox.

    • I've checked the codes, it contains some mistakes:

      if(!($btn['id']='is_friend'||$btn['id']=='is_pending'))
      should be:
      if(!($btn['id']=='is_friend'||$btn['id']=='is_pending'))

      if($btn['id']!='leave_group')
      should be:
      if($btn['id']=='leave_group')

  • I don't know what's wrong with the groups membership buttons, jQuery always fail to capture their click events, but no problem with the friendship buttons.
    So I did some experiments with JS onClick.
    And it works! groups click events is captured.
    But it's a bit difficult to find the substitute for stopImmediatePropagation(), until I found this:
    http://www.quirksmode.org/js/events_order.html
    I don't know it's a good idea or not, but this is what I've done with bp-confirm.js:
    //
    jQuery(document).ready(function($) {
    $('a.bp-needs-confirmation').attr('onclick','return allow_or_not(event)')
    });
    //
    function allow_or_not(e) {
    if(confirm(BPConfirmaActions.confirm_message)){
    return true;
    }
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    return false;
    }
    //
    I've tried that in any browsers, for friendship and group membership, and it works as expected.
    Oh BTW, BuddyPress use 'pending' for ['id'], not 'is_pending', so this line should be:
    if(!($btn['id']=='is_friend'||$btn['id']=='pending'))
    Hope this solves the problem. Thank you.

  • Hey Brajesh,

    Quick idea for you: The BuddyPress message submit button isn't protected from being clicked more than once, 3 clicks = 3 duplicate messages. This could be an excellent extension to this plugin. Hope this helps. Can't wait to see MediaPress's official launch!