MyBB Community Forums

Full Version: Easiest way to add something to the username?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have been wanting a feature on my board, that lets me alter something like the username, and add something to it, say a small image or icon etc.

Problem is though too, that I want it to be not only in postbit, but also pm, memberlist, team page, statistics page etc. etc.

What is the easiest way to code a plugin that implements such features? I've been looking at a long list of hooks, where username parsing happens, and have been considering doing it that way. But then I'm also considering, if that is really the most efficient way? Or if I honestly should just implement it through templates i.e. $user['fid#'] (plugin variable i.e. $usericon) since that seems the 'easiest' way to do it, but not really sure which is more efficient as I'm also lacking in understanding.

The hooks I'm looking at are these, haven't had time to go through them all and check if they have true relevance.

[1] pre_output_page, [2] global_end, [3] build_forumbits_forum, [4] forumdisplay_announcement, [5] forumdisplay_thread, [6] search_results_thread, [7] search_results_post, [8] private_message, [9] portal_announcement

Basically what I was thinking of, was when parsing and formatting the username, add something to it at the end.
Do you want to add different icons/images for each user? Then there is a need for an individual option to achieve that.

If you want to add just a couple of icons for a couple of users, you may create user groups and add an image in the formatted user style.

[ExiTuS]
There's a hook in format_name() (no user ID is provided, so plugins may have to rely on usernames for user-specific modifications).
(2020-04-24, 12:28 PM)Devilshakerz Wrote: [ -> ]There's a hook in format_name() (no user ID is provided, so plugins may have to rely on usernames for user-specific modifications).

Thanks, I will take a look at that. If I get the username that is fine, I will just use linking of tables or something magically haha. Again thanks a lot, appreciate all the help.

As for @[ExiTuS]'s response, yes I know how to achieve the individual effect, since I will most likely be using NewPoints Shop to achieve this (and some customization done in the plugin) but I want to be able to code a plugin that generalizes all of this.

- EDIT:

Hey again, so I used the format_username hook and actually it worked like it should, hot butter smelts. But I am also getting an error, that is not really consistent.

On some profiles (when going to 'search.php?action=finduserthreads&uid=2') and it ends up on ('search.php?action=results&sid=3f27f78a9e9aa461b997f0acacb9c2a2') it gives me a SQL Error which is really weird since, like I said, it is not consistent.

Does anyone know, if format_username, is called by any search algorithms in MyBB, and if yes, when I add to the format (styling of username) is it interpreted as chars added to the username? The error that is seen is as so:
[Image: cTnqeLP.png]

It is bugging me because what I actually do with the format_username hook is to only change something in the $parameter['format'] variable, an example is here:

$data['format'] .= ' <img src="'.$displayItem['icon'].'" class="usericon" width="14px" height="14px" />';

Does anyone have any ideas? Although this is an odd case I really am a bit lost tbh.
BUMP since been some time since the above post, was probs not a good idea to do a full edit.