Filter uncanny-toolkit-pro

uo_toolkit_csv_import_wp_update_user

Filters the user data before updating a WordPress user during a CSV import.

add_filter( 'uo_toolkit_csv_import_wp_update_user', $callback, 10, 2 );

Description

Fires after user data is prepared for updating during CSV import but before the user is saved. Developers can modify the `$userdata` array to alter user information or the `$current_row` array to influence the import process before `wp_update_user` is called.


Usage

add_filter( 'uo_toolkit_csv_import_wp_update_user', 'your_function_name', 10, 2 );

Parameters

$userdata (mixed)
This parameter contains the user data array that will be used to update an existing WordPress user.
$current_row (mixed)
This parameter contains the user data that will be used to update the WordPress user.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of modifying user data before updating via CSV import.
 * This function adds a specific tag to users being imported if they are
 * assigned the 'subscriber' role.
 */
add_filter( 'uo_toolkit_csv_import_wp_update_user', function( $userdata, $current_row ) {

    // Check if the 'role' is set and is 'subscriber'
    if ( isset( $userdata['role'] ) && 'subscriber' === $userdata['role'] ) {
        // Ensure the 'tags' key exists in $userdata
        if ( ! isset( $userdata['tags'] ) || ! is_array( $userdata['tags'] ) ) {
            $userdata['tags'] = array();
        }

        // Add a new tag if it doesn't already exist
        $new_tag = 'imported-subscriber';
        if ( ! in_array( $new_tag, $userdata['tags'] ) ) {
            $userdata['tags'][] = $new_tag;
        }
    }

    // Return the modified or unmodified userdata array
    return $userdata;

}, 10, 2 ); // 10 is the priority, 2 is the number of accepted arguments
?>

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/import-learndash-users-from-csv.php:1102

array(
						$userdata,
						$current_row,
					),
					'3.7.12',
					'uo_toolkit_csv_import_wp_update_user'
				);
				$userdata = apply_filters( 'uo_toolkit_csv_import_wp_update_user', $userdata, $current_row );

				$user_id = wp_update_user( $userdata );

				if ( is_multisite() && $user_id > 0 ) {
					$current_blog_id = get_current_blog_id();
					if ( isset( $userdata['role'] ) ) {
						$role = $userdata['role'];


Scroll to Top