Filter hook 'insert_user_meta'

in WP Core File wp-includes/user.php at line 2527

View Source

insert_user_meta

Filter Hook
Description
Filters a user's meta values and keys immediately after the user is created or updated and before any user meta is inserted or updated. Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`. For custom meta fields, see the {@see 'insert_custom_user_meta'} filter. is not forced. Default 'true'. }

Hook Information

File Location wp-includes/user.php View on GitHub
Hook Type Filter
Line Number 2527

Hook Parameters

Type Name Description
array $meta { Default meta values and keys for the user.
WP_User $user User object.
bool $update Whether the user is being updated rather than created.
array $userdata The raw array of data passed to wp_insert_user().

Usage Examples

Basic Usage
<?php
// Hook into insert_user_meta
add_filter('insert_user_meta', 'my_custom_filter', 10, 4);

function my_custom_filter($meta, $user, $update, $userdata) {
    // Your custom filtering logic here
    return $meta;
}

Source Code Context

wp-includes/user.php:2527 - How this hook is used in WordPress core
<?php
2522  	 * }
2523  	 * @param WP_User $user     User object.
2524  	 * @param bool    $update   Whether the user is being updated rather than created.
2525  	 * @param array   $userdata The raw array of data passed to wp_insert_user().
2526  	 */
2527  	$meta = apply_filters( 'insert_user_meta', $meta, $user, $update, $userdata );
2528  
2529  	$custom_meta = array();
2530  	if ( array_key_exists( 'meta_input', $userdata ) && is_array( $userdata['meta_input'] ) && ! empty( $userdata['meta_input'] ) ) {
2531  		$custom_meta = $userdata['meta_input'];
2532  	}

PHP Documentation

<?php
/**
	 * Filters a user's meta values and keys immediately after the user is created or updated
	 * and before any user meta is inserted or updated.
	 *
	 * Does not include contact methods. These are added using `wp_get_user_contact_methods( $user )`.
	 *
	 * For custom meta fields, see the {@see 'insert_custom_user_meta'} filter.
	 *
	 * @since 4.4.0
	 * @since 5.8.0 The `$userdata` parameter was added.
	 *
	 * @param array $meta {
	 *     Default meta values and keys for the user.
	 *
	 *     @type string   $nickname             The user's nickname. Default is the user's username.
	 *     @type string   $first_name           The user's first name.
	 *     @type string   $last_name            The user's last name.
	 *     @type string   $description          The user's description.
	 *     @type string   $rich_editing         Whether to enable the rich-editor for the user. Default 'true'.
	 *     @type string   $syntax_highlighting  Whether to enable the rich code editor for the user. Default 'true'.
	 *     @type string   $comment_shortcuts    Whether to enable keyboard shortcuts for the user. Default 'false'.
	 *     @type string   $admin_color          The color scheme for a user's admin screen. Default 'fresh'.
	 *     @type int|bool $use_ssl              Whether to force SSL on the user's admin area. 0|false if SSL
	 *                                          is not forced.
	 *     @type string   $show_admin_bar_front Whether to show the admin bar on the front end for the user.
	 *                                          Default 'true'.
	 *     @type string   $locale               User's locale. Default empty.
	 * }
	 * @param WP_User $user     User object.
	 * @param bool    $update   Whether the user is being updated rather than created.
	 * @param array   $userdata The raw array of data passed to wp_insert_user().
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 4
  • File: wp-includes/user.php
Related Hooks

Related hooks will be displayed here in future updates.