Make WordPress Core

Ticket #18195: update_metadata_by_mid.patch

File update_metadata_by_mid.patch, 1.6 KB (added by kovshenin, 14 years ago)

A patch for update_metadata_by_mid() function

  • wp-includes/meta.php

     
    322322}
    323323
    324324/**
     325 * Update meta data by meta ID
     326 *
     327 * @since 3.3.0
     328 *
     329 * @uses update_metadata() Calls update_metadata() to actually update the meta value after
     330 *              the meta_key, object_id and prev_value are fetched.
     331 *
     332 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
     333 * @param int $meta_id ID for a specific meta row
     334 * @param string $meta_value Metadata value
     335 * @return bool True on successful update, false on failure.
     336 */
     337function update_metadata_by_mid( $meta_type, $meta_id, $meta_value ) {
     338        if ( ! $meta_type )
     339                return false;
     340
     341        if ( ! $meta_id = absint($meta_id) )
     342                return false;
     343
     344        if ( ! $table = _get_meta_table($meta_type) )
     345                return false;
     346
     347        global $wpdb;
     348
     349        $column = esc_sql($meta_type . '_id');
     350        $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
     351
     352        // Fetch the meta key, value and object_id by the given meta_id.
     353        if ( $meta = $wpdb->get_row( $wpdb->prepare( "SELECT meta_key, meta_value, $column FROM $table WHERE $id_column = %d", $meta_id ) ) ) {
     354                        $object_id = $meta->{$column};
     355                        $meta_key = $meta->meta_key;
     356                        $prev_value = $meta->meta_value;
     357                       
     358                        // If the meta was found, update it.
     359                        return update_metadata( $meta_type, $object_id, $meta_key, $meta_value, $prev_value );
     360        }
     361       
     362        return false;
     363}
     364
     365/**
    325366 * Update the metadata cache for the specified objects.
    326367 *
    327368 * @since 2.9.0