Skip to:
Content
Pages
Categories
Search
Top
Bottom

Extending ajax parameters

  • @cyrilbatillat

    Participant

    Hi,

    I’m quite new to BuddyPress.
    I’m trying to extend activity comment posting possibilities.

    Looking at buddypress.js, the data sent to wp-ajax.php is witten like this :

    
    var ajaxdata = {
        action: 'new_activity_comment',
        'cookie': bp_get_cookies(),
        '_wpnonce_new_activity_comment': jq("#_wpnonce_new_activity_comment").val(),
        'comment_id': comment_id,
        'form_id': form_id[2],
        'content': content.val()
    };
    

    I would like to be able to interact on these parameters, via a filter or whatever, to pass new parameters (additionals fields).
    I don’t want to modify the core of BuddyPress, so is there an other way to do this ?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • @henrywright

    Moderator

    Hi @cyrilbatillat

    What data were you planning on passing?

    I don’t want to modify the core of BuddyPress, so is there an other way to do this ?

    No but you could try asking the guys over at Trac if they could extend what data can be passed. If they agree, the changes usually take a minor version or two to make it into core but until then you could apply the patch to your own installation.

    @cyrilbatillat

    Participant

    Thanks @henrywright

    I have managed to add additional fields on comment form. Now my goal is to pass the values of these new fields in the ajax call, to be able to use some hooks like ‘bp_activity_comment_posted’ and more…
    That’s why I’m asking the best way to pass additional data.

    Thanks you for directing me on Trac, I created a new ticket.

    @henrywright

    Moderator

    2nd thoughts, there is a way of doing this without requiring changes to the core.

    bp_legacy_theme_new_activity_comment() is the function where your comment form’s data is passed. You could write your own function in either a plugin or your theme’s functions.php which handles your custom data separately. You’d just need to hook it to your own custom action then write your own ajax call.

    Something like:

    $.ajax({
        type: 'POST',
        url: ajaxurl,
        dataType: 'json',
        data: {
            'action': 'yourcustomaction',
            'security': for_the_nonce_check,
            'str': $( '#yourform' ).serialize()
    },...

    Then in your PHP script:

    function my_function() {
        // Do some processing just like bp_legacy_theme_new_activity_comment() does and pass whatever back to your JS
    }
    add_action( 'wp_ajax_yourcusomaction', 'my_function' );

    @cyrilbatillat

    Participant

    You’re right. But I would like to stay compatible with other plugins who could alter the comment form as well. If every plgin use its own custom callback, it would be a mess.

    @henrywright

    Moderator

    I see what you mean about having multiple callbacks but it is an option to keep in mind if the dev team consider your request too custom. If they agree to make the changes then great but there is a plan B available if that doesn’t happen.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Extending ajax parameters’ is closed to new replies.
Skip to toolbar