753 posts
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Author had a Free File of the Month
  • Exclusive Author
  • Has been a member for 5-6 years
  • Bought between 1 and 9 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
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
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Author had a Free File of the Month
  • Exclusive Author
  • Has been a member for 5-6 years
  • Bought between 1 and 9 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
AdamGold says

Sorry, tried to edit the first post

753 posts
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Author had a Free File of the Month
  • Exclusive Author
  • Has been a member for 5-6 years
  • Bought between 1 and 9 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
AdamGold says

Someone? It’s really frustrating.

822 posts
  • Power Elite Author: Sold between 1 000 000 - 1 999 999 dollars
  • Power Elite Author
  • Won a Competition
  • Exclusive Author
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Europe
  • Bought between 50 and 99 items
+2 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
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Author had a Free File of the Month
  • Exclusive Author
  • Has been a member for 5-6 years
  • Bought between 1 and 9 items
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
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