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

Newbie help: accessing "parent" variables from an extension

Development and Programming

Pete Smith's avatar
Pete Smith
91 posts
17 years ago
Pete Smith's avatar Pete Smith

So I’ve decided to get serious and stop hacking and start working within EE’s structure, and that means learning extensions.

My OOP skills aren’t what they should be; I think if they were this would be easy.

I’m using the email_module_send_email_end hook and I want to adjust the “Thank You” page.

Specifically I want to adjust the $return_name variable from the Email module. But I’m not sure how to access it.

So something like

function rewrite_thankyou_content()
    {
        global $return_name;
        if (isset($_POST['newsletter']))
        {
            $return_name .= "and look for our newsletter!";
            return $return_name;
        }

    }

But like that, $return_name in the calling object doesn’t get changed. I’m not sure how to access that, or if I can? I guess I could copy the rest of the calling function into my extension but I’m trying to keep it as minimally intrusive as possible.

Thanks for any advice!

       
Jesse M's avatar
Jesse M
92 posts
17 years ago
Jesse M's avatar Jesse M

Hi Pete,

Your code isn’t working because the $return_name variable you want to change isn’t in the global scope, it’s local to the scope of send_email() – there’s no way you can touch it directly from your hook method.

What exactly is the context here? Both of the tags that I see for the Email module offer a return attribute that allows you to set the value used for $return_name.

If that doesn’t address your situation, I’d suggest one of the following:

A) Somewhere before send_email() executes (perhaps in your path.php file), set $_POST[ ‘RET’ ]. By doing that you can set the value that is used for $return_value.

B) Use the technique I described here.

       
Pete Smith's avatar
Pete Smith
91 posts
17 years ago
Pete Smith's avatar Pete Smith

Hey Jesse,

What I was trying to do is add a pixel to the “thank you” page message. We have a form where users can send in a question to our editors, and there’s an optional “Sign me up for your newsletter” checkbox (strictly opt-in). The company we use for our mailing lists allows signing up an individual via calling a pixel on their servers (with list name and email address as parameters) which makes it easy to do 2 things with 1 form. I just needed to add the img src tag to the thank you message. I was thinking I’d append it to the $return_name variable.

I ended up just printing it in my extension, but that makes for sloppy html since the pixel happens before the opening <html tag. It works, but it bugs me.

I guess what I could do is some php on the form side of things, seeing if the user wants the newsletter and if his/her email is valid, and append that to the return value. That would do away with the need for an extension altogether, wouldn’t it?

The nice thing about the extension is that it can be updated (if the pixel changes or something) by the editors (I created a field for it in the extension settings).

So a bit of a tradeoff…I’ll have to ponder it.

Thanks for the reply!

       
Jesse M's avatar
Jesse M
92 posts
17 years ago
Jesse M's avatar Jesse M

So it’s something like: ?list=whatever&[email protected] ?

Perhaps in your extension you could do something like:

file_get_contents( 'http://example.com/[email protected]' );
       
Pete Smith's avatar
Pete Smith
91 posts
17 years ago
Pete Smith's avatar Pete Smith

Yup, that’s almost exactly what it looks like.

I’ll check out the file_get_contents angle, thanks for the suggestion!

UPDATE: That worked like a charm. Thanks again!

       

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.