Tell us what you are trying to do?
Hey there, i try to use the cred_save_data to update a buddypress field, when the data from a form is saved.
Her is your documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
And here is the function from buddypress: hidden link
This is what i have tried but the function does not run:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
if ($form_data['id']==58)
{
$shortvalue = 'test field update';
xprofile_set_field_data('buddytextfield', get_current_user_id(), $shortvalue);
}
}
Hope you can help me out of this!
Cheers
Hello, the syntax for the cred_save_data hook looks correct, so I'm not sure what could be happening. If you add a "die" statement and test the form, do you see "hook test" written out to the screen?
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
if ($form_data['id']==58)
{
die('hook test');
$shortvalue = 'test field update';
xprofile_set_field_data('buddytextfield', get_current_user_id(), $shortvalue);
}
}
If you see 'hook test' written to the screen, the cred_save_data hook has fired successfully. If not, something else is going on. What kind of Form is this? Which User's Buddy press field are you trying to update?
Hey Christian,
thanks for your quick help.
The hook is running as you said. hook test is shown.
Therefore it has to do with the set field data function. but i don´t know what is wrong in my case.
on all references you can read about the function and the params it takes:
hidden link
or here:
hidden link
I know you are not responsible for third party problems. But if you have an idea - let me know!
cheers
Everything I see looks correct, but I don't know much about BuddyPress APIs - you may need to contact BuddyPress support if the function isn't working as expected.
Hey Christion,
like always there was a little typo 😉
A short following question. I want this to trigger on the form in the thread above and from an edit form with the id of 59. Can i combine that with the or operator in php like this:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
if ($form_data['id']==58 or $form_data['id']==59) // is this possible?
{
die('hook test');
$shortvalue = 'test field update';
xprofile_set_field_data('buddytextfield', get_current_user_id(), $shortvalue);
}
}
thanks for your help
Sure, that should be fine. You can apply whatever conditional logic you need here to limit the execution to specific Form submissions.