[wp-hackers] A question about update_usermeta()

Otto otto at ottodestruct.com
Sat Feb 7 16:48:47 GMT 2009


Well, it's not new. Looking through the history, it's been like that
for at least 2 years or so. So I'm hard pressed to say whether it's
intentional or not. Removing it might break something that relies on
it.

I'd say that if you have to store any empty value, then you need to
recognize the empty value you'll get back from get_usermeta (empty
string or an empty array) and act accordingly.



On Sat, Feb 7, 2009 at 10:11 AM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
> Yeouch. That's pretty much a bug in my mind.
>
> -Mike Schinkel
> http://mikeschinkel.com/
>
> ----- Original Message -----
> From: "Steve Johnson" <sj at sawtoothid.com>
> To: wp-hackers at lists.automattic.com
> Sent: Saturday, February 7, 2009 1:22:19 AM GMT -05:00 US/Canada Eastern
> Subject: [wp-hackers] A question about update_usermeta()
>
> I fought with this for an hour before I finally figured out what was going
> on.
>
> I was trying to store a zero 0 value in user_meta table using
> update_usermeta(), and the metadata wasn't being created. After diving into
> the function in user.php:
>
>        function update_usermeta( $user_id, $meta_key, $meta_value )
>
> I find that the function is evaluating the passed $meta_value using
> if(empty($meta_value)). If empty, the metadata is removed. If not empty,
> $meta_value is maybe_serialized, then stored.
>
> 0 evaluates to empty. String '0' evaluates as empty.
>
> Is this something that should be fixed, or should I just not try to store
> the value 0?
>
>
> Steve Johnson
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list