• Hi,
    I’m probably missing something but cant figure out. Sample code does not work as i expected.

    In constructor, i change object property but when i dump it returns false. I havent dig into add_action but i assume it calls call_user_func so it should pass (?) already created object (with all assigned properties) even if not, i mean if it creates another instance, it should also go through constructor and assign ‘aaa’ value to $test.

    To clearify, i want to get ‘aaa’ value from $test property while in testing method.

    Thanks.

    class trkr_test {
        private $test = false;
    
        public function __construct() {
          $this->test = 'aaa';
          add_action( 'bp_setup_nav', array($this, 'testing'), 99 );
        }
    
        public function testing() {
          var_dump($this); // returns object with all methods and properties but $test returns false not aaa
        }
    }
    
    function trkr_load_test() {
        $trkr_test  = new trkr_test();
    }
    
    add_action( 'plugins_loaded', 'trkr_load_test', 999 );
Viewing 1 replies (of 1 total)
  • Thread Starter Turker YILDIRIM

    (@trkr)

    Fixed, actually above sample works fine but my original class is not simple as this is ofcourse.

    Anyway, as you may noticed bp_setup_nav action, i’m using some BP related classes before calling that action but at that point BP was not successfully loaded. After i changed add_action( ‘plugins_loaded’, ‘trkr_load_test’, 999 ); into add_action( ‘bp_setup_globals’, ‘trkr_load_pta’, 999 ); it’s working fine.

    Keep in mind, be sure all required things loaded before you start to do something.

Viewing 1 replies (of 1 total)
  • The topic ‘add_action, object property not accessible’ is closed to new replies.