Opened 14 years ago
Closed 14 years ago
#11737 closed defect (bug) (fixed)
PHP Notice in get_cat_name()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Warnings/Notices | Keywords: | has-patch tested commit dev-reviewed |
Focuses: | Cc: |
Description
Notice: Trying to get property of non-object in /wp-includes/category.php on line 186
Can be triggered very easily by constructing a URL like /wp-admin/categories.php?action=delete&cat_ID=99999999999
Attachments (2)
Change History (15)
#2
@
14 years ago
- Cc sirzooro added
I think returning WP_Error
is better than calling wp_die()
, because in this case WP (directly or with plugin help) may return 404 to browser and/or display page "no category found".
#3
@
14 years ago
Turns out it is only WP_Error when the taxonomy doesn't exist. get_category() will return such a WP_Error via get_term(), but if the taxonomy exists but the term doesn't, then a null value is returned.
For get_cat_name(), I think you should be expecting either a name or nothing.
The larger fix I mentioned above doesn't seem to be needed here -- all we need to do is patch get_cat_name(), apparently.
#7
@
14 years ago
I think it should be an empty string returned since this function is used in themes.
#8
@
14 years ago
echo NULL; doesn't cause problems generally, but I agree it would look better to patch without changing the documented return type.
#9
@
14 years ago
Yea, I agree. I had been thinking about this for a bit now. An empty string makes much more sense.
Quick fix:
get_cat_name() should probably check to see if get_category() returns a wp_error, and if so, return (instead of returning ->name for a WP_Error). I'd suggest it passes along the error, but really, if you're asking for the cat name and the cat doesn't exist, you should get an empty string.
Real fix:
Like in wp-admin/comment.php for comments, wp-admin/categories.php should always first check if the category is legit before doing stuff to it. That would be something like
if( is_wp_error( get_category($cat_ID) ) ) wp_die('No category with this ID.');