I am trying to:
1) use a variable which has been defined as a global.
2) pass that variable to be used on another page/form
Link to a page where the issue can be seen:
CRED SUCCESS REDIRECT HOOK
add_filter('cred_success_redirect', 'mm101_redirect',10,3);
function mm101_redirect($url, $post_id, $form_data)
{
if ($form_data['id']==3356){
//global $working_memap_id;
$working_memap_id = $post_id;
echo $working_memap_id;
$url = 'my link url';
return $url;
}
}
also I have to MAKE A SHORTCODE for access the php variable in wp
$working_memap_id = 0;
add_shortcode( 'working_memap_id', 'working_memap_id_func');
function working_memap_id_func($atts)
{
global $working_memap_id;
return $working_memap_id;
}
I expected to see:
When the form jumps to the redirect url, the working_$memap_id variable to be set by the redirect function and available for use in this new page that we've arrived on.
Instead, I got:
Thanks for the support on the previous threads so far from your team.
The shortcode works as expected. On the jump page I've used :
[working_memap_id] to check it's available but it still shows the initial variable value, whatever I set it to (in this case 0)
My question and problem is the scope of the global variable and where to set it..
1) As you can see it's just floating there. Not inside a function or anything. It is just set in a code customisations plugin at the moment (like all the other function) but when I call that function from cred_success_redirect , it's value does not change to what has been set in that function? Do I need to wrap it in another function - if so when to call?
2) how else or where should I set the initial value variable (if at all) so that when redirecting to/loading the new page, it does not cause it to revert to the initial value?
3) or what do I do the ensure the value of the cred_success_redirect function is held and passed over to the new page we are redirected to?
I fear this is php101 for newbies question - and something like use -> instead of = or use " instead of ' but I will ask anyway - we are still out there!
I've have been looking at php resources and threads on this site but to no avail.
Much Thanks in advance
Robert