I have a class that has ajax callbacks inside it, as well as actions set in the __construct()
of that class. I am also passing the property to the class when instantiating it. It looks kinda like this
<?php
class My_Class{
private $passed_string;
public function __construct( $passed_string ) {
$this->$passed_string = $passed_string;
add_action( 'wp_ajax_my_callback', array( $this, 'my_callback' ) );
}
public function my_callback() {
error_log( print_r( $this->$passed_string, true ) );
wp_die();
}
}
$init = new My_Class( 'Passed string!' );
Now this should show in my error logs when I call this function with ajax. But it's empty.
The callback works (tested).
The thing is that when doing this in a similar class that has a method inside, that is not hooked to wp_ajax
hook it works, and I see the passed string just fine.
How come?