From 2b47dd4afe3cc828d3eba056545c68faecc2858d 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: http://core.svn.wordpress.org/trunk@21766 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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);