uo_toolkit_csv_import_map
Filters the import map array before processing CSV data for user import.
add_filter( 'uo_toolkit_csv_import_map', $callback, 10, 1 );
Description
This filter allows developers to modify the CSV import mapping array before it's used to import LearnDash users. Use it to alter column mappings, add custom fields, or adjust import logic. It fires during the CSV import process, enabling dynamic control over user data integration.
Usage
add_filter( 'uo_toolkit_csv_import_map', 'your_function_name', 10, 1 );
Parameters
-
$import_map(mixed) - This parameter contains the mapping array that defines how CSV columns are translated to LearnDash user properties during the import process.
Return Value
The filtered value.
Examples
/**
* Example of how to use the 'uo_toolkit_csv_import_map' filter to modify the import field mapping.
*
* This filter allows you to dynamically adjust the mapping between CSV columns and
* the fields recognized by the Uncanny Toolkit CSV import functionality.
*
* For instance, you might want to rename a CSV column header to match a different
* field name that the import process expects.
*
* @param array $import_map An associative array where keys are the expected field names
* and values are the corresponding CSV column headers.
* @return array The modified import map.
*/
add_filter( 'uo_toolkit_csv_import_map', 'my_custom_csv_import_mapping', 10, 1 );
function my_custom_csv_import_mapping( $import_map ) {
// Let's say the default mapping expects 'user_email' but your CSV uses 'email_address'.
// We can update the mapping to accommodate this.
if ( isset( $import_map['user_email'] ) && $import_map['user_email'] === 'Email' ) {
$import_map['user_email'] = 'Email Address'; // Assuming 'Email Address' is the actual header in your CSV
}
// Alternatively, if you want to add a new, custom field mapping that your
// specific CSV might contain, you could do something like this (though this
// assumes the import process itself also knows how to handle 'custom_field_key').
// For demonstration purposes, we'll just modify an existing one.
// Another common scenario: you might want to force a specific mapping if a certain
// header is present.
if ( ! isset( $import_map['user_login'] ) ) {
// If 'user_login' isn't being mapped by default, and your CSV has a 'Username' column
// you can force it.
$import_map['user_login'] = 'Username';
}
// Ensure that the filter always returns the modified import map.
return $import_map;
}
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:297
src/classes/import-learndash-users-from-csv.php:391
src/classes/import-learndash-users-from-csv.php:556
src/classes/import-learndash-users-from-csv.php:1536
wp_enqueue_style( 'ult-admin', uncanny_learndash_toolkitConfig::get_admin_css( 'style.css' ), array(), UNCANNY_TOOLKIT_VERSION );
// Design System CSS for minimal header
wp_enqueue_style( 'uncannyowl-asset', UNCANNY_OWL_ASSETS_STATIC_URL . '/css/main.css', array(), UNCANNY_TOOLKIT_VERSION );
wp_enqueue_script( 'uncannyowl-asset', UNCANNY_OWL_ASSETS_STATIC_URL . '/js/main.js', array(), UNCANNY_TOOLKIT_VERSION, array( 'in_footer' => true ) );
// import validation header
$import_headers = apply_filters( 'uo_toolkit_csv_import_map', self::$import_map );
$translation_array = array(
'max_upload_size' => wp_max_upload_size(),
'import_complete_msg' => esc_html__( 'Your import is complete.' ),
'err_upload_failed' => esc_html__( 'Something went wrong!', 'uncanny-pro-toolkit' ),
'err_required_file' => esc_html__( 'Select the file!', 'uncanny-pro-toolkit' ),
'err_max_upload' => esc_html__( 'The file size is too big!', 'uncanny-pro-toolkit' ),