I'm trying to make some of the variables from my plugin available for an instance of the class on my page. But it's not showing up the correct values.
Here's the relevant part of the plugin:
class opi{
// version
public $opi_version = "1.0";
public $mg = 0;
//constructor
public function opi(){
$this->__construct();
}
public function __construct(){
add_action('init', array(&$this, 'o_check'));
// ...
}
function o_check(){
if (is_user_logged_in()){
$this->mg = 4;
}
}
}
$opi = new opi;
If I put echo $this->mg;
just before the closing brace in the o_check()
function, then it shows 4
. Fine.
Now if I put the following in page.php, and I'm logged into WordPress, I get the result 0
.
<?php $pageopi = new opi; ?>
<?php echo $pageopi->mg; ?>
Any ideas where I'm going wrong please?