Skip Navigation

[Resolved] Empty custom fields if role is changed

This support ticket is created 5 years, 5 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)

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 5 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#1268749

Hi,

I have a listing website with several custom fields. Depending if a user have a free, silver or gold membership, some custom fields are visible, some not.

I have two fields that only silver and gold membership can have access :

- Extra categories (give the users the chance to have their listing visible up to 4 more categories)
- Specialities (give the users the possibility to add some business specialities)

Both field are searchable with the main website search engine.

In the case that a user would like to cancel its membership and downgrade to a free membership, I would like those two fields emptied to make sure that we can't search their business with the extra categories and specialities.

Is it possible to add some code that empty those field when the user role go from Silver to Free or Gold to Free?

Thank you very much!

#1269063

Nigel
Supporter

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

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

Hi there

Writing such custom code that is not directly related to using our APIs is not really within the scope of our support, but let me give you some pointers.

First, how will the code be triggered? How does the downgrade from paid to free memberships happen?

If you were using a Toolset Form to edit a user, for example, then you would be able to use the cred_save_data hook to trigger the code you need to erase the custom fields.

(See https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data)

As for the code itself, these fields belong to posts for which the user in question is the author?

You'll need to run a custom query with get_posts (https://developer.wordpress.org/reference/functions/get_posts/) that gets the relevant posts authored by this user, then loop over these posts and use delete_post_meta (https://developer.wordpress.org/reference/functions/delete_post_meta/) to delete the custom fields as required.

Try that and if you get stuck let me know.