This fix has to work just while doing ajax, in the admin terminal or when wp-cli is running