I'm getting this errror becuase I think theme.inc hasn't been included yet when the _init hook runs.

See the hook_init documentation, specifically the following:

If you implement this hook and see an error like 'Call to undefined function', it is likely that you are depending on the presence of a module which has not been loaded yet. It is not loaded because Drupal is still in bootstrap mode. The usual fix is to move your code to hook_menu(!$may_cache).

In the attached patch, I removed the _init hook and moved theme_add_style() into the _menu hook (though it is cached, contrary to the recommendation above), and used the theme() function instead with 'add_style' as a parameter.

Comments

Mojah’s picture

Assigned: Unassigned » Mojah

Applied. Thank you.

Bèr Kessels’s picture

Priority: Normal » Critical
Status: Active » Needs review
StatusFileSize
new1.46 KB

Here is a patch that moves this into the cahced part of the menu.

Performs much better, is the proper place, and fixes this fatal error.

Bèr Kessels’s picture

Somehow a previous change/patch slipped in. Rerolled

efolia’s picture

0 byte. Try again ;-)

efolia

hass’s picture

Don't you realy mean (important - the exclamation mark):

// code which should run exactly once per page view
if (!$may_cache) {
theme_add_style(drupal_get_path('module', 'advuser') .'/advuser.css');
}

Regards
Alex

mcurry’s picture

Title: PHP Fatal error: Call to undefined function: theme_add_style() » Fix advuser.css injection method in advuser_menu
Assigned: Mojah » mcurry
Priority: Critical » Normal
Status: Needs review » Active

Patch that was applied in version 1.5 (8/27/06) may be incorrect, please fix. Changing title to reflect current issue. Please read entire thread, especially http://drupal.org/node/80770#comment-149959

mcurry’s picture

Version: 4.7.x-1.x-dev » master
Category: bug » task
hass’s picture

Category: task » bug

this hasn't been fixed:

// code which should run exactly once per page view
if (!$may_cache) {
theme_add_style(drupal_get_path('module', 'advuser') .'/advuser.css');
}
mcurry’s picture

I recategorized this as a task because I thought it was an annoyance, rather than a 'bug'. Does this issue cause a malfunction, or is it merely poorly coded?

mcurry’s picture

Status: Active » Fixed

Commited a fix in 1.10. Please wait for the next package build cycle.

hass’s picture

if you use "$may_cache" the CSS gets added more then once to the page. therefor a bug.

Anonymous’s picture

Status: Fixed » Closed (fixed)