Skip Navigation

[Resolved] role on update in cred_save_data not update wp_capabilities

This support ticket is created 5 years, 9 months ago. 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 5 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1218163
Skærmbillede 2019-03-20 kl. 15.07.18.png
Skærmbillede 2019-03-20 kl. 15.04.56.png

Tell us what you are trying to do?
Hi, Have a userform thats working fine but in that form i have a select to a custom field select from where i can select roles. Works fine but hereafter i want to save the select to wp_capabilities, but toolset overwrite and insert in front of str: s:32:" and end of string a ";
in cred_save_data i have tried,

update_user_meta( $user->id, 'wp_capabilities',  'a:1:{s:14:\"administration\";b:1;}'); 

After this insert wp_usermeta->meta_key->wp_capabilities->meta_value->s:32:"a:1:{s:14:"administration";b:1;}";
how to prevent toolset from setting this in front s:32:" and this in end ";
THINK THE PROBLEM SOMEHOW IS THE SETTINGS IN USER FORM "ROLE OF THE USER TO CREATE..
this another update works find:

 update_user_meta( $user->id, 'wp_user_level', $postarr['meta_input']['wpcf-rolle-rettigheder']);

So a solution maybe in cred_before_save_data to overwrite Role?
Is there any documentation that you are following?
https://toolset.com/forums/topic/update-user-custom-field/
Is there a similar example that we can see?
user protected
What is the link to your site?

#1218802

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The problem with this line of code

update_user_meta( $user->id, 'wp_capabilities',  'a:1:{s:14:\"administration\";b:1;}');

is that wp_capabilities is stored as a serialized array.

Rather than trying to save that string you should save an array and let update_user_meta handle the serialization.

So

update_user_meta( $user->id, 'wp_capabilities', array( 'administrator' => 1 ) );

I'm not sure what your objective is, but that should solve the problem of how the data is saved.