I have a function in functions.php
function test(){
do_action('before_test_action');
echo 'in test';
}
Then within my Widget, in the widget( $args, $instance )
function i use:
$boolean = (isset($instance['boolean'])) ? $instance['boolean'] : '';
if ($boolean == 'on'){
add_action('before_test_action', array($this, 'widget_test_func'));
}
After widget()
function i have the widget_test_func
function:
public function widget_test_func(){
echo 'within widget test func';
}
The action does not run and i don't see anything on the browser.
If i add the add_action within the widget constructor it will work but i need to make sure it runs if the $boolean == 'on'