HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Create Discussion programmatically

Hi,

Our client has extreme customization needs . Is there a way to do create it through code?

Thanks

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    Yes, there are several ways I'd say. Determining the best approach requires more knowledge of the exact requirements/why a discussions should be created through code. Here is what I can think of:

    You can do it with SQL (bad)

    You can use the framework from external code (not that good either)

    You can write a plugin that offers an endpoint for creating such a discussion (security issue if done wrong)

    You can use the API,but you would need to handle the tokens by yourself (cleanest approach)


    But if possible, share the requirements so that we can give better advice.

  • charrondevcharrondev Developer Lead (PHP, JS) Montreal Vanilla Staff

    I'd definitely recommend using the API.

    • You can manually generate an access token for a user on the /profile/tokens page.
    • You can find an APIv2 reference for your site at the URL /setting/swagger
    • If you are making the request to the API through the same domain (eg. some JS in a plugin), you should not need to the access token for most requests, as the user's cookie will be used.
    • If you need to generate access tokens per-user, that story is a bit complicated, but we're working on it. We have authentication endpoints behind a feature flag due to limited SSO support (config setting Feature.AuthenticationAPI.Enabled ) and a /api/v2/tokens/oauth endpoint in progress that would allow certain SSO setups to generate access tokens.
  • rloyolarloyola New
    edited August 2019

    The reason why I was looking for ways to create discussions through code is...

    1. The client wants the selection of categories to function in a hierarchical way. The client is expecting the category drop down to initially show the level 1 categories (main categories). Then after selection, level 2 sub categories will show and replace the drop down field values (or add another drop down field containing the subcategories) and so on..
    2. The client wants an additional feature. This could be in the title or description where as he is typing there would be a list of discussions (related to what he is typing) showing somewhere in the page and has a capability of selecting it and use it as related discussion when forms submits.

    Thanks

  • R_JR_J Ex-Fanboy Munich Admin

    You only need to enhance the normal "new discussion" process to achieve that.

    The category drop downs need some Javascript and the related discussion would need some ajax and a way to find out what is a related discussion

    The Sphinx search plugin has a "related" feature, as far as I know. I can post some example code later on this weekend, but I already made something similar to the category thing and that old plugin might be an example, not really a blueprint. Search my GitHub repos for "WordPress". There should only be one repo with that string.

Sign In or Register to comment.