Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: ***
- Plugin URI: ***
- Description: ****
- Version: 0.1
- Author: *****
- Author ***
- */
- class Sample_Widget extends WP_Widget
- {
- function Sample_Widget()
- {
- $widget_ops = array('classname' => 'ODw_Blocks', 'description' => 'ONE.DAY.web blocks.');
- $control_ops = array('width' => 600, 'height' => 800);
- $this->WP_Widget('ODw_Blocks', 'O.D.w Tekst Blokke', $widget_ops, $control_ops);
- // Load Jquery & redactor!
- $redactorCSS = plugins_url('/odw-sections/css/redactor.css');
- $redactorJS = plugins_url('/odw-sections/js/redactor.min.js');
- $redactorInit = plugins_url('/odw-sections/js/init.js');
- wp_enqueue_style('redactorcss', $redactorCSS);
- wp_enqueue_script('redactorjs', $redactorJS);
- wp_enqueue_script('redactorInit', $redactorInit);
- }
- function update($new_instance, $old_instance)
- {
- $instance = $old_instance;
- $instance['box1'] = $new_instance['box1'];
- $instance['box2'] = $new_instance['box2'];
- $instance['box3'] = $new_instance['box3'];
- $instance['box4'] = $new_instance['box4'];
- if ( current_user_can('unfiltered_html') )
- $instance['text'] = $new_instance['box1'];
- else
- $instance['box1'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['box1']) ) ); // wp_filter_post_kses() expects slashed
- if($instance['boxqty'] > 4)
- {
- $instance['boxqty'] = 4;
- }
- else if($instance['boxqty'] < 1)
- {
- $instance['boxqty'] = 1;
- }
- else {
- $instance['boxqty'] = $new_instance['boxqty'];
- }
- return $instance;
- }
- function form($instance)
- {
- $instance = wp_parse_args((array) $instance, array( 'box1' => '', 'box2' => '', 'box3' => '', 'box4' => '' ));
- $box1 = $instance['box1'];
- $box2 = $instance['box2'];
- $box3 = $instance['box3'];
- $box4 = $instance['box4'];
- $boxqty = $instance['boxqty'];
- $uniqueID = rand();
- echo "Unique ID: ".$uniqueID;
- ?>
- <p>
- <label for="<?php echo $this->get_field_id('boxqty'); ?>">Number of blocks: (1-4)
- <input class="widefat" id="<?php echo $this->get_field_id('boxqty'); ?>" name="<?php echo $this->get_field_name('boxqty'); ?>" type="text" value="<?php echo attribute_escape($boxqty); ?>" />
- </label>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('box1'); ?>">Box 1:
- <textarea class="widefat redactor_content" id="box1" name="<?php echo $this->get_field_name('box1'); ?>" style="width: 600px;"><?php echo $box1; ?></textarea>
- </label>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('box2'); ?>">Box 2:
- <textarea class="widefat redactor_content" id="<?php echo $this->get_field_id('box2'); ?>" name="<?php echo $this->get_field_name('box2'); ?>" style="width: 600px;"><?php echo $box2; ?></textarea>
- </label>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('box3'); ?>">Box 3:
- <textarea class="widefat redactor_content" id="<?php echo $this->get_field_id('box3'); ?>" name="<?php echo $this->get_field_name('box3'); ?>" style="width: 600px;"><?php echo $box3; ?></textarea>
- </label>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id('box4'); ?>">Box 4:
- <textarea class="widefat redactor_content" id="<?php echo $this->get_field_id('box4'); ?>" name="<?php echo $this->get_field_name('box4'); ?>" style="width: 600px;"><?php echo $box4; ?></textarea>
- </label>
- </p>
- <!--Activate Redactor-->
- <script type="text/javascript">
- jQuery('.redactor_content').destroyEditor();
- redactor_editor();
- </script>
- <?php
- }
- function widget($args, $instance)
- {
- extract($args, EXTR_SKIP);
- $box1 = empty($instance['box1']) ? '' : apply_filters('widget_text', $instance['box1']);
- $box2 = empty($instance['box2']) ? '' : apply_filters('widget_text', $instance['box2']);
- $box3 = empty($instance['box3']) ? '' : apply_filters('widget_text', $instance['box3']);
- $box4 = empty($instance['box4']) ? '' : apply_filters('widget_text', $instance['box4']);
- $boxqty = empty($instance['boxqty']) ? '' : apply_filters('widget_title', $instance['boxqty']);
- if($boxqty > 4)
- {
- echo "<div class='sixteen columns'><div class='box padding'>";
- echo $box1;
- echo "</div></div>";
- }
- if($boxqty < 1)
- {
- echo "<div class='sixteen columns'><div class='box padding'>";
- echo $box1;
- echo "</div></div>";
- }
- if($boxqty == 1)
- {
- echo "<div class='sixteen columns'><div class='box padding'>";
- echo $box1;
- echo "</div></div>";
- }
- if($boxqty == 2)
- {
- echo "<div class='eight columns'><div class='box padding'>";
- echo $box1;
- echo "</div></div>";
- echo "<div class='eight columns'><div class='box padding'>";
- echo $box2;
- echo "</div></div>";
- echo "<div class='clearfix'></div>";
- }
- if($boxqty == 3)
- {
- echo "<div class='one-third column'><div class='box padding'>";
- echo $box1;
- echo "</div></div>";
- echo "<div class='one-third column'><div class='box padding'>";
- echo $box2;
- echo "</div></div>";
- echo "<div class='one-third column'><div class='box padding'>";
- echo $box3;
- echo "</div></div>";
- echo "<div class='clearfix'></div>";
- }
- if($boxqty == 4)
- {
- echo "<div class='four columns'><div class='box padding'>";
- echo $box1;
- echo "</div></div>";
- echo "<div class='four columns'><div class='box padding'>";
- echo $box2;
- echo "</div></div>";
- echo "<div class='four columns'><div class='box padding'>";
- echo $box3;
- echo "</div></div>";
- echo "<div class='four columns'><div class='box padding'>";
- echo $box4;
- echo "</div></div>";
- echo "<div class='clearfix'></div>";
- }
- }
- }
- add_action('widgets_init', create_function('', 'return register_widget("Sample_Widget");'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement