get_option
fires hooks itself so you are triggering a infinite loop (or something similar if not actually infinite). Your callback calls get_option
, which triggers the hooks used by get_option
. Each hook triggers the callback again, which used get_option
which triggers the hooks used by get_option
. And so on…
Get your option value in the constructor, outside of the callback method. That way, when your callback runs it is inadvertently triggering itself. Proof of concept:
class WP_Test_Logging_Plugin {
static $data = array();
public function __construct() {
$this->data = get_option('option_name', 1);
add_action( 'all', array( $this, 'log_to' ) );
}
public function log_to() {
$hook = current_filter();
var_dump($hook,$this->data);
}
}
$ntlp = new WP_Test_Logging_Plugin();