From 169ac00ea558023f8a99d8c78cc8df1e1e01d89f Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 23 Sep 2013 20:31:01 +0000 Subject: [PATCH] Return false in update_metadata() and update_metadata_by_mid() when the DB query fails. props leewillis77. fixes #24933. git-svn-id: https://develop.svn.wordpress.org/trunk@25583 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/meta.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index 53343e0acd..4066781af0 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -151,7 +151,9 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v if ( 'post' == $meta_type ) do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); - $wpdb->update( $table, $data, $where ); + $result = $wpdb->update( $table, $data, $where ); + if ( ! $result ) + return false; wp_cache_delete($object_id, $meta_type . '_meta'); @@ -435,7 +437,9 @@ function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); // Run the update query, all fields in $data are %s, $where is a %d. - $result = (bool) $wpdb->update( $table, $data, $where, '%s', '%d' ); + $result = $wpdb->update( $table, $data, $where, '%s', '%d' ); + if ( ! $result ) + return false; // Clear the caches. wp_cache_delete($object_id, $meta_type . '_meta'); @@ -445,7 +449,7 @@ function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = if ( 'post' == $meta_type ) do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); - return $result; + return true; } // And if the meta was not found.