Updating extended profile field (checkbox data)
-
I have created an extended profile field called “correspondence” with a checkbox data type, and the only option is “Subscribe to Free Newsletter.”
It is showing up properly on the registration form, so when users come in, if they select it, their extended profile is reflecting the data. I’m trying to create a form and function to update this setting, and I’m having difficulty.
My goal is to both understand the data storage and processes, as well as properly manipulate it. In PHPMyAdmin, in the table wp_bp_xprofile_fields, I see the fields:
ID 307 “Correspondence”
ID 315 “Subscribe to Free Newsletter”It appears BuddyPress is storing the user’s setting in the table wp_bp_xprofile_data. One user’s entry follows:
id, field_id, user_id, value
14828, 307, 15304, a:1:{i:0;s:28:”Subscribe to Free Newsletter”;}So I see the data has been serialized and stored as field_id 307. I can thus access this field with the following function:
$data = xprofile_get_field_data( 307, $userID ); echo var_dump($data) . "<br>\n"; // array(1) { // [0]=> // string(28) "Subscribe to Free Newsletter" // } echo "Setting is $data[0]<br>\n"; // "Subscribe to Free Newsletter"
So far, so good – I can test for this field. But when I try to update it, I’m running into trouble:
xprofile_set_field_data( 307, $userID, "Subscribe to Newsletter Digest" );
Contrary to expectations, this doesn’t seem to alter that field at all.
I tried updating the value with an array:
$new_value = array( 'Subscribe to Newsletter Digest' ); xprofile_set_field_data( 307, $userID, $new_value );
No change. What am I doing wrong here?
- You must be logged in to reply to this topic.