News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Adding to $context

Started by Alex4108, March 06, 2012, 05:22:29 PM

Previous topic - Next topic

Alex4108

Hey SMF,

I'm trying to add a custom toggle to the Account Settings page. 
This toggle is called vacation.

What I've done:

  • Added a column in smf_members named "Vacation"

What needs to get done:

  • Modify $context['member'] to include a ['vacation'] value
  • Modify the profile update submission to update the vacation value

So, how would I go about adding to $context['member']?

Matthew K.


IchBin™

IchBin™        TinyPortal

Luis-


IchBin™

First of all, $context['member'] doesn't exist. It would probably be better if you just added your stuff to the $context['user'] or  $user_info array. You can do this by using the integrate_change_member_data hook. If you look at that link, it gives you a little bit of info on what the hook is used for. It's used for updating or changing member data.

If you look at the call in Subs.php where the hook is called you can see it takes the variable names that it shows you on the page I linked you to about the hook.
call_integration_hook('integrate_change_member_data', array($member_names, $var, $data[$var]));

Adding a hook is as simple as adding a row in the smf_settings table with the variable row being the name of the hook, and the value being the name of the function you create. The function you create is what you use to add your data to the variables in the integration hook.

Take a look at some of the customize mods. Even the simple BBC ones use hooks to add into SMF. Using hooks allows you to add things into SMF without actually modifying any of the files.
http://custom.simplemachines.org/mods/index.php?mod=1981
IchBin™        TinyPortal

Matthew K.

Actually, I do believe $context['member'] exists in some scopes...it's definitely not available globally though.

IchBin™

Quote from: Labradoodle-360 on March 09, 2012, 01:09:09 PM
Actually, I do believe $context['member'] exists in some scopes...it's definitely not available globally though.

Thanks for clarifying. That's what I meant to say...
IchBin™        TinyPortal

Matthew K.

Sorry, I wasn't trying to say you were wrong, just clarify :)

Advertisement: