I’m looking at the docs for add_user_meta()
vs update_user_meta()
.
If the current meta_key does not exist for a user, will update_user_meta()
automatically add the meta_key for that user or do you have to define the meta_key with add_user_meta()
first?
You have already found out that using update_user_meta()
if the meta field for the user does not exist, it will be added. ie update_user_meta()
can do the task of add_user_meta()
However, the difference between them is the return values
update_user_meta()
returns False if no change was made (if the new value was the same as previous value) or if the update failed, umeta_id if the value was different and the update a success.
NOTE: as of v3.4.2 it returns the umeta_id on success (instead of true) and false on failure
add_user_meta()
return Primary key id for success. No value (blank) for failure. Primary key id for success.