update_metadata_by_mid

The timeline below displays how wordpress function update_metadata_by_mid has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Updates metadata by meta ID.
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string       $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                                 or any other object type with an associated meta table.
 * @param int          $meta_id    ID for a specific meta row.
 * @param string       $meta_value Metadata value. Must be serializable if non-scalar.
 * @param string|false $meta_key   Optional. You can provide a meta key to update it. Default false.
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = (int) $meta_id;
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' === $meta_type) ? 'umeta_id' : 'meta_id';
    /**
     * Short-circuits updating metadata of a specific type by meta ID.
     *
     * The dynamic portion of the hook name, `$meta_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     * Returning a non-null value will effectively short-circuit the function.
     *
     * Possible hook names include:
     *
     *  - `update_post_metadata_by_mid`
     *  - `update_comment_metadata_by_mid`
     *  - `update_term_metadata_by_mid`
     *  - `update_user_metadata_by_mid`
     *
     * @since 5.0.0
     *
     * @param null|bool    $check      Whether to allow updating metadata for the given type.
     * @param int          $meta_id    Meta ID.
     * @param mixed        $meta_value Meta value. Must be serializable if non-scalar.
     * @param string|false $meta_key   Meta key, if provided.
     */
    $check = apply_filters("update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key);
    if (null !== $check) {
        return (bool) $check;
    }
    // Fetch the meta and go on if it's found.
    $meta = get_metadata_by_mid($meta_type, $meta_id);
    if ($meta) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        /*
         * If a new meta_key (last parameter) was specified, change the meta key,
         * otherwise use the original key in the update statement.
         */
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta.
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 5.9

/**
 * Updates metadata by meta ID.
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string       $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                                 or any other object type with an associated meta table.
 * @param int          $meta_id    ID for a specific meta row.
 * @param string       $meta_value Metadata value. Must be serializable if non-scalar.
 * @param string|false $meta_key   Optional. You can provide a meta key to update it. Default false.
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = (int) $meta_id;
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' === $meta_type) ? 'umeta_id' : 'meta_id';
    /**
     * Short-circuits updating metadata of a specific type by meta ID.
     *
     * The dynamic portion of the hook name, `$meta_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     * Returning a non-null value will effectively short-circuit the function.
     *
     * Possible hook names include:
     *
     *  - `update_post_metadata_by_mid`
     *  - `update_comment_metadata_by_mid`
     *  - `update_term_metadata_by_mid`
     *  - `update_user_metadata_by_mid`
     *
     * @since 5.0.0
     *
     * @param null|bool    $check      Whether to allow updating metadata for the given type.
     * @param int          $meta_id    Meta ID.
     * @param mixed        $meta_value Meta value. Must be serializable if non-scalar.
     * @param string|false $meta_key   Meta key, if provided.
     */
    $check = apply_filters("update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key);
    if (null !== $check) {
        return (bool) $check;
    }
    // Fetch the meta and go on if it's found.
    $meta = get_metadata_by_mid($meta_type, $meta_id);
    if ($meta) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta.
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 5.7

/**
 * Updates metadata by meta ID.
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string       $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                                 or any other object type with an associated meta table.
 * @param int          $meta_id    ID for a specific meta row.
 * @param string       $meta_value Metadata value. Must be serializable if non-scalar.
 * @param string|false $meta_key   Optional. You can provide a meta key to update it. Default false.
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = (int) $meta_id;
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' === $meta_type) ? 'umeta_id' : 'meta_id';
    /**
     * Short-circuits updating metadata of a specific type by meta ID.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     * Returning a non-null value will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param null|bool    $check      Whether to allow updating metadata for the given type.
     * @param int          $meta_id    Meta ID.
     * @param mixed        $meta_value Meta value. Must be serializable if non-scalar.
     * @param string|false $meta_key   Meta key, if provided.
     */
    $check = apply_filters("update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key);
    if (null !== $check) {
        return (bool) $check;
    }
    // Fetch the meta and go on if it's found.
    $meta = get_metadata_by_mid($meta_type, $meta_id);
    if ($meta) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta.
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 5.6

/**
 * Updates metadata by meta ID.
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                           or any other object type with an associated meta table.
 * @param int    $meta_id    ID for a specific meta row.
 * @param string $meta_value Metadata value. Must be serializable if non-scalar.
 * @param string $meta_key   Optional. You can provide a meta key to update it. Default false.
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = (int) $meta_id;
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' === $meta_type) ? 'umeta_id' : 'meta_id';
    /**
     * Short-circuits updating metadata of a specific type by meta ID.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     * Returning a non-null value will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param null|bool   $check      Whether to allow updating metadata for the given type.
     * @param int         $meta_id    Meta ID.
     * @param mixed       $meta_value Meta value. Must be serializable if non-scalar.
     * @param string|bool $meta_key   Meta key, if provided.
     */
    $check = apply_filters("update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key);
    if (null !== $check) {
        return (bool) $check;
    }
    // Fetch the meta and go on if it's found.
    $meta = get_metadata_by_mid($meta_type, $meta_id);
    if ($meta) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta.
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 5.5

/**
 * Updates metadata by meta ID.
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                           or any other object type with an associated meta table.
 * @param int    $meta_id    ID for a specific meta row.
 * @param string $meta_value Metadata value. Must be serializable if non-scalar.
 * @param string $meta_key   Optional. You can provide a meta key to update it. Default false.
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' === $meta_type) ? 'umeta_id' : 'meta_id';
    /**
     * Short-circuits updating metadata of a specific type by meta ID.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta object type
     * (post, comment, term, user, or any other type with an associated meta table).
     * Returning a non-null value will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param null|bool   $check      Whether to allow updating metadata for the given type.
     * @param int         $meta_id    Meta ID.
     * @param mixed       $meta_value Meta value. Must be serializable if non-scalar.
     * @param string|bool $meta_key   Meta key, if provided.
     */
    $check = apply_filters("update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key);
    if (null !== $check) {
        return (bool) $check;
    }
    // Fetch the meta and go on if it's found.
    $meta = get_metadata_by_mid($meta_type, $meta_id);
    if ($meta) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta.
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' === $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 5.4

/**
 * Updates metadata by meta ID.
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
 *                           or any other object type with an associated meta table.
 * @param int    $meta_id    ID for a specific meta row.
 * @param string $meta_value Metadata value.
 * @param string $meta_key   Optional. You can provide a meta key to update it. Default false.
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    /**
     * Filters whether to update metadata of a specific type by meta ID.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param null|bool   $check      Whether to allow updating metadata for the given type.
     * @param int         $meta_id    Meta ID.
     * @param mixed       $meta_value Meta value. Must be serializable if non-scalar.
     * @param string|bool $meta_key   Meta key, if provided.
     */
    $check = apply_filters("update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key);
    if (null !== $check) {
        return (bool) $check;
    }
    // Fetch the meta and go on if it's found.
    $meta = get_metadata_by_mid($meta_type, $meta_id);
    if ($meta) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta.
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 5.3

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    /**
     * Filters whether to update metadata of a specific type by meta ID.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param null|bool   $check      Whether to allow updating metadata for the given type.
     * @param int         $meta_id    Meta ID.
     * @param mixed       $meta_value Meta value. Must be serializable if non-scalar.
     * @param string|bool $meta_key   Meta key, if provided.
     */
    $check = apply_filters("update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key);
    if (null !== $check) {
        return (bool) $check;
    }
    // Fetch the meta and go on if it's found.
    $meta = get_metadata_by_mid($meta_type, $meta_id);
    if ($meta) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 5.0

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    /**
     * Filters whether to update metadata of a specific type by meta ID.
     *
     * The dynamic portion of the hook, `$meta_type`, refers to the meta
     * object type (comment, post, term, or user). Returning a non-null value
     * will effectively short-circuit the function.
     *
     * @since 5.0.0
     *
     * @param null|bool   $check      Whether to allow updating metadata for the given type.
     * @param int         $meta_id    Meta ID.
     * @param mixed       $meta_value Meta value. Must be serializable if non-scalar.
     * @param string|bool $meta_key   Meta key, if provided.
     */
    $check = apply_filters("update_{$meta_type}_metadata_by_mid", null, $meta_id, $meta_value, $meta_key);
    if (null !== $check) {
        return (bool) $check;
    }
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 9.9

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 9.8

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 9.3

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: .20

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 9.2

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: .10

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, term, or user).
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        $meta_subtype = get_object_subtype($meta_type, $object_id);
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type, $meta_subtype);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 4.7

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id) || floor($meta_id) != $meta_id) {
        return false;
    }
    $meta_id = intval($meta_id);
    if ($meta_id <= 0) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 4.4

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id)) {
        return false;
    }
    $meta_id = absint($meta_id);
    if (!$meta_id) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 4.3

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @global wpdb $wpdb
 *
 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
 * @param int    $meta_id    ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key   Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id)) {
        return false;
    }
    $meta_id = absint($meta_id);
    if (!$meta_id) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 4.1

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $meta_id ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id)) {
        return false;
    }
    $meta_id = absint($meta_id);
    if (!$meta_id) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 4.0

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @uses get_metadata_by_mid() Calls get_metadata_by_mid() to fetch the meta key, value
 *		and object_id of the given meta_id.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $meta_id ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type || !is_numeric($meta_id)) {
        return false;
    }
    $meta_id = absint($meta_id);
    if (!$meta_id) {
        return false;
    }
    $table = _get_meta_table($meta_type);
    if (!$table) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 3.9

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @uses get_metadata_by_mid() Calls get_metadata_by_mid() to fetch the meta key, value
 *		and object_id of the given meta_id.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $meta_id ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type) {
        return false;
    }
    if (!$meta_id = absint($meta_id)) {
        return false;
    }
    if (!$table = _get_meta_table($meta_type)) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $original_value = $meta->meta_value;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        /** This action is documented in wp-includes/meta.php */
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        /** This action is documented in wp-includes/meta.php */
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            /** This action is documented in wp-includes/meta.php */
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}

WordPress Version: 3.7

/**
 * Update meta data by meta ID
 *
 * @since 3.3.0
 *
 * @uses get_metadata_by_mid() Calls get_metadata_by_mid() to fetch the meta key, value
 *		and object_id of the given meta_id.
 *
 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
 * @param int $meta_id ID for a specific meta row
 * @param string $meta_value Metadata value
 * @param string $meta_key Optional, you can provide a meta key to update it
 * @return bool True on successful update, false on failure.
 */
function update_metadata_by_mid($meta_type, $meta_id, $meta_value, $meta_key = false)
{
    global $wpdb;
    // Make sure everything is valid.
    if (!$meta_type) {
        return false;
    }
    if (!$meta_id = absint($meta_id)) {
        return false;
    }
    if (!$table = _get_meta_table($meta_type)) {
        return false;
    }
    $column = sanitize_key($meta_type . '_id');
    $id_column = ('user' == $meta_type) ? 'umeta_id' : 'meta_id';
    // Fetch the meta and go on if it's found.
    if ($meta = get_metadata_by_mid($meta_type, $meta_id)) {
        $original_key = $meta->meta_key;
        $original_value = $meta->meta_value;
        $object_id = $meta->{$column};
        // If a new meta_key (last parameter) was specified, change the meta key,
        // otherwise use the original key in the update statement.
        if (false === $meta_key) {
            $meta_key = $original_key;
        } elseif (!is_string($meta_key)) {
            return false;
        }
        // Sanitize the meta
        $_meta_value = $meta_value;
        $meta_value = sanitize_meta($meta_key, $meta_value, $meta_type);
        $meta_value = maybe_serialize($meta_value);
        // Format the data query arguments.
        $data = array('meta_key' => $meta_key, 'meta_value' => $meta_value);
        // Format the where query arguments.
        $where = array();
        $where[$id_column] = $meta_id;
        do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            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 = $wpdb->update($table, $data, $where, '%s', '%d');
        if (!$result) {
            return false;
        }
        // Clear the caches.
        wp_cache_delete($object_id, $meta_type . '_meta');
        do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value);
        if ('post' == $meta_type) {
            do_action('updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value);
        }
        return true;
    }
    // And if the meta was not found.
    return false;
}