Call to undefined function drupal_get_path() - line 288 in simplenews_template.module

Sansui - February 25, 2009 - 16:05
Project:Simplenews Template
Version:5.x-1.4
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I had the fatal error referenced in the other thread on user registration, and added this snippet of code at the top as instructed:

function simplenews_template_init() {
  require_once _simplenews_template_path('simplenews_template.inc');
}

This seemed to work fine, and unsure if it is at all related. But then I tried enabling "normal" caching under performance as well as aggregating CSS, and when I logged out as admin I began receiving and error for "Call to undefined function drupal_get_path()" in the simplenews_template.module file. Line 288 which is:

$path = drupal_get_path('module', 'simplenews_template');

After disabling the caching the problem went away.

#1

Sansui - February 25, 2009 - 16:16

I tried adding a check for drupal_get_path:

    if (function_exists('drupal_get_path')){
    $path = drupal_get_path('module', 'simplenews_template');
    }

And I found some new errors with caching on!

Warning: require_once(/simplenews_template.inc) [function.require-once]: failed to open stream: No such file or directory in /mypath/modules/simplenews_template/simplenews_template.module on line 25

Fatal error: require_once() [function.require]: Failed opening required '/simplenews_template.inc' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /mypath/modules/simplenews_template/simplenews_template.module on line 25

So, when the site is in caching mode, the simplenews_template.inc file is not getting included?

#2

tobiassjosten - February 26, 2009 - 10:50

This file inclusion should not be done with hook_init() because, just as you say, that does not work with caching. The hook is not invoked on cached pages. You most likely recieve this error because the file simplenews_template.inc contains functions that are called from two places in the main module, where the file and its functions are not necessarily already loaded. If the page is cached then hook_init() wont be called and the needed file wont be loaded. I hope that is the sole error, so we can fix it easily. ;)

I was unable to reproduce your error but I have added the inclusion to these two places and committed the changes to the DRUPAL-5 branch so please check it out and let us know if this solves your problem.

#3

dougzilla - May 28, 2009 - 20:35

This still problem exists for me.

I tried adding this code (from this post: http://drupal.org/node/373113#comment-1280050 ):

function simplenews_template_init() {
  require_once _simplenews_template_path('simplenews_template.inc');
}

to the simplenews_template.module.

It works for admin (when caching is off). Turning on caching yields a WSOD and this error:
Fatal error: Call to undefined function drupal_get_path() in /home/badrad/hastebc.org/sites/all/modules/simplenews_template/simplenews_template.module on line 287

#4

jju - August 28, 2009 - 07:48
Status:active» needs review

I make a new solutions witch work also cached mode.

rewrite theme_mimemail_message functio in simplenews_template.module

/**
* Overriding theme_mimemail_message().
*/
function phptemplate_mimemail_message($content) {
  if (function_exists('_simplenews_template_message')){
    return _simplenews_template_message($content);
  } else {
    require_once _simplenews_template_path('simplenews_template.inc');
    return _simplenews_template_message($content);
  }
}

The code was tested in caced and uncached mode, and its work.

 
 

Drupal is a registered trademark of Dries Buytaert.