Creating Gravity Form Parameters And Regular Shortcodes From Site Session

Greetings Gurus.

I am so so stumped.

I am probably going to cause a few giggles as I sure I am in a “cant see the forest for the trees” scenario here.

It’s been about 3 hours.

I give up and hope that someone out there can point out the error of my ways.

I have successfully captured a session, and echo’d the results. yay.

The last echo (line 32) however, is as far as my variables seem to want to travel.

What is it that I have to do to get the $gformxml->xxxxxxxx part of my code to travel into the add_filter and add_shortcode blocks?

The error I get on each of these blocks is

Notice: Undefined variable: gformxml in [PATH REMOVED FOR SECURITY] on line (each line defining the variable)

I dont get it. I can echo this, but I can’t assign it to a shortcode!?

Help!

Here is my code (of course, once it works, I want to get rid of the echo’s)

<?php
if(class_exists('WP_Session'))
{
$wp_session = WP_Session::get_instance();

if ($wp_session['socialbug_name'] != null && strlen($wp_session['socialbug_name']) > 0)
{
?>
<?php
$gformid = $wp_session['socialbug_affiliate_id'];
?>
<?php
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = '[REMOVED FOR SECURITY]' . $gformid;
$gformxml = file_get_contents($url, false, $context);
$gformxml = simplexml_load_string($gformxml);

$gformFN = $gformxml->FirstName;
$gformLN = $gformxml->LastName;
$gformEMAIL = $gformxml->Email;
$gformPH = $gformxml->PhoneNumber;
$gformPIC = $gformxml->AffiliatePictureURL;

echo $gformxml->FirstName;
echo '<br>';
echo $gformxml->LastName;
echo '<br>';
echo $gformxml->Email;
echo '<br>';
echo $gformxml->PhoneNumber;
echo '<br>';
echo $gformxml->AffiliatePictureURL;

// Add Gravity Forms Consultants Information
// Email Address
add_filter('gform_field_value_consultant_gform', 'fn_get_consultant_webemail');
function fn_get_consultant_webemail($value){
$bizemail = $gformxml->Email;
return $bizemail;
}
// Name
add_filter('gform_field_value_consultantname_gform', 'fn_get_consultant_gfname');
function fn_get_consultant_gfname($value){
$bizname = $gformxml->FirstName;
return $bizname;
}
// Phone
add_filter('gform_field_value_consultantphone_gform', 'fn_get_consultant_gfphone');
function fn_get_consultant_gfphone($value){
$bizphone = $gformxml->PhoneNumber;
return $bizphone;
}

// Add Shortcodes
// Email Address
add_shortcode( 'consultant_email_addr' , 'fn_get_consultant_emailaddr' );
function fn_get_consultant_emailaddr(){
$consultantemailaddr = $gformxml->Email;
return $consultantemailaddr;
}

} else {
// Email Address
add_filter('gform_field_value_consultant_gform', 'fn_get_consultant_webemail');
function fn_get_consultant_webemail($value){
return 'cs@intimatetickles.com';
}
// Add Shortcode Consultants Email
add_shortcode( 'consultant_emailaddr' , 'fn_get_consultant_emailaddr' );
function fn_get_consultant_emailaddr(){
$consultantemailaddr = 'cs@intimatetickles.com';
return $consultantemailaddr;
}

}
}

?>