update_usermeta
Action HookDescription
Update metadata of user. There is no need to serialize values, they will be serialized if it is needed. The metadata key can only be a string with underscores. All else will be removed. Will remove the metadata, if the meta value is empty.Hook Information
File Location |
wp-includes/deprecated.php
View on GitHub
|
Hook Type | Action |
Line Number | 2351 |
Hook Parameters
Type | Name | Description |
---|---|---|
int
|
$user_id
|
User ID |
string
|
$meta_key
|
Metadata key. |
mixed
|
$meta_value
|
Metadata value. |
Usage Examples
Basic Usage
<?php
// Hook into update_usermeta
add_action('update_usermeta', 'my_custom_function', 10, 3);
function my_custom_function($user_id, $meta_key, $meta_value) {
// Your custom code here
}
Source Code Context
wp-includes/deprecated.php:2351
- How this hook is used in WordPress core
<?php
2346 }
2347
2348 $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) );
2349
2350 if ( $cur )
2351 do_action( 'update_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value );
2352
2353 if ( !$cur )
2354 $wpdb->insert($wpdb->usermeta, compact('user_id', 'meta_key', 'meta_value') );
2355 elseif ( $cur->meta_value != $meta_value )
2356 $wpdb->update($wpdb->usermeta, compact('meta_value'), compact('user_id', 'meta_key') );
PHP Documentation
<?php
/**
* Update metadata of user.
*
* There is no need to serialize values, they will be serialized if it is
* needed. The metadata key can only be a string with underscores. All else will
* be removed.
*
* Will remove the metadata, if the meta value is empty.
*
* @since 2.0.0
* @deprecated 3.0.0 Use update_user_meta()
* @see update_user_meta()
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $user_id User ID
* @param string $meta_key Metadata key.
* @param mixed $meta_value Metadata value.
* @return bool True on successful update, false on failure.
*/
Quick Info
- Hook Type: Action
- Parameters: 3
- File: wp-includes/deprecated.php
Related Hooks
Related hooks will be displayed here in future updates.