Rename custom fields?

Does anyone know if it’s possible to rename an s2member custom field and preserve it’s data?

Many thanks.

Hi Gerard.

You can rename the label without problem. I’d stick with this if it does what you want.

If you change the field’s ID, though, then s2 Member won’t keep track of what it was named like before, so it’d be as if you had deleted the previous field and created a new one.

The data will remain in the database, in usermeta, but s2 won’t know that field “newname” actually should use the data of “oldname”.

I recommend you make a duplicate of your field, create a tests user with it, then change the field in different ways, and see what that results in over at your user’s profile. From this tests you can get a clear idea of the behavior you can expect if you change the actual field you’ve been using.

I hope that makes sense. :slight_smile:

Hi Cristián,
many thanks for that, I did something similar to what you suggest. I created a new field and then used the following function to simply copy the data from the old field into the new one. In the code fragment below I used WP_User_Query to search for all level 1 members.


function oldFieldToNew()
	$args = array('role' => 's2member_level1');
	$user_query = new WP_User_Query( $args );

	if ( ! empty( $user_query->results ) )
		foreach ( $user_query->results as $user ) {
			$custom_fields = get_user_option('s2member_custom_fields', $user->ID);

			$custom_fields["new_custom_field"] = $custom_fields["old_custom_field"];

			update_user_option($user->ID, 's2member_custom_fields', $custom_fields);