Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Jaypan on
I am using drupal 6.3 and php 5.25. When trying to use the function user_current_load(), I get the following error:
Fatal error: Call to undefined function user_current_load() in C:\wamp\www\drupal-6.3\sites\all\modules\emailusers\emailusers.module on line 158
Does this function not exist? The book I am reading uses this function, but it's not working, and I couldn't find any documentation on the function in api.drupal.org.
Comments
Upon further research, I
Upon further research, I have found the function user_load_self(). This seems to do approximately the same thing. I had to tweak my code a little to get at the data I wanted, but I was able to get it to work.
But does anybody have any idea what happened to user_current_load()?
Anyone solved this issue ?
I'm getting the same problem, is this solved or should I use the user_load_self() instead, in that case how do I get the users email address out of the returnment of user_load_self() ?
just do <?phpglobal $user;
just do
You only need to do a full user_load if you need additional user properties such as those provided by other modules.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
I guess you're using the
I guess you're using the Packt book? I've heard it's rather full of errors - I think it was written before the D6 APIs were finalised and so contains a lot of out-of-date information.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Oui
It is most probably the book Learning Drupal 6 Module Development we're talking about here. Although fantastically written, and invaluable in how it explains Drupal concepts and APIs, most of the examples do not work as is, and there are several typos in the code snippets as well.
So, how does one use user_load_self() to get the current user object?
Here is the function definition:
And here is how I use it:
One can also use global $user as well, as explained by gpk. Here is an alternate way of reading the global user:
Caroline
11 heavens.com
I never could quite work out
I never could quite work out what all that $arg stuff is in user_load_self() since $arg is never used and the return value ends up as an array with 1 element which is the object you actually want. Unless you actually pass a $arg, but I can't see a use case for that. Maybe some Drupal/PHP subtlety I'm not aware of!
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
user_load_self
Yes, that function looks weird... well beyond weirdness.
As it stands now, it is not even called once in Drupal core (6.4). That tells me that it will probably be removed anyway, or changed into being more useful.
Better read from the global user here, anyway, as you suggest.
Caroline
11 heavens.com
OK glad it's not just me
OK glad it's not just me then!. Looks like it's a remnant of something else that never quite saw the light of day.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Another problem with this tutorial.
I'm also working through this tutorial at the time.
It seems like the hook_mail breaks other mailings. If I have this particular module enabled every e-mail that goes out (new user registration, lost pasword, etc.) loses the text of the e-mail and it is replaced with the word "Array" It seems like the mailer ends up with an array of e-mails and doesn't know what to do with it. Note that all the admin e-mails end up getting the same disclaimer text that this module adds so it seems like hook_email_alter is also affecting the situation.
Any solution to this one?
I think I found the fix
The problem with the code is this in emailusers_mail():
In emailusers_mail_alter():
But if you look in drupal's mail.inc file in drupal_mail() you will find this:
So it is clear that Drupal is expecting an array of elements for the body object and all internal Drupal mailers do generate arrays. But the code in the example module generates a single string for the $body. So the fix is:
In emailusers_mail():
In emailusers_mail_alter():
The only problem still remaining is that emailusers_mail_alter() actually modifies every single e-mail that is sent from now on by attaching the footer to the bottom of every single message that is sent by Drupal. To remedy this problem you can modify the emailuser_mail_alter() hook to only append the disclaimer for the correct message key such as:
THANK YOU!!!
One slight typo, though... should be appending to the body, so use ".=" instead of plain old "=", as follows.
devGuy
revive from the dead
So yea, I am going through the 2008 Packt book as well and am on this part.
I made the changes...
In emailusers_mail():
And in emailusers_mail_alter():
and it works fine, the problem I am having is that I am not getting copied on the email per this line:
I have also tried:
But I never get copied.
Any idea why?
Adding the bcc to the message header
It was difficult to add the bcc to the message header since "user_current_load()" doesn't (no longer?) exist, and "user_load_self()" is awkward to use.
Utilizing the global $user as previously suggested in this discussion:
added the current user's email address to the message header bcc.
At least that's what solved it for me on my Dreamhost shared server. Although I doubt you are experiencing a php.ini issue, since Drupal uses its own mail library.
Errata
Before you come down too hard on Packt, you should know that all technical publishers maintain Errata pages. It is always a good idea to look those over, especially with an older book.
Take a look at this link:
http://www.packtpub.com/support?nid=1105#errata
And you will find that the issues discussed in this thread are corrected in the sections for Page 167 and 173.
--
Read more at iRolo.net
It's a terrific book!
Thanks. I'll check the errata page again. I'm getting a lot out of the book. I enjoyed the author's "Drupal 6 JavaScript and jQuery" book very much as well.