Plugin Widget Development – “Add New …” Button not adding new accordion item

Asked on August 25, 2015 in Development.

Hi There,
Working away on building a widget and getting my head around plugin/widget development. One problem I’m stuck on is creating the “Add New…” button that adds a new accordion section.

A working example is the Slider widget, when you click “Add new slide” it adds a new Slide section to the accordion.

I have copied the code pretty carefully and edited it for my needs (I’m building a media gallery), however, the button currently links away to the following URL:

http://www.samskirrow.com/skizzar-test/wp-admin/customize.php?widget-layers-widget-slide[5][design][layout]=layout-full-screen&widget-layers-widget-slide[5][show_slider_arrows]=on&widget-layers-widget-slide[5][show_slider_dots]=on&widget-layers-widget-slide[5][slider_arrow_color]=&widget-layers-widget-slide[5]...[media_gallery_excerpt]=Simple%2C+clean+and+modern+multimedia+gallery+for+Skizzar&widget-layers-widget-media_gallery[3][media_gallery_item][834][design][background][image]=&widget-layers-widget-media_gallery[3][media_gallery_item][834][design][background][color]=%23444&widget-layers-widget-media_gallery[3][media_gallery_item][834][design][background][repeat]=no-repeat&widget-layers-widget-media_gallery[3][media_gallery_item][834][design][background][position]=center&widget-layers-widget-media_gallery[3][media_gallery_item][834][design][fonts][align]=text-center&widget-layers-widget-media_gallery[3][media_gallery_item][834][design][fonts][size]=large&widget-layers-widget-media_gallery[3][media_gallery_item][834][design][fonts][color]=&widget-layers-widget-media_gallery[3][media_gallery_item][834][media_gallery_type]=&widget-layers-widget-media_gallery[3][media_gallery_image][834][media_gallery_image]=&widget-layers-widget-media_gallery[3][media_gallery_item][834][media_gallery_type]=&widget-id=layers-widget-media_gallery-3&id_base=layers-widget-media_gallery&widget-width=980&widget-height=0&widget_number=3&multi_number=&add_new=&_customize-radio-show_on_front=page&_customize-dropdown-pages-page_on_front=3889&_customize-dropdown-pages-page_for_posts=0&attr-title-hide=attr-title&screenoptionnonce=68da585acf&_customize-radio-layers-header-width=layout-boxed&_customize-radio-layers-header-menu-layout=header-logo-center&_customize-radio-layers-footer-width=layout-boxed

…It’s actually a lot longer than that, so I’ve cut it down. Obviously something is going wrong in my code here. This is the section that deals with the button and creating new sections:

<ul id="media_gallery_list_number ); ?>" class="layers-accordions layers-accordions-sortable layers-sortable" data-id_base="id_base; ?>" data-number="number; ?>">
gallery_item( array(

'id_base' => $this->id_base ,

'number' => $this->number

) ,

$media_gallery_item_id ,

( isset( $instance[ 'media_gallery_item' ][ $media_gallery_item_id ] ) ) ? $instance[ 'media_gallery_item' ][ $media_gallery_item_id ] : NULL );

} ?>
<button class="layers-button btn-full layers-add-widget add-new-widget" data-number="number ); ?>">

Can you see anything obviously wrong with this code that is causing my error?

Sam Skirrow Power User
Reply
  • Possible Answers to Your Question:

  • 1 Answer(s)
    Answered on September 2, 2015.

    You’re missing a double quote at the end there.

    I also recommend using the Content widget as your base, not the slider (unless your widget will be a slider) since it has a lot of stuff specific to the slider.

    <button class="layers-button btn-full layers-add-widget-column add-new-widget" data-number="<?php echo esc_attr( $this->number ); ?>"><?php _e( 'Add New Column' , 'layerswp' ) ; ?></button>
     

    Will this method work for any social app buttons because I have to add social app buttons to my site like whatsapp twitter etc.

    on July 26, 2020.

    Well, I did do the same as you told. Is it possible to add these things to a complete blog? For example cyberflix blog.

    on September 13, 2020.

    Was this helpful for AosTv which is a live streaming app?Because i installed it recently.

    on October 13, 2020.

    I will definately do the same for Whatsappsniffer blog.It added more new features.

    on October 14, 2020.

    Okay I get it, I shouldn’t be scared of my error messages, but just changing how I feel doesn’t help me get past this error message right in front of me! What should I do!Regards UnlockMyTv

    on October 14, 2020.
    Reply