在钩子中访问变量?

I'm making a WP Plugin, and within my plugin I have a few functions.

The first one is to find the location of user, and one of the others is to run some logic, depending on the output of the location, however this function hooks it into the_post like so:

function find_location() {
...
$countrycode = $obj->country_code;
...
}

function everypost_func($obj) {
...
echo $countrycode;
...
} 
add_action('the_post','everypost_func');

I've tried using global variables, but these don't seem to work. Can anyone shed any light on the situation? The issue I'm facing is getting access to the $countrycode variable, outside of the find_location function

Have you considered passing the variables to the function like this:

function find_location($obj) {
  //...
  $countrycode = $obj->country_code;
  //...
  return $countrycode;
}

function everypost_func($obj) {
  //...
  $countrycode = find_location($obj);
  echo $countrycode;
  //...
} 
add_action('the_post','everypost_func');
function find_location() {
...
$countrycode = $obj->country_code;
...
return $countrycode;
}

function everypost_func() {
...
$countrycode = find_location();
echo $countrycode;
...
} 
add_action('the_post','everypost_func');

if there are more values in the $obj you need access to you could do

function find_location() {
...
$countrycode = $obj->country_code;
...
return $obj;
}

function everypost_func() {
$object = find_location();
...
$countrycode = $object->country_code;
echo $countrycode;
...
} 
add_action('the_post','everypost_func');