Questo è in realtà un argomento duplicato. Gli ho risposto qui: How to add and remove a flag for a post in a plugin.