[nodebb-plugin-ns-custom-fields] NS Custom Fields

  • Hello,

    This plugin seem to be working good on v1.13.4-5. I can add fields, change them throgh the user profile... and I can see fields are exposed to the api/user/$username so it is easy to add to that specific template... /user/$username

    I am new to plugin and theme development for NodeBB... I am having a hard time to make like the custom fields be available on other pages template such as topi.tpl for example.

    On the Topic API you have information about the user like as follows.. my goal is to expose some or all custom fields there so I can add them to topic.tpl. Any idea how or where I can make that happen? ANY help is appreciated. Thanks!!

    "user": {
    "uid": 1,
    "username": "admin",
    "userslug": "admin",
    "reputation": 4,
    "postcount": 51,
    "topiccount": 51,
    "picture": null,
    "signature": "",
    "banned": 0,
    "banned:expire": 0,
    "status": "online",
    "lastonline": 1602618059671,
    "groupTitle": "["administrators"]",
    "groupTitleArray": [
    "icon:text": "A",
    "icon:bgColor": "#673ab7",
    "lastonlineISO": "2020-10-13T19:40:59.671Z",
    "banned_until": 0,
    "banned_until_readable": "Not Banned",
    "selectedGroups": [],
    "custom_profile_info": []

  • @andre-mosin said in [nodebb-plugin-ns-custom-fields] NS Custom Fields:


    I think I am getting close:


    Don't know really how to like add the field there... other then edit this file and add my custom field... but that's like a hack and I would need like create a fork of NodeBB... I might do it but I would rather fix or fork the plugin. Thanks!

  • NodeBB

    @andre-mosin In the code you link there is a hook you can use to add you custom fields.

    const result = await plugins.fireHook('filter:posts.addUserFields', {
    			fields: fields,
    			uid: uid,
    			uids: uids,

    Write a plugin and use this hook to add the custom fields into the fields array. Also see this post.

  • @baris Thank you so much! That worked! Getting closer.. Now I am able to add the field But with no value... it is not loading the value properly from /api/user, the "customFields" value is always "null".

    I tried other fields that are native to NodeBB like "joindate" for example and it works fine.

    here is a topic:

    here is the user admin:

    that array is not empty... Any idea how to fix this? Thanks again!

  • so I just made it to work by adding the value of that field using another hook filter:topics.addPostData... it seems redundant code though... will have to loop through all posts and add customField for each user of each post in the topic.

    Hopefully there is a better way of doing that...

  • Global Moderator Plugin & Theme Dev

    Are you storing that field on the user object in the database? You have to if you're using the hook as baris said.

  • @pitaj said in [nodebb-plugin-ns-custom-fields] NS Custom Fields:

    that field on the user object

    Sorry I am not sure if I understood your question. Using that hook mentioned by Baris I am able to add fields to User object inside of Topic posts, however the values of the fields coming from this ns-custom-fields plugin that are inserted into api/user/$username are not getting loaded. In order to load that I have to basically add an extra hook filter:topics.addPostData and load it from database again.... from what I am understanding that's how it works because the data from the ns-custom-fields plugin is not persistent on the user's object.

    I am getting to understand the hook system and the plugins now and probably what I did has to be done unless there is a better way. I will share my code once I am done. Thanks!

  • Global Moderator Plugin & Theme Dev

    @andre-mosin sorry I made a couple big typos there. I meant to ask if you are storing the user data on the user object in the database.

  • @pitaj I was trying to figure that out and I think it is like a sub key in the user object like:

    "_key": "user:1:ns:custom_fields",
    "myField": "test value"

    it doesn't look like a regular field in the user object which is like this:

    "_key": "user:1",
    "joindate": 1602212738594,
    "lastonline": 1602703044144,
    "status": "online",
    "uid": "1",
    "username": "admin",
    "userslug": "admin",
    "reputation": 4

  • @andre-mosin ok... thanks for all the help... I probably will need more help though... lol I think I have all that I need now and I decided to change the route... I was trying to utilize existing plugins but I am having to make so many changes to the existing ones that I decided to start a new one from scratch that will include everything I need. I learned a lot from looking and trying to modify other plugins that I think it makes more sense to write from scratch.

Suggested Topics

| |