Pushing Session information into an add_filter and add_shortcode block

I asking this question for a second time. Sorry. The first solution did not work. It resulted in a code error of Notice: Undefined variable: wp_session in /***/shopping-with.php on line 33,

and that post seems to have fallen into an abyss, as I can’t get anyone to continue the conversation. So I am starting a new one here.

I need to get the information from a session to pass into an add_filter (for gravity forms) and add_shortcode (self explanatory) block.

My attempts are not working, and a suggestion has also failed.

I can echo my values before and after any add_filter or add_shortcode blocks, but I can’t get those values to parse the blocks.

The suggestion was the inclusion of a function – then call the function. This is shown below, and this did not work.

$wp_session = WP_Session::get_instance();

if ($wp_session['socialbug_name'] != null && strlen($wp_session['socialbug_name']) > 0)
<div style="text-align:center; font-weight: normal;">
<b>Shopping With:</b> <?php echo $wp_session['socialbug_name']; ?> |
<b>City:</b> <?php echo $wp_session['socialbug_city']; ?> |
<b>Phone:</b> <?php echo $wp_session['socialbug_phone']; ?> |
<b>Email:</b> <?php echo $wp_session['socialbug_email']; ?>

add_filter('gform_field_value_consultant_gform', 'fn_get_consultant_webemail');
function fn_get_consultant_webemail($value){
// $bizemail = $gformxml->Email;
// return $bizemail;
$gfxml = get_the_gformxml();
if( !empty( $gfxml ) ){
$bizemail = $gformxml->Email;
return $bizemail;

return '';

function get_the_gformxml(){
$gformxml = "";
if ( $wp_session['socialbug_name'] != null
&& strlen($wp_session['socialbug_name']) > 0 ){
$gformid = $wp_session['socialbug_affiliate_id'];
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = 'http://***/AffiliateId=' . $gformid;
$gformxml = file_get_contents($url, false, $context);
$gformxml = simplexml_load_string($gformxml);
return $gformxml;


I am under a wicked crunch time line here as this system is suppose to launch Saturday night, and can not launch if I can’t get the session information (specifically the email address) to dynamically populate into the Gravity form.

Many thanks for any assistance you can offer.

  • Rupok
    • Support Ninja

    Hi Deryk,

    Can you please tell us what was the previous suggestions? I've a pretty basic workaround in my mind, why are you not putting the session data in a variable and using the "global" keyword for calling those variables inside your blocks? From your code, I can see that the session data you are dealing with, are pretty simple like name, city, phone etc. Please check the attached screenshot for reference.

    Please note, I'm not sure if this will work but this is what came to my mind at first. Can you please try in this way and let us know how it goes?

    Have a nice day. Cheers!


  • Deryk
    • The Incredible Code Injector

    Hi Ropuk.

    Thanks for your suggestion.

    For some reason, the function solution is not working for me.

    The “Previous Suggestion” is the code I entered into my initial message.

    I did come up with a fix, however.

    While taking a nap (doesn’t it always work that way!), I wondered my I was not wrapping the entire request INSIDE the add_function – so I tried it like this

    Plugin Name: .Biz Shortcode Gravity Forms
    Plugin URI: http://intimatetickles.biz/biz_gravity_forms
    Description: Customize Contact Forms - Upload and Activate.
    Author: Deryk Brown
    Version: 1.5
    Author URI: http://webstorme.com
    add_filter('gform_field_value_consultant_gfemail', 'my_consultant_webemail');
    function my_consultant_webemail($value){

    $wp_session = WP_Session::get_instance();

    if ($wp_session['socialbug_name'] != null && strlen($wp_session['socialbug_name']) > 0)

    $consultantid = $wp_session['socialbug_affiliate_id'];

    $context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
    $url = 'http://***AffiliateId=' . $consultantid;
    $xml = file_get_contents($url, false, $context);
    $xml = simplexml_load_string($xml);

    $consultantEMAIL = $xml->Email;

    return $consultantEMAIL;

    } else {

    return "cs@intimatetickles.com";



    And it worked just fine.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.