syamilmj / aqua-page-builder

Aqua Page Builder WordPress Plugin
238 stars 114 forks source link

Problem with Add New button #152

Closed temsool closed 10 years ago

temsool commented 10 years ago

Hi, Just made a block but add new button not add a new element! it just return 0!

the code is: http://pastebin.com/Dy31rGGM

<?php /* List Block */ if (!class_exists('Tabbed_Content_Block')) {

class Tabbed_Content_Block extends AQ_Block {

function __construct() {
  $block_options = array(
      'name' => 'Dimco:: Tabbed Content',
      'size' => 'span12'
  );

  //create the widget
  parent::__construct('Tabbed_Content_Block', $block_options);

  //add ajax functions
  add_action('wp_ajax_aq_block_tab_add_new_tab', array($this, 'add_new_tab'));
}

function form($instance) {

  $defaults = array(
      'title' => '',
      'myTabs' => array(
          1 => array(
              'title' => '1st Tab',
              'navbtntext' => 'Nav Button',
              'content' => '',
              'id' => '',
              'contentsize' => 'full'
          )
      ),
      'effect' => 'fade'
  );

  $instance = wp_parse_args($instance, $defaults);
  extract($instance);

  $effect_options = array(
      'none' => 'None',
      'fade' => 'Fade'
  );
  $contentsize_options = array(
      'full' => 'Full Width',
      'half' => 'Half Width'
  );
  ?>

  <div class="description">
    <label for="<?php echo $this->get_field_id('title') ?>">
      Title<br/>
      <?php  echo aq_field_input('title', $block_id, $title, $size = 'full') ?>
    </label>
  </div>

  <div class="description cf">
    <ul id="aq-sortable-list-<?php echo $block_id ?>" class="aq-sortable-list" rel="<?php echo $block_id ?>">
      <?php
      $myTabs = is_array($myTabs) ? $myTabs : $defaults['myTabs'];
      $count = 1;
      foreach ($myTabs as $tab) {
        $this->the_tab($tab, $count);
        $count++;
      }
      ?>
    </ul>
    <p></p>
    <a href="#" rel="tab" class="aq-sortable-add-new button">Add New</a>
    <p></p>
  </div>

  <div class="description half ">
    <label for="<?php echo $this->get_field_id('contentsize') ?>">
      Content Width<br/>
      <?php echo aq_field_select('contentsize', $block_id, $contentsize_options, $contentsize); ?>
    </label>
  </div>

  <div class="description half last">
    <label for="<?php echo $this->get_field_id('effect') ?>">
      Effect<br/>
      <?php echo aq_field_select('effect', $block_id, $effect_options, $effect); ?>
    </label>
  </div>

  <div class="cf"></div>

  <?php
}

function the_tab($tab = array(), $count = 0) {
  ?>

  <li id="sortable-item-<?php echo $count ?>" class="sortable-item" rel="<?php echo $count ?>">

    <div class="sortable-head cf">
      <div class="sortable-title">
        <strong><?php echo $tab['title'] ?></strong>
      </div>
      <div class="sortable-handle">
        <a href="#">Open / Close</a>
      </div>
    </div>

    <div class="sortable-body">
      <div class="tab-desc description">
        <label for="<?php echo $this->get_field_id('myTabs') ?>-<?php echo $count ?>-title">
          Title<br/>
          <input type="text" id="<?php echo $this->get_field_id('myTabs') ?>-<?php echo $count ?>-title" class="input-full" name="<?php echo $this->get_field_name('myTabs') ?>[<?php echo $count ?>][title]" value="<?php echo $tab['title'] ?>" />
        </label>
      </div>

      <input type="hidden" id="<?php echo $this->get_field_id('myTabs') ?>-<?php echo $count ?>-id" class="input-full" name="<?php echo $this->get_field_name('myTabs') ?>[<?php echo $count ?>][id]" value="#<?php echo $this->get_field_name('myTabs') ?>tab<?php echo $count; ?>" />

      <div class="tab-desc description">
        <label for="<?php echo $this->get_field_id('myTabs') ?>-<?php echo $count ?>-navbtntext">
          Button Text<br/>
          <input type="text" id="<?php echo $this->get_field_id('myTabs') ?>-<?php echo $count ?>-navbtntext" class="input-full" name="<?php echo $this->get_field_name('myTabs') ?>[<?php echo $count ?>][navbtntext]" value="<?php echo $tab['navbtntext'] ?>" />

        </label>
      </div>

      <div class="tab-desc description">
        <label for="<?php echo $this->get_field_id('myTabs') ?>-<?php echo $count ?>-content">
          Content
          <?php
          $args = array(
              'tinymce' => true,
              'quicktags' => true,
              'textarea_name' => $this->get_field_name('myTabs') . '-' . $count . '-content'
          );
          wp_editor(htmlspecialchars_decode($text), $this->get_field_id('myTabs'), $args);
          ?>
        </label>
      </div>

      <p class="tab-desc description"><a href="#" class="sortable-delete">Delete</a></p>
    </div>

  </li>

  <?php
}

function block($instance) {
  extract($instance);

  $themefolder = get_template_directory_uri();

  $output = '';

  $output .= '<section  id="tab-' . $block_id . '" class="section >';
  $output .= '<div class="container">';
  $output .= '<div class="myTabs-holder">';

  $output .= '<div class="paragraph-holder text-center"><p>' . $title . '</p>'; //should close

  $output .= '<ul class="myTabs-buttons" >';

  if (!empty($myTabs) && is_array($myTabs)) {

    $i = 1;

    foreach ($myTabs as $tab) {

      $output .= '<li class="' . ($i == 1 ? 'active ' : '') . '">';

      if (!empty($tab['navbtntext'])) {

        $output .= '<a class="le-button big" href="' . $tab['id'] . '" data-toggle="tab" />';
        $output .= $tab['navbtntext'];
        $output .= '</a>';
      }

      $i++;
    }
    $output .= '</ul>'; //End myTabs-buttons ul

    $output .= '</div>'; //End paragraph-holder Div;
  }

  $output .= '</div>'; // End myTabs-holder
  $output .= '</div>'; // End container

  $output .= '<hr>';

  $output .= '<div class="container">'; //Tabs body 
  $output .= '<div class="myTabs-holder">';
  $output .= '<div class="tab-content">';

  foreach ($myTabs as $tab) {
    $output .= '<div class="tab-pane' . ($tab['effect'] == 'fade' ? 'fade ' : '') . '" id="' . $tab['id'] . '">';
    }

     $output .= '</div>'; // End tab-pane
  $output .= '</div>'; // End tab-content

  echo $output;
}

/* AJAX add testimonial */

function add_new_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 testimonial
  $tab = array(

              'title' => 'New Tab',
              'navbtntext' => 'Nav Button',
              'content' => '',
              'id' => '',
              'contentsize' => 'full'

  );

  if ($count) {

    $this->the_tab($tab, $count);
  } else {
    die(-1);
  }

  die();
}

function update($new_instance, $old_instance) {
  $new_instance = aq_recursive_sanitize($new_instance);
  return $new_instance;
}

}

}

temsool commented 10 years ago

SOLVED!!

Just need to pay attention on these lines: add_action('wp_ajax_aq_block_tabcontent_add_new', array($this, 'add_new_tab')); // tabcontent

Add New //rel="tabcontent"