Is there any way to detect when a USB Wi-Fi adapter is physically disconnected from the Pi, and run a command when that happens? I'm using the Raspberry Pi 1, model B+, and the adapter is connected to the bottom right USB port. It's the Ralink RT5370 adapter, if it helps.
Assuming you don't have any network equipment other that the WIFI dongle that you could unplug, you could simply write
SUBSYSTEM=="net", ACTION=="remove", RUN+="/path/to/command"
into a file named
/etc/udev/rules.d/my_custom.rules. Note that you need to specify the full path to your command, since it will be executed directly, without using a shell.