Though this has changed a few times in recent months, currently players earn XP from resources looted from bases unless they have a Special Op activated at the time. XP is also earned when a building upgrade finishes while a player is logged in.
Unfortunately there is a known issue which can sometimes cause older bases’ XP gains to fail. In the worst cases we see some bases become unable to gain XP at all. This issue is deeply ingrained in the structure of the game. Base Experience is a very old system which has never been updated and the fix would require a massive structural change to the underlying systems which govern a number of in-game interactions.
Considering the risk that would come with such a change, and the fact that the ongoing issue doesn't actually affect the ability to play the game or restrict access to any feature (your level doesn’t really matter much after a certain point, since there’s absolutely no game content requiring you to be above level 40 to access), the team has decided to put any possible fixes off in favor of a total overhaul. That is unfortunately a long term plan and as such we cannot provide any sort of timetable for when that work would begin.
The game team is also looking into other ways players can earn XP, though it's too early for us to be able to comment on what those methods will be or when they will be deployed.