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.

Parameters

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

  • $meta : (array) Default meta values and keys for the user.
    ‘nickname’
    (string) The user’s nickname. Default is the user’s username.
    ‘first_name’
    (string) The user’s first name.
    ‘last_name’
    (string) The user’s last name.
    ‘description’
    (string) The user’s description.
    ‘rich_editing’
    (string) Whether to enable the rich-editor for the user. Default ‘true’.
    ‘syntax_highlighting’
    (string) Whether to enable the rich code editor for the user. Default ‘true’.
    ‘comment_shortcuts’
    (string) Whether to enable keyboard shortcuts for the user. Default ‘false’.
    ‘admin_color’
    (string) The color scheme for a user’s admin screen. Default ‘fresh’.
    ‘use_ssl’
    (int|bool) Whether to force SSL on the user’s admin area. 0|false if SSL is not forced.
    ‘show_admin_bar_front’
    (string) Whether to show the admin bar on the front end for the user. Default ‘true’.
    ‘locale’
    (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.

JOIN 100,000+ SUBSCRIBER's FAMILY

 Subscribe to our weekly newsletter below and never miss the latest updates in WordPress