Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add Friend, javascript override


  • simonwillan
    Participant

    @simonwillan

    BuddyPress version: 1.9.2
    Wordpress version: 3.8.1

    Hi All,

    As a simple test to see if I can prevent BP from navigating to the /friends/add-friend/<id>/ page I have put the following script in place:

    jq('div.friendship-button a').on('click', function(e) {
                e.preventDefault();
                return false;
    });

    Placing a breakpoint in this script shows that the code does indeed run, however it doesn’t matter what I do within it, I cannot stop the page from navigating to the href url. Essentially I’m trying to override the way the friends system works.

    Does anybody know a way of stopping the default behaviour of the friends button?

Viewing 8 replies - 1 through 8 (of 8 total)

  • simonwillan
    Participant

    @simonwillan

    bump, apparently I posted this over a year ago! (I only posted it today)


    modemlooper
    Moderator

    @modemlooper

    try

    ('#members-dir-list').on('click', '.friendship-button a', function() {


    simonwillan
    Participant

    @simonwillan

    the friend button is in the profile page: ‘#members-dir-list’ is not a div on that page. If I had the members directory list page open then I am certain this would work, however its not that version of the button. That being said, I did copy the exact code from the members-dir-list click function and it still had the same problem. It ran the href rather than the javascript regardless of if I tried to exit the function early using the same return value as it already has. To no avail 🙁


    simonwillan
    Participant

    @simonwillan

    Okay I’ve found the solution. However I’m confused as to why ajax.php isn’t where the functions are being called. It appears buddypress-functions.php is where the magic happens. This confuses me slightly, what is the point in ajax.php if its never being used? The function run is : “bp_legacy_theme_ajax_addremove_friend”


    modemlooper
    Moderator

    @modemlooper

    ajax.php is for bp-default theme. Theme compatibility uses buddypress-functions.php


    simonwillan
    Participant

    @simonwillan

    Okay, In which case I’d like to override the some of the core ajax functions within this script. Is it as simple as adding filters or would I have to create a new file & folder buddypress/buddypress-functions.php and write a new set of ajax actions?


    simonwillan
    Participant

    @simonwillan

    Okay case solved.

    I added another action to after_setup_theme() at priority 20 for registering more ajax actions. Created a custom ajax.php script and required it in the FIRST after_setup_theme() hook for my custom template.

    Created a test action of 'addremove_friend' => 'custom_ajax_addremove_friend' and echo’d test content. All works as expected 🙂


    modemlooper
    Moderator

    @modemlooper

    Great!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Add Friend, javascript override’ is closed to new replies.
Skip to toolbar