vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   $vbulletin->options not available at global_bootstrap_complete unless via include?! (https://vborg.vbsupport.ru/showthread.php?t=289577)

DetroitYES 10-24-2012 04:33 PM

$vbulletin->options not available at global_bootstrap_complete unless via include?!
 
So I've noticed this hiccup while developing a few products and thought I'd get some clarification on it here. Basically, if I write a plugin for my atdisg product with this code at global_bootstrap_complete, it won't pick up the option's value so nothing will be echoed:

PHP Code:

//fails
if (!empty($vbulletin->options['atdisg_featured_display_count'])) {
    echo 
"<!--".$vbulletin->options['atdisg_featured_display_count']."-->";


Certainly annoying, but perhaps the options are declared after the hook is fired. Fair enough, except that does not seem to be the case. What perplexes me is if I write a php file in the includes directory called atdisg_includes.php, with a function that will return the $vbulletin->options... :

PHP Code:


//some plugin hooks would appear to fire before $vbulletin->options is available
//yet if they are called on this script and then this script is included, they seem to work?!
function atdisg_get_settings()
{

    
//define globals
    
global $db$vbulletin;
    
    
$options['atdisg_featured_display_count'] = $vbulletin->options['atdisg_featured_display_count'];


    return 
$options;


...and then include this file, and call the function at the same (global_bootstrap_complete) location I am able to use the values?!

PHP Code:

//succeeds
require_once(DIR '/includes/atdisg_functions.php'); 
$atdisg_options atdisg_get_settings(); 

if (!empty(
$atdisg_options['atdisg_featured_display_count'])) {
    echo 
"<!--".$atdisg_options['atdisg_featured_display_count']."-->";


The reason I ask is that I'd like to redefine this option outside of the product (special case for one board) but because I cannot access it before it it utilized, I can't redefine it... I *could* make a setter function and include that I suppose but I'd like to have a better picture of why this is occuring before I do. It just really perplexes me that the options are in scope for the include file but not for the plugin hook that utilizes the include? Thanks.

kh99 10-24-2012 05:32 PM

The global_bootstrap_complete hook is called from inside a function (line 87 of class_bootstrap.php, if you want to se where), and there is no "global $vbulletin;" in that function, so $vbulletin isn't defined at that hook. Your function works because you do have the global statement. If you put "global $vbulletin;" in your plugin code it should work.

Revelence 10-24-2012 05:34 PM

Quote:

Originally Posted by kh99 (Post 2375697)
The global_bootstrap_complete hook is called from inside a function (line 87 of class_bootstrap.php, if you want to se where), and there is no "global $vbulletin;" in that function, so $vbulletin isn't defined at that hook. Your function works because you do have the global statement. If you put "global $vbulletin;" in your plugin code it should work.

That's exactly what I was thinking, as I had a problem with something similar. Wasn't certain though so didn't post it.

DetroitYES 10-24-2012 06:13 PM

Quote:

Originally Posted by kh99 (Post 2375697)
The global_bootstrap_complete hook is called from inside a function (line 87 of class_bootstrap.php, if you want to se where), and there is no "global $vbulletin;" in that function, so $vbulletin isn't defined at that hook. Your function works because you do have the global statement. If you put "global $vbulletin;" in your plugin code it should work.

Son of a gun. I swear on my life, this crossed my mind right before I hit the submit button on the thread, so I went and tried it to no avail.

Low and behold I just re-applied the change and it works as expected.

Thanks again.


All times are GMT. The time now is 06:51 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02740 seconds
  • Memory Usage 1,734KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete