I tried to have a siderbar registered at the "init" hook based on a variable from the theme options array indicating whether the sidebar should be used in the design.
Now it appears that that the condition works fine (tested with some other code) but if I use
add_action( 'init', 'register_sidebar_x' );
or
add_action( 'wp_loaded', 'register_sidebar_x' );
based on the condition being true, nothing happens, and the sidebar won't be registered, while it will be registered just using the code outside of the control structure using either hook.
So it appears that the init function is executed before the functions.php has access to the theme options array (which is included). The control structure works with "wp_head", for example.
So my question is - from what hook on is it possible to use conditionals and is there one that can be used to register sidebars after that point?
UPDATE:
OK, here's the current code trying to incorporate some suggestions from below... The sidebar is registered just fine if I'm not testing for the condition, but the condition clearly is 'yes'. Is there any way to conditionally register sidebars?
add_action( 'after_setup_theme', 'aad_theme_setup' );
function aad_theme_setup() {
if ( function_exists( 'get_option_tree') ) {
$theme_options = get_option('option_tree');
}
if ($theme_options['aad_sliding_sidebar']=='yes') {
add_action( 'widgets-init', 'aad_register_sidebar_function' );
}
}
So it still doesn't work... thanks for any additional suggestions!
get_option_tree
function, which is defined in a plugin - not in core. I'm not familiar with that plugin, but you'd have to look and see when that function is defined, and choose a hook after that, or a lower priority action on that same hook.