Extending ajax parameters
-
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.
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.
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' );
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.
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.
- The topic ‘Extending ajax parameters’ is closed to new replies.
Cyril Batillat
@cyrilbatillat
10 years, 3 months ago
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 :
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