This is actually a duplicated topic. I’ve answered him here: How to add and remove a flag for a post in a plugin.