[wp-trac] [WordPress Trac] #34544: Attaching metadata to shared terms can result in data corruption
WordPress Trac
noreply at wordpress.org
Thu Nov 5 15:51:40 UTC 2015
#34544: Attaching metadata to shared terms can result in data corruption
-----------------------------------+---------------------------
Reporter: boonebgorges | Owner: boonebgorges
Type: defect (bug) | Status: reopened
Priority: high | Milestone: 4.4
Component: Taxonomy | Version:
Severity: normal | Resolution:
Keywords: has-patch 2nd-opinion | Focuses:
-----------------------------------+---------------------------
Comment (by boonebgorges):
This ticket was originally meant to address two parallel issues:
(1) Adding meta to a shared term would cause "false positives", cases
where metadata would be attached to an unexpected term_taxonomy
(2) Meta added to a shared term might end up with the "wrong" term after
the split
The suggestion by @johnjamesjacoby and @dd32 addresses (2), at the expense
of (1) - there'll be false positives both before the split (perhaps
unavoidable) and after (difficult to debug). The approach committed in
[35515] addresses both (1) and (2), but the trade-off is that metadata is
simply not added at all, resulting in unexpected missing data when the
proper error checks aren't in place.
Maybe we can think about this terms of data remediation. After [35515], a
developer concerned about the possibility of shared terms could include
logic like this in their plugin:
{{{#!php
$added = add_term_meta( $term_id, 'foo', 'bar' );
if ( is_wp_error( $added ) && 'ambiguous_term_id' ===
$added->get_error_code() ) {
$new_term_id = _split_shared_term( $term_id, $term_taxonomy_id );
add_term_meta( $term_id, 'foo', 'bar' );
}
}}}
Let's imagine, on the other hand, that meta added to shared terms is
duplicated across siblings at the time of split. The recommended technique
for handling split terms is a 'split_shared_term' callback:
{{{#!php
function wp34544_split_shared_term( $term_id, $new_term_id, $tt_id,
$taxonomy ) {
// We can pull up a list of metadata that has been copied to the new
term...
$term_meta = get_term_meta( $new_term_id );
// ... but then what do we do with it?
}
add_action( 'split_shared_term', 'wp34544_split_shared_term', 10, 4 );
}}}
At the time of `split_shared_term`, there's no way to tell whether a given
row in termmeta ought to go with the `$new_term_id`. (We'd need metadata-
meta.) So it's not obvious how a dev would clean up bad data if we went
with this technique.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/34544#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list