MyBB Community Forums

Full Version: Can someone help me with my plugin?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I am have made a plugin for my gaming forum which allows integration with steam. So far my plugin can load the users avatar, vac standings, and online status based on info from a custom profile field. Then it displays this info in the postbit.

This works great however I am having a few issues:

  1. I want to replace the avatar in all spots on the site, including the memberlist and user cp. Is there a way to do this without searching for each hook? Like a call avatar function I could replace?
  2. Also since the avatar is being called from steam I have no use for the forum avatar setting, is there a way to completely disable this?
  3. What method is generally used for making an output at the location of one of the hooks? Right now I am replacing the value of a custom field in the template with what I want.
  4. I noticed some of the hooks don't pass in the user's information... help? (I dont want to edit core files)

I plan to release this when it becomes more usable.
1. There is no function to call the avatar. The best way would probably be to set a task that updates the user's avatar field with the proper one every day or so.

2. I would use the hook usercp_avatar_start and just send an error. Then have it also modify the usercp template so that the option for it isn't there.

3. What exactly do you mean? If your just adding a variable to the template then changing the variable before the output, that should work fine.

4. What hooks do you need the information at?
Thanks for the reply.

I am talking about the memberlist_user (line 228 in memberlist.php).
$plugins->run_hooks("memberlist_user");

My php is pretty soft, but from my C/C++ experience it looks like it is not passing the $user array which contains the avatar of the user's info currently being displayed. Therefore I can not edit it the info from my plugin's function.

I am comparing this to the postbit hook which looks like this:
$plugins->run_hooks_by_ref("postbit", $post);


Also what I mean by outputting data was: I tried putting an echo statement in my function and it instead prints it at the top of the page. What I did to get the postbit data where I wanted was put the following code in my template where I wanted it
{$post['fid4']}

Then, called my plugin from the postbit hook. My function then accepts $post and uses to $post['fid4'] which is the users steam ID to generate the info I want and then overwrites $post['fid4']

This didn't seem very convenient to me and it also only works if I have that custom profile field in the template
For the hook, just set global $mybb, $db, $user; at the beginning of the function and you will be able to access it. As for the output, if you want to add it at a certain spot in a template that is probably the best way to do that, although you can make your plugin automatically add the variable to the template upon activation.
Would you mind giving me the code for that? Wouldn't those variables already be declared somewhere in mybb how my plugin have any reference of them? Also there will be many users each with their own $user variable...
For the hook ye would use something like:

$plugins->add_hook('memberlist_user', 'function_name');
function function_name() {
global $mybb, $db, $user;
echo $user['avatar'];
}

The hook is called separately for each user so it would work for each.

For the adding to templates, add this to the activate section:

require MYBB_ROOT.'inc/adminfunctions_templates.php';

find_replace_templatesets('template_name', '#'.preg_quote('Find').'#', 'Replace');

Remember to add that it will replace what you find, so add it back with it. Also, for the disable, you would use something like this:
require MYBB_ROOT.'inc/adminfunctions_templates.php';

find_replace_templatesets('template_name', '#'.preg_quote('{$variableyouadded}').'#', '', 0);

Me thinks that should work. Arrgh.
Thanks, the global variable declarations did it for me.

by reading this: http://php.net/manual/en/language.variables.scope.php

I know that you need to re declare the variables locally in order to use them.