I'm trying to get information from the front end of my Wordpress site, I used ajax to do that, it gave me the ability to use the data in one of my plugin functions, but in my case I want to use this data in more than just one function.
add_action( 'admin_footer', 'my_action_javascript' );
function my_action_javascript() { ?>
<script type="text/javascript" >
jQuery(document).ready(function($) {
var data = {
'action': 'my_action',
'whatever': 1234
};
jQuery.post(ajaxurl, data);
});
</script> <?php
}
add_action( 'wp_ajax_my_action', 'my_action' );
function my_action() {
$whatever = $_POST['whatever'];
}
In other words I need to use $_POST['whatever']
in other functions in my plugin not only my_action()
function, I tried using PHP global variables like so , but it didn't workout:
$whatever;
function my_action(){
global $whatever = $_POST['whatever'];
}
function my_other_function(){
global $whatever;
if(isset($whatever)){
echo $whatever;
}
}