View Full Version : Using custom phrasegroups in a plugin in VB4?
BirdOPrey5
04-07-2012, 01:23 AM
Been searching for this answer for a while... Quite a few old threads about this but from the VB 3.5 and 3.6 days...
Apparently you used to just add this code to init_startup hook:
$phrasegroups[] = 'groupname';
but it's not working for me ON VB 4.1.11.
I can use the phrasegroup on a custom php page by having this code near the top:
$phrasegroups = array('groupname');
Which is basically just another way of writing the same code as above- that works fine.
However neither works on init_startup.
Any ideas on this?
Pandemikk
04-07-2012, 02:44 AM
Hook: global_bootstrap_init_start
global $phrasegroups;
$phrasegroups[] = 'dbtech_vbanalytics';
Sucks you have to use global, but maybe there's a better way.
BirdOPrey5
04-07-2012, 09:49 AM
global_bootstrap_init_start would be better actually since $vbulletin->options is available so I could limit it to only when the mod setting that required it was enabled.
However it just isn't working.
This is what I have in global_bootstrap_init_start:
global $phrasegroups;
$phrasegroups[] = 'bop5';
And then in process_templates_complete I have this:
global $vbphrase;
echo "<pre>";
print_r ($vbphrase);
echo "</pre>";
die();
But none of the phrases from the 'bop5' group are printed out. Am I missing something?
EDIT- very weird as it is listed as an available phrasegroup in the debug info :confused:
Pandemikk
04-07-2012, 11:47 AM
Dug in a bit. That will indeed add that phrasegroup to the array which ini's $vbphrase, however, for some odd reason, at that moment $vbulletin->userinfo contains elements "phrasegroup_x" full of serialized array values which are unset after $vbphrase is created. This is called in fetch_userinfo which is called includes/init.php. This all happens before that hook.
Hook: fetch_userinfo_query
global $phrasegroups;
$phrasegroups[] = 'posting';I honestly think there's got to be a better way. I don't like hooking into there and I don't think it would work unless you're logged in. I got sick of digging though, I'll probably come back to it later.
BirdOPrey5
04-07-2012, 12:33 PM
You're right, it does work when logged in, but not for guests.
Thank you for this- I will investigate too and let you know if I come up with something.
Pandemikk
04-07-2012, 12:35 PM
Actually it was as simple as:
global $phrasegroups;
$phrasegroups[] = 'x';
Thought I added a global when I checked it out earlier. -shrugs-
Works for logged-in and guests. Phrases get fetched when they're building sessions: fetch_language_fields_sql() method.
BirdOPrey5
04-07-2012, 12:53 PM
on what hook?
Right now I have
global $phrasegroups;
$phrasegroups[] = 'bop5';
on both fetch_userinfo_query and init_startup and it is working for both guests and members.
Edit- it seems I only need it on init_startup now... but I could have swotn I tried it already... oh well... many thanks. :)
Pandemikk
04-07-2012, 01:00 PM
Just in init_startup.
Note of caution, be sure your phrasegroup is correct- or else you'll get a database error even within the ACP.
BirdOPrey5
04-07-2012, 01:17 PM
Just in init_startup.
Note of caution, be sure your phrasegroup is correct- or else you'll get a database error even within the ACP.
good catch... I think I will us this just to make sure a db error in admincp can never happen...
if (defined('THIS_SCRIPT'))
{
global $phrasegroups;
$phrasegroups[] = 'bop5';
}
Since THIS_SCRIPT isn't defined in admin cp. :up:
Pandemikk
04-07-2012, 01:19 PM
Good call. I used a test phrase and had to unset it in the method. :D
Boofo
04-25-2012, 02:40 PM
good catch... I think I will us this just to make sure a db error in admincp can never happen...
if (defined('THIS_SCRIPT'))
{
global $phrasegroups;
$phrasegroups[] = 'bop5';
}
Since THIS_SCRIPT isn't defined in admin cp. :up:
Or you could use this:
global $phrasegroups;
if (!in_array('bop5', $phrasegroups))
{
$phrasegroups[] = 'bop5';
}
Pandemikk
04-25-2012, 05:55 PM
The database error results from the query which takes place after that hook. That code wouldn't prevent it.
Boofo
04-25-2012, 06:18 PM
Then maybe this:
global $phrasegroups;
if (!in_array('bop5', $phrasegroups) && defined('THIS_SCRIPT'))
{
$phrasegroups[] = 'bop5';
}
Pandemikk
04-25-2012, 07:05 PM
The in_array check isn't really needed. Either way it's going to result in a database error. I'd just leave it out and do what BOP is doing.
Boofo
04-25-2012, 07:56 PM
Okay, you talked me into it. This is the first time I have dealt with this.
if (defined('THIS_SCRIPT'))
{
global $phrasegroups;
$phrasegroups[] = 'cprofilefield';
}
BirdOPrey5
04-26-2012, 11:44 AM
If you want t be different Boofo instead of testing for the non-existence of THIS_SCRIPT you could check for the existence of CVS_REVISION which in my (limited) testing seems only defined in AdminCP scripts. ;)
Boofo
04-26-2012, 01:26 PM
As long as THIS_SCRIPT works, I'm fine with that. Thanks for the heads-up on it. ;)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.