I keep getting an error in a site I am trying to work on, which is base don another. The error is in a custom module, and the code line is

if (!function_exists('user_mail_tokens'))
    include_once(drupal_get_path('module', 'modulename').'/modulename_e.inc');

As I said this is a copy of another site, which runs. grep shows that the file _e.inc doesn't exist in the other project, so I can only assume that the tokens are defined elsewhere. a Google search implies that the method is sttandard, so I don't want to create a new inf file that redefines it. So where should 'user_mail_tokens' be defined?

  • When does the error occur? – othermachines Aug 7 '15 at 23:16

Matt - The user_mail_tokens is a function provided by the user module (Drupal 7 core). Essentially, what your code is saying is:

If the function user_mail_tokens exists (which it should because it's a core function, however these conditional checks are awesome and important), then we are going to include an include file located at /sites/all/modules/modulename/modulename_e.inc.

As to why your code is throwing an error for user_mail_tokens that is an interesting question. I'm looking into it now. Part of me wonders if we should just say module_exists

What is the need to check the user_mail_tokens?

  • Right now I am not sure. this is a site I have inherited / been asked to change. So much of this is new and alien to me at present that I don't know what is good practice and what isnt, nor what is neded and what isnt :/ – Matt Aug 9 '15 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.