__('AT Counter', 'aakanksha'),
'size' => 'span12',
);
//create the widget
parent::__construct('as_Counter_Block', $block_options);
//add ajax functions
add_action('wp_ajax_as_block_counter_add_new', array($this, 'add_counter'));
}
function form($instance) {
$defaults = array(
'counters' => array(
1 => array(
'title' => __('Add new counter', 'aakanksha'),
'from' => '0',
'to' => '100',
'speed' => '4000',
'interval' => '50'
)
),
'column' => 'three',
'margin_top' => 10,
'margin_bottom' => 10,
);
$instance = wp_parse_args($instance, $defaults);
extract($instance);
$counter_columns = array(
'two' => 'Two Columns',
'three' => 'Three Columns',
'four' => 'Four Columns',
);
?>
-
counter($counter, $count);
$count++;
}
?>
';
foreach( $counters as $counter ){
$output .= '
' .htmlspecialchars_decode($counter['title']). '
';
if($i%2 == 0 && $i != sizeof($counters) && $span == 'col-md-6') $output .= '';
if($i%3 == 0 && $i != sizeof($counters) && $span == 'col-md-4') $output .= '';
if($i%4 == 0 && $i != sizeof($counters) && $span == 'col-md-3') $output .= '';
$i++;
}
$output .='';
echo $output;
}
/* AJAX add counter */
function add_counter() {
$nonce = $_POST['security'];
if (! wp_verify_nonce($nonce, 'aspb-settings-page-nonce') ) die('-1');
$count = isset($_POST['count']) ? absint($_POST['count']) : false;
$this->block_id = isset($_POST['block_id']) ? $_POST['block_id'] : 'as-block-9999';
//default key/value for the counter
$counter = array(
'title' => __('Add new counter','aakanksha'),
'from' => '0',
'to' => '100',
'speed' => '4000',
'interval' => '50'
);
if($count) {
$this->counter($counter, $count);
} else {
die(-1);
}
die();
}
function update($new_instance, $old_instance) {
$new_instance = as_recursive_sanitize($new_instance);
return $new_instance;
}
function before_block($instance) {
extract($instance);
return;
}
function after_block($instance) {
extract($instance);
return;
}
}
as_register_block( 'as_Counter_Block' );
endif;