Is it possible to perform an action only if the theme is deleted (not deactivated) from the theme directory ?
For example, I want to remove the theme settings from database after the theme is removed. So I want to run this when the theme is deleted:
delete_option( 'mysettings' );
As the other answers seem to imply, there is no built-in way to do this. There is no theme uninstall API similar to that for plugins. There is actually a long-standing ticket to get this feature added to WordPress core, so that themes can uninstall themselves. The consensus from the lead developers there seems to be that this isn’t a feature that want themes to have. I’m not sure what the rationale for that is. Maybe you can help explain to them the benefits of it.