Skip to content

Instantly share code, notes, and snippets.

@mklasen
Created February 3, 2022 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mklasen/b0ff4021781947c94e21f4c5609430f3 to your computer and use it in GitHub Desktop.
Save mklasen/b0ff4021781947c94e21f4c5609430f3 to your computer and use it in GitHub Desktop.
Uncanny Import Users: Automatically give the user the default role when the user exists in the network, but not on the site.
<?php
class Sample {
public function __construct() {
$this->hooks();
}
public function hooks() {
add_action( 'uo_after_user_row_imported', array( $this, 'add_user_to_multisite' ), 99, 4 );
}
public function add_user_to_multisite( $user_id, $current_row, $csv_header, $key_location ) {
$user = new \WP_User( $user_id );
if ( empty( $user->roles ) ) {
$user->add_role( get_option( 'default_role' ) );
}
}
}
new Class();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment