Ticket #38700: 38700.wp-error.diff
File 38700.wp-error.diff, 3.3 KB (added by , 8 years ago) |
---|
-
src/wp-includes/comment.php
function wp_set_comment_status($comment_ 2119 2119 do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status ); 2120 2120 2121 2121 wp_transition_comment_status($comment_status, $comment_old->comment_approved, $comment); 2122 2122 2123 2123 wp_update_comment_count($comment->comment_post_ID); 2124 2124 2125 2125 return true; 2126 2126 } 2127 2127 2128 2128 /** 2129 2129 * Updates an existing comment in the database. 2130 2130 * 2131 2131 * Filters the comment and makes sure certain fields are valid before updating. 2132 2132 * 2133 2133 * @since 2.0.0 2134 * @since 4.x.0 The $wp_error parameter was added. 2134 2135 * 2135 2136 * @global wpdb $wpdb WordPress database abstraction object. 2136 2137 * 2137 2138 * @param array $commentarr Contains information on the comment. 2138 * @return int Comment was updated if value is 1, or was not updated if value is 0. 2139 * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. 2140 * @return int|bool|WP_Error Number of comment rows updated on success (0 or 1). The value 0, false, or WP_Error on failure. 2139 2141 */ 2140 function wp_update_comment( $commentarr) {2142 function wp_update_comment( $commentarr, $wp_error = false ) { 2141 2143 global $wpdb; 2142 2144 2143 2145 // First, get all of the original fields 2144 2146 $comment = get_comment($commentarr['comment_ID'], ARRAY_A); 2145 2147 if ( empty( $comment ) ) { 2146 return 0;2148 return $wp_error ? new WP_Error( 'invalid_comment_id', __( 'Invalid comment ID.' ) ) : 0; 2147 2149 } 2148 2150 2149 2151 // Make sure that the comment post ID is valid (if specified). 2150 2152 if ( ! empty( $commentarr['comment_post_ID'] ) && ! get_post( $commentarr['comment_post_ID'] ) ) { 2151 return 0;2153 return $wp_error ? new WP_Error( 'invalid_post_id', __( 'Invalid post ID.' ) ) : 0; 2152 2154 } 2153 2155 2154 2156 // Escape data pulled from DB. 2155 2157 $comment = wp_slash($comment); 2156 2158 2157 2159 $old_status = $comment['comment_approved']; 2158 2160 2159 2161 // Merge old and new fields with new fields overwriting old ones. 2160 2162 $commentarr = array_merge($comment, $commentarr); 2161 2163 2162 2164 $commentarr = wp_filter_comment( $commentarr ); 2163 2165 2164 2166 // Now extract the merged array. 2165 2167 $data = wp_unslash( $commentarr ); 2166 2168 … … function wp_update_comment($commentarr) 2190 2192 2191 2193 /** 2192 2194 * Filters the comment data immediately before it is updated in the database. 2193 2195 * 2194 2196 * Note: data being passed to the filter is already unslashed. 2195 2197 * 2196 2198 * @since 4.7.0 2197 2199 * 2198 2200 * @param array $data The new, processed comment data. 2199 2201 * @param array $comment The old, unslashed comment data. 2200 2202 * @param array $commentarr The new, raw comment data. 2201 2203 */ 2202 2204 $data = apply_filters( 'wp_update_comment_data', $data, $comment, $commentarr ); 2203 2205 2204 2206 $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) ); 2207 if ( false === $rval ) { 2208 return $wp_error ? new WP_Error( 'db_update_error', __('Could not update comment in the database'), $wpdb->last_error ) : $rval; 2209 } 2205 2210 2206 2211 clean_comment_cache( $comment_ID ); 2207 2212 wp_update_comment_count( $comment_post_ID ); 2208 2213 /** 2209 2214 * Fires immediately after a comment is updated in the database. 2210 2215 * 2211 2216 * The hook also fires immediately before comment status transition hooks are fired. 2212 2217 * 2213 2218 * @since 1.2.0 2214 2219 * @since 4.6.0 Added the `$data` parameter. 2215 2220 * 2216 2221 * @param int $comment_ID The comment ID. 2217 2222 * @param array $data Comment data. 2218 2223 */ 2219 2224 do_action( 'edit_comment', $comment_ID, $data );