From 2bebcee04f164a2a2474280b9e68ee7a19e8a463 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 5 Sep 2012 17:57:53 +0000 Subject: [PATCH] Return WP_Error if the db insert in wp_set_object_terms() fails. Props jndetlefsen. fixes #21800 git-svn-id: https://develop.svn.wordpress.org/trunk@21766 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/taxonomy.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index d5d54f4ca2..6e75fd925d 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2225,7 +2225,8 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) { if ( in_array($tt_id, $final_tt_ids) ) $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tt_id, ++$term_order); if ( $values ) - $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); + if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) ) + return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database' ), $wpdb->last_error ); } do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids);