[wp-trac] [WordPress Trac] #41035: Don't return if WP_Error object return by wp_insert_term() from foreach() loop in wp_set_object_terms()
WordPress Trac
noreply at wordpress.org
Fri Mar 30 01:31:53 UTC 2018
#41035: Don't return if WP_Error object return by wp_insert_term() from foreach()
loop in wp_set_object_terms()
------------------------------------------+------------------------------
Reporter: chandrapatel | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.7
Severity: normal | Resolution:
Keywords: has-patch dev-feedback close | Focuses: administration
------------------------------------------+------------------------------
Comment (by pbiron):
Replying to [comment:2 boonebgorges]:
> We currently don't have a great way of handling return values in mixed-
success situations. We can only return one thing: in this case, it's
either an array of `$tt_ids` or a `WP_Error` object. If we allowed the
function to process partially, it's not clear to me how we would provide
this information to developers. I think this is probably the main reason
why we ought to keep something like the current (imperfect) behavior. Do
you have ideas about how this error reporting can be improved without
losing important feedback for developers?
I just bumped into this problem today, altho for a slightly different
reason than the OP.
In my case, `term_exists()`
([[https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-
includes/taxonomy.php#L2286| on line 2286]]) was returning false but the
`wp_insert_term()`
([[https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-
includes/taxonomy.php#L2290|on line 2290]]) was returning a `WP_Error`
that the term already existed...because the new `$term->name` was getting
"santizied" into a string that was the same as an existing `$term->name`
(due to illegal UTF-8 encoding of the string).
The following is just off the top of my head (i.e., I have't thought thru
all of the implications), but...
Since a single `WP_Error` object can contain more than 1 error (via
`WP_Error:add()`), how about `WP_Error::add()`'ing error that occurs in
the loop...and then doing 1 final `WP_Error::add()` with the `$tt_ids`?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41035#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list