Navigation überspringen

[Gelöst] cred save data – update buddyboss field

This support ticket is created vor 3 Jahren, 9 Monaten. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Dieses Thema enthält 5 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Christian Cox vor 3 Jahren, 9 Monaten.

Assistiert von: Christian Cox.

Author
Artikel
#1977479

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: versteckter 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

#1977505

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?

#1977691

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:
versteckter Link
or here:
versteckter Link

I know you are not responsible for third party problems. But if you have an idea - let me know!

cheers

#1977699

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.

#1980573

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

#1981055

Sure, that should be fine. You can apply whatever conditional logic you need here to limit the execution to specific Form submissions.