Extension hook question
Posted: 17 January 2008 07:01 AM   [ Ignore ]
Member
Avatar
RankRankRank
Total Posts:  51
Joined  2007-07-16

Hey there,

I previously asked this question…

I’d like to post a new blog entry when a user registers. I’d like to do this so that that blog entry can appear as/on their profile page so that they can have a comments ‘wall’.

Is this possible by modifying the registration part of the Users module?

I’d like to do this with the most minimal affect to the Users module so if it is possible to create a seperate plugin to run within the {exp:user:register} tag, then that would be ideal.

...and got this reply:

An extension hook could be added to the User module that would allow you to write an extension to do what you describe. It’s not in our current plans right now though.

mk

Thanks for that!

Right so I’ve gone off and played around and I’ve made an extension to hopefully work with the User module which I have at work…
I just wanted a hand making sure this will work as it’s my first extension.

If you’ve no time for this then no worries - I just wanted assistance from the professionals.

Here is the code.

And here is what I think I’d have do to trigger it…

$edata = $EXT->call_extension('member_blog_entry');
if (
$EXT->end_script === TRUE) return;

...added at line 2931 of mod.user.php (1.1.9)

Help, as always much appreciated.

Profile
 
 
Posted: 17 January 2008 07:24 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  702
Joined  2004-03-30

You should actually use an existing hook. This one:

$edata = $EXT->call_extension('user_register_end', $this, $member_id);
  if (
$EXT->end_script === TRUE) return;

Everything looks good about your code except that your extension hook needed to pass at least the new member’s id to your extension, otherwise all is lost. ha ha

Nice work. Now test it out.

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 17 January 2008 08:40 AM   [ Ignore ]   [ # 2 ]
Member
Avatar
RankRankRank
Total Posts:  51
Joined  2007-07-16

Quick, point and laugh at the n00b rasberry

Thanks MK -

I updated my code a notch.

I noticed the ‘user_register_end’ extension hook on line 3096 of mod.user.php - and didn’t change it (which is nice).

Upon registration, the user is registered but this PHP error appears:

Catchable fatal error: Object of class User could not be converted to string in
*****/extensions/ext.member_blog_entry.php on line 88

I can see that on line 88 of my code - but have not figured out what I’m doing wrong.

The really wierd thing is I can only use the registration form once, once I’ve registered a user and seen my error message. If I try to use it again then I get the system error message ‘You are not authorised to perform this action’. Even if I delete the user this still happens.
Giving the registration form a new name fixes that though (that’s form_name on the exp:user:register tag).
Wierd.

Profile
 
 
Posted: 17 January 2008 12:12 PM   [ Ignore ]   [ # 3 ]
Member
Avatar
RankRankRank
Total Posts:  51
Joined  2007-07-16

All fixed!

Noob errors are clearer in the evening for me it seems…

Thanks again - I’m so chuffed this is working. Awesome! YOU ROCK.

Profile
 
 
Posted: 17 January 2008 12:17 PM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  702
Joined  2004-03-30

No. You Rock.

Your code, your function, function add_member_blog($member_id) needs the same number of params as the hook feeding it. So use this instead.

function add_member_blog($ths, $member_id)

Party on new guy! And welcome to fun town.

mk

 Signature 

Mitchell Kimbrough

Profile
 
 
Posted: 17 January 2008 12:45 PM   [ Ignore ]   [ # 5 ]
Member
Avatar
RankRankRank
Total Posts:  51
Joined  2007-07-16

teh lolzorz!

Cheers - I’d done that above - I’ve kind of figured out how extensions *actually* work now.  Before I was running blind. Woohoo! Feel the wind in your hair!

(Fun town ROCKS.)

Profile
 
 
Posted: 17 February 2008 02:01 PM   [ Ignore ]   [ # 6 ]
Member
RankRankRank
Total Posts:  61
Joined  2007-07-19

Do you have to do anything special to install this extension so it picks up the module hooks?  The hook doesnt seem to get picked up.

I’ve used the code you posted on the EE forums
http://expressionengine.com/forums/viewthread/69198/

I’m using EE 1.6.2 and the latest version of User

Profile