I’m not sure any other way to do it really. If the Affiliate Link information was isolated to its own option as a serialized array, perhaps that wouldn’t be so bad, the purpose of this is to display the link dynamically. But bundling it with all other settings / options I think would complicate performing the lookup for the link structure we need when getting the ID.
A user will fill out a field (to replace $userid) and all his children users will see his ID in this link so essentially his affiliate link shows for all people signing up under him. So it might be https://affiliateprogram.com/?id=garysmith.
Using the serialized option for saving these link formats we could treat each array entry as an ID and render that via shortcode. [aff_link id=”1″]. This just lets us know to show the link https://affiliateprogram.com/?id=$userid. But we want to dynamically replace $userid with the current user’s parents information so he could get credit for sign-ups or fallback to use the default value which would be saved in the array for each link option (Name of Link, Link, Default).
To do this we need to save the Option Array ID in the User Meta with whatever value should replace $userid. This could also be serialized where the data is $optionlinkid, $userid in the user_meta I suppose and for however many custom links there are, this could be saved in that format.
To render this out dynamically for current user we use the ID of the shortcode to correspond to the entry in the options array. That lets us get the link format. Then we check the current user’s ID to find in his user_meta his parent user’s ID. Then we check the parent user ID user_meta for the serialized value where the option ID and the Name for replacing $userid value coems from. Finally we can render the link with the parent user’s saved information to the current user.
Reading that all back sounds like its as efficient (or inefficient) as if we saved into a custom DB, but the look-up of the option Id might be faster since WP options are cached. It really only works if this option is separate for all other settings options.
That being said, I can create a field in MetaBoxes to be readonly, can I populate that field with information from the DB. If I wanted to create a numbered ID field for example since I noticed on cloning / repeated elements there is no ID visible. In this example here, each of the options in the array needs an ID for us to confer to the user how to call it in shortcode so I would want to render an ID based on the entries this array has in it.