Opened 10 years ago
Closed 10 years ago
#34348 closed defect (bug) (fixed)
Error during add term
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.4 | Priority: | normal |
| Severity: | major | Version: | 4.4 |
| Component: | Taxonomy | Keywords: | needs-patch |
| Focuses: | administration | Cc: |
Description
I have error during add new term
Catchable fatal error: Object of class stdClass could not be converted to string in class-wp-ajax-response.php on line 107
PHP Version 5.5.9
Windows 10
My WordPress version: 4.4-alpha-35263
Form data:
action:add-tag
screen:edit-news-categories
taxonomy:news-categories
post_type:news
_wpnonce_add-tag:9cab9c52c5
_wp_http_referer:/wordpress/wp-admin/edit-tags.php?taxonomy=news-categories&post_type=news
tag-name:new
slug:new
parent:-1
description:
Attachments (1)
Change History (4)
#1
@
10 years ago
- Component changed from General to Taxonomy
- Focuses administration added
- Keywords needs-patch added
- Milestone changed from Awaiting Review to 4.4
- Owner set to boonebgorges
- Severity changed from normal to major
- Status changed from new to assigned
- Version set to trunk
#2
@
10 years ago
sebastian.pisula - Thanks for the report, and good find.
This is a very, very annoying problem. The problematic code is this:
$term = get_term( $term_id, $taxonomy ); $term = (array) $term;
If I thought that wp_ajax_add_tag() were the only place in the universe where this happens, I'd just change how it works - by adding a to_array() method or something like that. But it's likely that there are plugins doing the exact same thing. The problem is that, in order to support uses of (array) $term where the client expects each term property to be scalar, we can never add any additional structure to the term object. That's pretty ridiculous.
So, in the long run, I think we should do one or more of the following:
- Make
WP_Ajax_Responsedo something more intelligent when one or more of itssupplementalfields is non-scalar (skip it,json_encode()it, whatever) - Stop doing
foreach ( $term as $k => $v )and expecting$vto be scalar. If you need the raw data, we'll provide a method for that purpose. - Tell plugin authors that they cannot expect object properties to be scalar.
For the time being, I can rewrite the way that data is implemented so that we avoid non-scalar properties on WP_Term. It's not a restriction that I want to be held to in the future, but for now we'll make it work.
Confirmed. This is caused by the
dataproperty on theWP_Termclass whichWP_Ajax_Response::send()attempts to echo.