753 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 1
  • Weekly Top Seller
+5 more
AdamGold
says

Hi, I am developing my own WP framework and currently I am working on the options panel. Now, I want to add an option to create as many sidebars as the user wants. Now, this is my code:

// when the button is clicked.. function register_new_sidebars() { register_sidebar( array( 'name' => __( 'Test the panel', 'gateway' ), 'id' => 'test-options-panel', 'description' => __( 'The Test widget area', 'gateway' ), 'before_widget' => '<li class="widget-container %2$s" id="%1$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) ); } add_action( 'widgets_init', 'register_new_sidebars' );

It doesn’t work. When I wrap it with var_dump it returns the ID of the sidebar, which actually says the function works but it just doesn’t add the sidebar (in the widgets page).

Thanks.

753 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 1
  • Weekly Top Seller
+5 more
AdamGold
says

Sorry, tried to edit the first post

753 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 1
  • Weekly Top Seller
+5 more
AdamGold
says

Someone? It’s really frustrating.

839 posts
  • Power Elite Author
  • Winner
  • Top Monthly Author
  • Trendsetter
+10 more
wpbakery
says

I believe you should run your register_sidebar every time on init;

add_action( 'init', 'the_widgets_init' );

function the_widgets_init() {
    if ( !function_exists('register_sidebars') )
        return;

    register_sidebar( array( 'name' => __( 'Test the panel', 'gateway' ), 'id' => 'test-options-panel', 'description' => __( 'The Test widget area', 'gateway' ), 'before_widget' => '<li class="widget-container %2$s" id="%1$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) );
}

So in options panel save ids or other params that you need and then on init loop throw those params and register_sidebar

753 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 1
  • Weekly Top Seller
+5 more
AdamGold
says

I believe you should run your register_sidebar every time on init;
add_action( 'init', 'the_widgets_init' );

function the_widgets_init() {
    if ( !function_exists('register_sidebars') )
        return;

    register_sidebar( array( 'name' => __( 'Test the panel', 'gateway' ), 'id' => 'test-options-panel', 'description' => __( 'The Test widget area', 'gateway' ), 'before_widget' => '<li class="widget-container %2$s" id="%1$s">', 'after_widget' => '</li>', 'before_title' => '

’, ‘after_title’ => ‘

’, ) ); } So in options panel save ids or other params that you need and then on init loop throw those params and register_sidebar

I figured it out like an hour ago, I just made an array every time the user submits and then used add_action with the widgets_init hook.

Thank you anyway! :)

by
by
by
by
by
by