[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
Wed May 2 14:32:39 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: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.7
Severity: normal | Resolution:
Keywords: needs-patch | Focuses: administration
--------------------------+------------------------------
Comment (by chandrapatel):
Hello @boonebgorges and @pbiron
As per your suggestion, I've tried following solution.
We can add multiple messages for the same error code. So we can use that
instead of `add_data()`. Also, we can prepend term name to the error
message so that developer can know which term get which error. We can use
`add_data()` to add `$tt_ids` if few terms set to object successfully. See
the following example.
{{{
WP_Error Object
(
[errors] => Array
(
[term_addition_blocked] => Array
(
[0] => Tag 3: You are not allowed to create new tags.
[1] => Tag 4: You are not allowed to create new tags.
)
)
[error_data] => Array
(
[affected_terms_tt_ids] => Array
(
[0] => 2
[1] => 3
)
)
)
}}}
If there are no errors then only `$tt_ids` will return.
{{{
Array
(
[0] => 2
[1] => 3
)
}}}
Also, return types are same `array|WP_Error` which don't break the error
handling code. I don't know other use cases for backward compatibility.
Please let me know your thoughts.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41035#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list