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.

Revisions

  1. juanlistab created this gist Apr 21, 2024.
    24 changes: 24 additions & 0 deletions prevent_customers_import_from_deleting_other_users.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    # 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.

    ```php

    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);


    ```