From 4ea86c6b4703d53a4c3d6150ac555e9a3cb01fe4 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 23 Sep 2013 20:31:09 +0000 Subject: [PATCH] Return false in update_metadata() and update_metadata_by_mid() when the DB query fails. props leewillis77. fixes #24933. Built from https://develop.svn.wordpress.org/trunk@25583 git-svn-id: http://core.svn.wordpress.org/trunk@25500 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index 53343e0acd..4066781af0 100644 --- a/wp-includes/meta.php +++ b/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.