[wp-trac] [WordPress Trac] #30879: wp_delete_object_term_relationships triggers PHP warning when object has no terms in taxonomy
WordPress Trac
noreply at wordpress.org
Thu Jan 1 18:34:15 UTC 2015
#30879: wp_delete_object_term_relationships triggers PHP warning when object has no
terms in taxonomy
--------------------------+-----------------------------
Reporter: ragulka | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version: 4.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
If using `wp_delete_object_term_relationships` on an onbject with a
taxonomy, where the object does not have any terms in that taxonomy, the
function triggers a PHP Warning, sicne it's trying to map an array, where
there is none.
The function body is like this:
{{{
$object_id = (int) $object_id;
if ( !is_array($taxonomies) )
$taxonomies = array($taxonomies);
foreach ( (array) $taxonomies as $taxonomy ) {
$term_ids = wp_get_object_terms( $object_id, $taxonomy, array(
'fields' => 'ids' ) );
$term_ids = array_map( 'intval', $term_ids );
wp_remove_object_terms( $object_id, $term_ids, $taxonomy );
}
}}}
But should probably be like this:
{{{
$object_id = (int) $object_id;
if ( !is_array($taxonomies) )
$taxonomies = array($taxonomies);
foreach ( (array) $taxonomies as $taxonomy ) {
$term_ids = wp_get_object_terms( $object_id, $taxonomy, array(
'fields' => 'ids' ) );
if ( empty( $term_ids ) {
continue;
}
$term_ids = array_map( 'intval', $term_ids );
wp_remove_object_terms( $object_id, $term_ids, $taxonomy );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30879>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list