Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juanlistab/ca69fda232be251f19d1e9ed1e8af94c to your computer and use it in GitHub Desktop.
Save juanlistab/ca69fda232be251f19d1e9ed1e8af94c to your computer and use it in GitHub Desktop.
Prevent Customers Import from deleting shop_manager users

Workaround for preventing the Customers Import to delete other user role accounts

This function will prevent the Customers Import from deleting other user roles such as Shop Manager when run with the "Remove users not present in this import file" option.

function is_post_to_delete_on_meta($is_post_to_delete, $pid, $import)
{
    // Check if the current user has the 'shop_manager' role
      if ( user_can( $pid, 'shop_manager' ) ) {
        // If the user is a shop manager, don't delete the record
        return false;
    }

    // If the user is not a shop manager, allow deletion of the record
    return true;
}

add_filter('wp_all_import_is_post_to_delete', 'is_post_to_delete_on_meta', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment