I have Dynamic sidebars that are generated based on terms of a taxonomy that were created.
CLASS EXCERPT:
public function __construct() {
add_action('widgets_init', array($this, 'checkForActiveSidebarAndMenu'));
}
public function checkForActiveSidebarAndMenu() {
//global $wp_registered_sidebars;
//print_r($wp_registered_sidebars);
$terms = get_terms(array('taxonomy'=>'minisite','hide_empty'=>false));
print_r($terms);
foreach($terms as $term) {
$this->registerSidebars($term->term_id);
//$this->registerMenu($term->term_id);
update_term_meta($term->term_id, 'sidebar_active', '1');
//update_term_meta($term->term_id, 'menu_active', '1');
}
}
public function registerSidebars($mini_site_id) {
// Register main content sidebar, [MINISITENAME]_[TERMID]_HOMEPAGE
// Register right aligned sidebar, [MINISITENAME]_[TERMID]_RIGHT_SIDEBAR
$mini_site_name = get_term($mini_site_id, 'minisite');
$mini_site_name = $mini_site_name->slug;
$sidebar_name = $mini_site_name . '_' . $mini_site_id;
$args = array(
'id'=>$sidebar_name . '_HOMEPAGE',
'name'=>$sidebar_name . ' HOMEPAGE'
);
register_sidebar($args);
//var_dump($sidebar);
$args = array(
'id'=>$sidebar_name . '_RIGHT_SIDEBAR',
'name'=>$sidebar_name . ' RIGHT SIDEBAR'
);
register_sidebar($args);
}
This function registers the sidebar. The query array in "get_terms" will change.
This is my second function that I've written as initially I was under the impression that sidebars only need to be registered once, not every single 'widgets_init'
The above code creates the sidebar every time widgets_init runs which means that I can populate my sidebar with widgets, refresh and the new sidebar would be there and the old one gone.
What am I doing wrong? I want to be able to register a dynamic sidebar and for it to stay until I unregister it.
Additional:
The class is fine and the methods are executing as they should.
The taxonomy "minisite" is my taxonomy and it works fine, it loads as priority 0 on 'init' to allow for widgets_init to run with that taxonomy correctly.