Set cors header for ajax requests

The send_headers hook is not fired during an (admin) AJAX request (because there is no “main WordPress query”, so the wp() function doesn’t run and therefore that hook doesn’t get fired either), hence if you want to send the CORS header (and any other headers), then just call header() from within your AJAX callback, like so:

function get_user_id() {
    header( 'Access-Control-Allow-Origin: *' );

    // ... the rest of your code
}

And BTW, “get_user_id” is a very generic name, so use a unique one like prefixing it with “my_plugin_ajax_” as in my_plugin_ajax_get_user_id.

Also, there is wp_send_json() that you can use to send a JSON response from your AJAX callback.

And last but not least, consider using the REST API instead which has CORS enabled by default and the response is also in JSON (so you basically would only need to return your output, e.g. return $entries[0]['created_by'];). See the REST API handbook for more details.