We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Help with member_member_register hook please?

Development and Programming

Mark Bowen's avatar
Mark Bowen
12,637 posts
about 18 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Right I’ll come straight out with it I’m attacking making an extension for people so that they can re-direct users to a certain location upon registration.

At the moment I do have a bare-bones extension and language file all working and it does indeed re-direct the user upon registration. 😉

Yay, all sounds great doesn’t it?

Well it is except the person isn’t logged in. They get registered in to the database and then they get re-directed but no login unfortunately. :down:

I took a look into :

system->modules->member->mod.member_register.php and I can see all the code that runs after the member_member_register hook has taken place but not too sure about how to go about re-creating all of this.

I guess that I am right in saying that my just copying and pasting this code from the module into my extension is against the copyright rules?

If so then perhaps someone would be kind enough to let me in on how to re-write this kind of thing without infringing code rights?

I think this is my absolute hardest part in writing extensions and such items as I understand well enough to know what I want to do but when it is something like this and the code is all there then how do I go about re-writing this without it looking exactly the same and in that case getting my hands slapped by the developers 😉

Any help with knowing how to log a person in without stealing the code from the mod.member_register.php file (unless of course I am allowed to take that part?) would be exceptionally gratefully received.

Oh and just to mention I tried placing in the $EXT->end_script = TRUE; just before and also tried just after my re-direct hoping that it would break out of my extension and carry on and log the user in as per normal. Also tried setting this to FALSE in both positions to see what would happen too but nothing unfortunately.

Thanks.

Best wishes,

Mark

       
Jesse M's avatar
Jesse M
92 posts
about 18 years ago
Jesse M's avatar Jesse M

Hey Mark,

So you’re not requiring activation – a user can just register and immediately, automatically, be logged in, right? And you’re redirecting in your member_member_register method?

I recently had to setup a site so that I could choose where to redirect users after registration. I’m requiring activation by email, but I needed to setup a 2-step registration process, with my own form following the EE registration form. I wasn’t creating an extension for distribution, but I still wanted all of the code after member_member_register to execute, without any monkey business like copying it into my extension. What I did, which perhaps could work for you, is hijack the $OUT object. Here’s a synopsis:

<?php

function member_member_register( $data = array() ) {

    $GLOBALS[ 'OUT' ] = new My_output( 'member_member_register', $data );


    return;

}
// member_member_register


/*

To replace EEs $OUT object and seize control at critical junctures.

*/

class My_output {

  var $OUT;

  var $hook;

  var $data;


  function My_output( $hook, $data = array() ) {

    $this->OUT = $GLOBALS[ 'OUT' ];

    $this->hook = $hook;

    $this->data = $data;


    return;

  }
  // My_output


  function show_message( $data, $xhtml = TRUE ) {

    switch ( $this->hook ) {

      case 'member_member_register':

        header( "Location: http://example.com" );

        exit();

      break;
      // member_member_register

    }
    // switch


    return;

  }
  // show_message

}
// My_output

?>

Obviously I checked and verified that after member_member_register there are no references to $OUT except the call to $OUT->show_message() at the end of register_member(). And $OUT->show_message() terminates script execution at the end, so $OUT won’t be needed again after that call. I just realized that I never checked $OUT->show_message for other method calls on the class [e.g. $OUT->some_other_method()]. I just took a look, and there’s just a couple of properties that you might want to copy to the replacement class for completeness.

This is a simplified example, but obviously in the replacement show_message() method you can do things dynamically based on the data from member_member_register and / or the data sent to show_message().

Not what I’d call a pretty solution, but for me better than not being able to control where the user gets sent after registration.

This is working for me in EE 1.5.2. Needless to say, a future version of EE could break this.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 18 years ago
Mark Bowen's avatar Mark Bowen

Hiya Jesse,

Thank you very much for the reply. I thought I could hear an echo for a moment in the Extensions forums 😉

Thanks for the code snippet I will take a look later on tonight at that and see what you are doing. As I’ve said many times before I can pretty much make simple plugins and the like but extensions and modules are just beyond me at the moment. Whilst I understand the theory, it’s the knowledge of how to get at what I need which eludes me! 😊

Hopefully when EE 2.0 comes out with the new developer code that EE have been talking about then it will be much easier for me to do these kinds of things and I will be able to make more items and release them for free to the community. Just have to wait and see on that one.

Thanks again though for the code, it is very much appreciated.

Best wishes,

Mark

       
Pete Smith's avatar
Pete Smith
91 posts
about 18 years ago
Pete Smith's avatar Pete Smith

Hi Mark,

I had all kinds of requests for changes to the registration system in EE. What I ended up doing is cloning the entire module and making changes to my cloned copy, then directing all registration forms to it.

It’s a little bit ‘hack-y’ but it leaves the official member module untouched for upgrade reasons. I did have to enter actions into exp_actions by hand so that I’d have actions that pointed to my copy of the member files.

My most recent change was making it so someone could get hit with a “register now” form when they tried to access a particular bit of content. Once they registered, they got an email with a link to click on to activate. That link now had the destination of the content they were originally trying to get at. And when they activated, I also logged them in at the same time.

It just cut down on the number of steps for the user. Fill out form, click a link in email and get the content. It used to be fill out the form, click a link in the email, click a login link, then go and find the content you wanted again.

I did duplicate the EE code; I hadn’t really thought about copyright issues, honestly. I’m not releasing my cloned module to the public, and it only works within the context of a licensed version of EE (I assume, I haven’t tried it on a non-licensed version) so I’m guessing EllisLabs won’t have a problem with my technique.

I’m honestly not sure how you’d do it without copying their code since they’re just setting session variables. You need a specific variable to get a specific value…there aren’t too many different ways to accomplish that. 😊

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
about 18 years ago
Mark Bowen's avatar Mark Bowen

Hi Peter,

Thanks for the reply. I know what you mean on that! I can get it to work with no problems at all but that would meant that I wouldn’t be able to release this to the community as I would just be copying their code and changing where required to make it work but I really want to get this working without doing that if possible so that I can release it for people to use as there has been a lot of requests for this type of thing.

It’s my first really big (well I think so 😉 ) extension though so am hoping I can get my head around it and I hope that the code Jesse provided above will get me set along the correct path. Time will only tell 😉

Thanks for stopping by though, every little helps.

Best wishes,

Mark

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.