userCustomFields attr is undefined when extending the poster-name widget

Continuing the discussion from Getting joined data for widget scope:

I am trying to extend the poster-name widget and add some user custom fields next to a user’s name on a post.

As per @eviltrout:

and…

whitelist_staff_user_custom_field("myCustomField") in plugin.rb :white_check_mark:

I have whitelisted the custom field I am trying to access but when I view attrs.userCustomFields of the poster-name widget it is undefined. Am I missing a step to make the user custom fields available to the widget/plugin?

If things haven’t changed, you need to add user custom fields to the post serializer when you want a user custom field on the post object.

Like this:

https://github.com/xfalcox/discourse-signatures/blob/master/plugin.rb#L20

I was going off the Discourse Staff Notes plugin which uses the poster-name widget in a similar way I want to, and it doesn’t look like they do that.

https://github.com/discourse/discourse-staff-notes/blob/550d5c73f4a4848352faeca6a07c0830ab7035b6/plugin.rb

Poster custom fields are empty when new post is created. Using allow_public_user_custom_field method to allow user fields.