id_base = isset($id_base) ? strtolower($id_base) : strtolower(get_class($this)); $this->name = isset($block_options['name']) ? $block_options['name'] : ucwords(preg_replace("/[^A-Za-z0-9 ]/", '', $this->id_base)); $this->block_options = $this->parse_block($block_options); } /** * Block - display the block on front end * * Sub-class MUST override this or it will output an error * with the class name for reference */ function block($instance) { extract($instance); echo __('function as_Block::block should not be accessed directly. Output generated by the ', 'aakanksha') . strtoupper($id_base). ' Class'; } /** * The callback function to be called on blocks saving * * You should use this to do any filtering, sanitation etc. The default * filtering is sufficient for most cases, but nowhere near perfect! */ function update($new_instance, $old_instance) { $new_instance = array_map('htmlspecialchars', array_map('stripslashes', $new_instance)); return $new_instance; } /** * The block settings form * * Use subclasses to override this function and generate * its own block forms */ function form($instance) { echo '
'; return 'noform'; } /** * Form callback function * * Sets up some default values and construct the basic * structure of the form. Unless you know exactly what you're * doing, DO NOT override this function */ function form_callback($instance = array()) { //insert block options into instance $instance = is_array($instance) ? wp_parse_args($instance, $this->block_options) : $this->block_options; //insert the dynamic block_id $this->block_id = 'as_block_' . $instance['number']; $instance['block_id'] = $this->block_id; //display the block $this->before_form($instance); $this->form($instance); $this->after_form($instance); } /** * Block callback function * * Sets up some default values. Unless you know exactly what you're * doing, DO NOT override this function */ function block_callback($instance) { //insert block options into instance $instance = is_array($instance) ? wp_parse_args($instance, $this->block_options) : $this->block_options; //insert the dynamic block_id $this->block_id = 'as_block_' . $instance['number']; $instance['block_id'] = $this->block_id; //display the block $this->before_block($instance); $this->block($instance); $this->after_block($instance); } /* assign default block options if not yet set */ function parse_block($block_options) { $defaults = array( 'id_base' => $this->id_base, //the classname 'order' => 0, //block order 'name' => $this->name, //block name 'size' => 'span12', //default size 'title' => '', //title field 'parent' => 0, //block parent (for blocks inside columns) 'number' => '__i__', //block consecutive numbering 'first' => false, //column first 'resizable' => 1, //whether block is resizable/not ); $block_options = is_array($block_options) ? wp_parse_args($block_options, $defaults) : $defaults; return $block_options; } //form header function before_form($instance) { extract($instance); $title = $title ? ' : '.$title.'' : ''; $resizable = $resizable ? '' : 'not-resizable'; echo '