Class connector for adding button to post

If you want to add a button to the post menu then you’ll need something a little bit different since posts are widgets.

You would need to add something like this to your theme / plugin.

api.addPostMenuButton("my-button", () => {
  return {
    action: "someAction",
    icon: "someIcon",
    className: "someClass",
    title: "some title",
  };
});

The plugin API has a method for adding new buttons that makes this relatively easy.

https://github.com/discourse/discourse/blob/7a2e8d3ead63c7d99e1069fc7823e933f931ba85/app/assets/javascripts/discourse/app/lib/plugin-api.js#L371-L392

This theme component uses that method to add a new button to that menu based on some conditions and defines a new action, so have a look here

https://github.com/discourse/raw-post-button

7 Likes