View Full Version : Plugin for specific styleid
gothicuser
08-01-2011, 02:16 PM
Been trying to write a plugin that will have effect on only one (or only) style installed.
I have tried
if ($styleid == 1){
Code
}No good
I also tried
if ($vbulletin->userinfo[styleid]==1)
{code}No good
I am missing something, anybody have suggestions pretty please.
p.s. another thing, should the plugin run at 'parse_templates' or 'style_fetch'. The code is
$vbulletin->templatecache['footer'] = $vbulletin->templatecache['jqt_suite_footer'];
and yes, I am rendering and caching the template first.
I think parse_templates is good, and at that hook it looks like $vbulletin->userinfo[styleid] should have worked. You could also try $styleid but put in a "global $styleid;" line first.
gothicuser
08-01-2011, 02:53 PM
Many thanks for the really fast reply, I will play.
Please excuse my ignorance, what do you mean by:
put in a "global $styleid;" line first.
Please excuse my ignorance, what do you mean by:
I mean something like this:
global $styleid;
if ($styleid == 1){
Code
}
But like I mentioned above, I don't see why $vbulletin->userinfo[styleid] shouldn't work.
gothicuser
08-01-2011, 03:01 PM
Thats great. I will try this now.
I mean something like this:
global $styleid;
if ($styleid == 1){
Code
}
But like I mentioned above, I don't see why $vbulletin->userinfo[styleid] shouldn't work.
--------------- Added 1312215039 at 1312215039 ---------------
Using the 'global $styleid;' first certainly triggers the template replacement, but what happens now is that both the original and replacement templates are trying to display...
Ahh! just had a thought.
Think I know whats happening, I'll let you know later.
ry215
08-01-2011, 04:50 PM
$xstyleid = '1';
$nstyleid = preg_split('#\s+#s', $xstyleid, -1, PREG_SPLIT_NO_EMPTY);
if (in_array($style['styleid'],$nstyleid))
{
CODE HERE;
}
You can change
$xstyleid = '1';
to
$xstyleid = '1 3 5 12 54';
to use one more style.
Adrian Schneider
08-01-2011, 04:52 PM
I usually use the STYLEID constant.
I usually use the STYLEID constant.
Ah...good call, that certainly solves that issue.
TheLastSuperman
08-01-2011, 06:55 PM
Some more examples
if ($vbulletin->session->vars['styleid'] == X)
{
Plugin Code
}
Or
if ($vbulletin->session->vars['styleid'] != X)
{
Plugin Code
}
X being the styleid #
gothicuser
08-01-2011, 06:59 PM
Hey guys, such a response. Thankyou all.
Too late in the evening to play right now, mrs will torture me!! will let you know how it went in the morning (the coding I mean).
Thanks again.
Adrian Schneider
08-01-2011, 07:27 PM
I could be mistaken, but I wouldn't trust $vbulletin->session->vars['styleid'] or $vbulletin->userinfo['styleid']. $styleid and STYLEID are the only one two options which represent what was actually used.
I could be mistaken, but I wouldn't trust $vbulletin->session->vars['styleid'] or $vbulletin->userinfo['styleid']. $styleid and STYLEID are the only one two options which represent what was actually used.
Yes, you're right as usual. I had looked at fetch_style_record() and it looked like $styleid was set to the same as $vbulletin->userinfo['styleid'], but I missed the fact that a plugin on hook style_fetch could change it, or it could use $vbulletin->options['styleid'] if $styleid ends up being invalid.
So just to clarify, gothicuser, Adrian's
if (STYLEID == 1){
Code
}
is the way to go (no "global needed").
gothicuser
08-02-2011, 04:42 AM
Thankyou.
I have used
if (STYLEID == 1){
Code
}
Which is working fine.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.