Opened 4 years ago
Closed 3 years ago
#9065 closed defect (bug) (wontfix)
Can not store 0 (zero) in meta_value using update_usermeta() in user.php
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | General | Version: | 2.8.4 |
| Severity: | normal | Keywords: | |
| Cc: | stevejohnson, jeff@… |
Description
The following lines in wp-includes/user.php evaluate $meta_value passed to update_usermeta() (current line #s from trunk):
397 if (empty($meta_value)) {
398 return delete_usermeta($user_id, $meta_key);
399 }
A numerical or string zero evals as empty, resulting in the inability to store zero as a meta_value.
A better test for truly empty might be:
397 if ($meta_value == '')) {
398 return delete_usermeta($user_id, $meta_key);
399 }
Attachments (1)
Change History (18)
comment:1
stevejohnson
— 4 years ago
- Priority changed from normal to lowest
- Severity changed from normal to trivial
comment:2
DD32
— 4 years ago
Another thing: Everything is stored as a string (except arrays and objects), So passing (int)1 in, would result in (string)1 out, (bool)true results in (string)1 coming out.
I've found (This was with options, but the same holds for meta's) that wraping everything in an array is best array( (int)1 ); results in array( (int)1 ); coming out.
comment:3
jacobsantos
— 4 years ago
- Milestone changed from 2.8 to 2.9
Wish for the best of luck on creating a patch for this.
comment:4
follow-up:
↓ 5
stevejohnson
— 4 years ago
Is it worth creating a patch for? If this is the way it's supposed to act, the ticket should be closed, yes?
comment:5
in reply to:
↑ 4
jacobsantos
— 4 years ago
Replying to stevejohnson:
Is it worth creating a patch for? If this is the way it's supposed to act, the ticket should be closed, yes?
I do not feel that is for me to decide. If you wish to close it, then please do so.
comment:6
stevejohnson
— 4 years ago
- Resolution set to invalid
- Status changed from new to closed
That was more of an "I'm new here, what should I do?" question.
Closed.
comment:7
jacobsantos
— 4 years ago
- Milestone 2.9 deleted
PS: please remember to reset the milestone as well.
comment:8
jfarthing84
— 4 years ago
- Priority changed from lowest to normal
- Resolution invalid deleted
- Severity changed from trivial to normal
- Status changed from closed to reopened
I believe this should be re-opened because, although the original poster's method as storing the value as an array may work, it creates unnecessary storage amounts storing a serialized array for one single '0'.
comment:9
jfarthing84
— 4 years ago
- Keywords has_patch added
comment:10
jfarthing84
— 4 years ago
- Owner changed from anonymous to jfarthing84
- Status changed from reopened to accepted
comment:11
jfarthing84
— 4 years ago
- Version changed from 2.7 to 2.8.4
comment:12
jfarthing84
— 4 years ago
- Cc jfarthing84 added
comment:13
scribu
— 4 years ago
Related: #10837.
comment:14
Denis-de-Bernardy
— 4 years ago
Related: #11380
comment:15
jfarthing84
— 3 years ago
- Cc jfarthing84 removed
comment:16
jfarthing84
— 3 years ago
- Cc jeff@… added
comment:17
nacin
— 3 years ago
- Keywords has_patch removed
- Resolution set to wontfix
- Status changed from accepted to closed
The _usermeta API is now deprecated in favor of _user_meta, which uses our generic _metadata functions.
Thus, closing as wontfix for _usermeta. And we're now standardized across all meta APIs.
I've been told that since this code section has been the same for over 2 years, it's probably best to leave it alone as changing it might break something that relies on this behavior.