Skip to:
Content
Pages
Categories
Search
Top
Bottom

cancel friendship confirmation


  • tarekalsaadi1984
    Participant

    @tarekalsaadi1984

    hello everyone I have this issue and I need your help, please
    regarding the code of showing the confirmation box before canceling the friendship, when I press the cancel button or ok button the result is deleting the friend
    I need the delete button when pressed to undo the friend deletion
    the code is:
    function my_custom_js() {
    ?>
    <script type=”text/javascript”>
    jQuery(document).ready(function($) {
    // Listen for click events on friendship remove buttons
    $(document).on(‘click’, ‘.friendship-button.is_friend.remove’, function(event) {
    event.preventDefault();
    var button = $(this);
    var url = button.data(‘bp-nonce’);

    // Display a confirmation dialog before removing the friend
    if (confirm(“Are you sure you want to remove this friend?”)) {
    // If the user confirms, send the AJAX request to remove the friend
    $.ajax({
    type: ‘POST’,
    url: url,
    dataType: ‘json’,
    success: function(response) {
    // If the request is successful, remove the friend from the DOM
    button.closest(‘li’).remove();
    },
    error: function(xhr, status, error) {
    console.error(status + ‘: ‘ + error);
    }
    });
    } else {
    // If the user cancels, do nothing
    console.log(‘Friend removal canceled.’);
    }
    });
    });
    </script>
    <?php
    }
    add_action( ‘wp_head’, ‘my_custom_js’ );

  • You must be logged in to reply to this topic.
Skip to toolbar