__('Tabs & Toggles', 'aqpb-l10n'), 'size' => 'span6', ); //create the widget parent::__construct('AQ_Tabs_Block', $block_options); //add ajax functions add_action('wp_ajax_aq_block_tab_add_new', array($this, 'add_tab')); } function form($instance) { $defaults = array( 'tabs' => array( 1 => array( 'title' => 'My New Tab', 'content' => 'My tab contents', ) ), 'type' => 'tab', ); $instance = wp_parse_args($instance, $defaults); extract($instance); $tab_types = array( 'tab' => 'Tabs', 'toggle' => 'Toggles', 'accordion' => 'Accordion' ); ?>

Add New

  • Delete

  • '; $output .= ''; $i = 1; foreach($tabs as $tab) { $output .= '
    '. wpautop(do_shortcode(htmlspecialchars_decode($tab['content']))) .'
    '; $i++; } $output .= '
    '; } elseif ($type == 'toggle') { $output .= '
    '; foreach( $tabs as $tab ){ $output .= '
    '; $output .= '

    '. $tab['title'] .'

    '; $output .= '
    '; $output .= '
    '; $output .= wpautop(do_shortcode(htmlspecialchars_decode($tab['content']))); $output .= '
    '; $output .= '
    '; } $output .= '
    '; } elseif ($type == 'accordion') { $count = count($tabs); $i = 1; $output .= '
    '; foreach( $tabs as $tab ){ $open = $i == 1 ? 'open' : 'close'; $child = ''; if($i == 1) $child = 'first-child'; if($i == $count) $child = 'last-child'; $i++; $output .= '
    '; $output .= '

    '. $tab['title'] .'

    '; $output .= '
    '; $output .= '
    '; $output .= wpautop(do_shortcode(htmlspecialchars_decode($tab['content']))); $output .= '
    '; $output .= '
    '; } $output .= '
    '; } echo $output; } /* AJAX add tab */ function add_tab() { $nonce = $_POST['security']; if (! wp_verify_nonce($nonce, 'aqpb-settings-page-nonce') ) die('-1'); $count = isset($_POST['count']) ? absint($_POST['count']) : false; $this->block_id = isset($_POST['block_id']) ? $_POST['block_id'] : 'aq-block-9999'; //default key/value for the tab $tab = array( 'title' => 'New Tab', 'content' => '' ); if($count) { $this->tab($tab, $count); } else { die(-1); } die(); } function update($new_instance, $old_instance) { $new_instance = aq_recursive_sanitize($new_instance); return $new_instance; } } }