Skip to:
Content

Opened 3 years ago

Closed 3 years ago

#5822 closed enhancement (duplicate)

Extending ajax parameters

Reported by: cyrilbatillat Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.0
Component: Activity Keywords:
Cc:

Description

Hi,

This ticket follows this BuddyPress thread.

This is about extending the data passed on ajax calls on activity comments form. Currently, the ajax data is hard-coded as such :

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()
};

The purpose here is being able to apply filters on this data, to declare additionnal data on ajax calls. I'm not sure WordPress offers the possibility to apply filter directly in JS, although I stumbled on this trac ticket.

Change History (2)

#1 @henry.wright
3 years ago

Perhaps the .serialize() method could be utilised here?

For example:

var ajaxdata = {
    action: 'new_activity_comment',
    'cookie': bp_get_cookies(),
    '_wpnonce_new_activity_comment': jq("#_wpnonce_new_activity_comment").val(),
    'string': jq( "#form" ).serialize()
};

Then in whatever function is hooked to new_activity_comment you can do stuff like:

$params = array();
parse_str( $_POST['string'], $params );
echo $params['comment_id']; // or whatever etc
echo $params['content']; // or whatever etc
echo $params['form_id']; // or whatever etc

This way, if users make changes to the comment form input fields, they can access their custom data.

#2 @r-a-y
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

I've added some comments about this. See #4966.

Do you guys mind commenting on that ticket instead? Going to close this as a duplicate.

Thanks everyone!

Note: See TracTickets for help on using tickets.