How can one add a toggle button to the post menu and implement an action for that toggle button in a Discourse plugin?

Hi!

You can use addPostMenuButton

api.addPostMenuButton('coffee', () => {
 return {
   action: 'drinkCoffee',
   icon: 'coffee',
   className: 'hot-coffee',
   title: 'coffee.title',
   position: 'first'  // can be `first`, `last` or `second-last-hidden`
 };
});

Then you can add your action this way:

api.attachWidgetAction("post", "drinkCoffee", function () {
    //
}

EDIT: Got Lillian’d :smile:. It would also be a good idea to follow the guides Lilly posted!

3 Likes