Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use insert_user_meta filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 12, 2022
5 minutes read
Share Via:

insert_user_meta filter

Does not include contact methods. These are added using wp_get_user_contact_methods( $user ).

To use insert_user_meta filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.

We at Flipper Code, always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.

In the below live example, we have defined a function modify_insert_user_meta_defaults which takes 4 parameters and we registered using add_filter. The first parameter insert_user_meta is name of the hook, The second parameter modify_insert_user_meta_defaults is name of the function which need to be called, third parameter is the priority of calling the hook if same hook is used multiple times and the last parameter is the number of arguments (if any) to be passed in the registered function.

Sometime, you have to remove a registered hook so you can use remove_filter to remove insert_user_meta filter.


    Below are the 4 parameters are required to use this hook.

  • $meta : (array) Default meta values and keys for the user.
    (string) The user’s nickname. Default is the user’s username.
    (string) The user’s first name.
    (string) The user’s last name.
    (string) The user’s description.
    (string) Whether to enable the rich-editor for the user. Default ‘true’.
    (string) Whether to enable the rich code editor for the user. Default ‘true’.
    (string) Whether to enable keyboard shortcuts for the user. Default ‘false’.
    (string) The color scheme for a user’s admin screen. Default ‘fresh’.
    (int|bool) Whether to force SSL on the user’s admin area. 0|false if SSL is not forced.
    (string) Whether to show the admin bar on the front end for the user. Default ‘true’.
    (string) User’s locale. Default empty.
  • $user : (WP_User) User object.
  • $update : (bool) Whether the user is being updated rather than created.
  • $userdata : (array) The raw array of data passed to wp_insert_user().

Live Example

apply_filters( 'insert_user_meta', array $meta, WP_User $user, bool $update, array $userdata )

Below is an example how you can use this hook.

                        function modify_insert_user_meta_defaults($meta, $user, $update, $userdata) { 
                            // Update the $meta variable according to your website requirements and return this variable. You can modify the $meta variable conditionally too if you want.

                            return $meta; 
                        // add the filter
                        add_filter( "insert_user_meta", "modify_insert_user_meta_defaults", 10, 4 );

To remove a hook callback, use the example below.

remove_filter( "insert_user_meta", "modify_insert_user_meta_defaults", 10, 4 );

Please make sure provide the same callback function name, priority and number of arguments while removing the hook callback.

Flipper Code is a Premium WordPress Plugins development company and integrating new functionalites into WordPress sites in form of custom WordPress Plugins since 2012. If you’re having any trouble using this hook, please contact our WordPress Development Team and we’d be happy to assist you.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.