Advertisement
dasmikko

my widget

Mar 13th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.67 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: ***
  4. Plugin URI: ***
  5. Description: ****
  6. Version: 0.1
  7. Author: *****
  8. Author ***
  9. */
  10.  
  11. class Sample_Widget extends WP_Widget
  12. {
  13.     function Sample_Widget()
  14.     {
  15.         $widget_ops = array('classname' => 'ODw_Blocks', 'description' => 'ONE.DAY.web blocks.');
  16.         $control_ops = array('width' => 600, 'height' => 800);
  17.         $this->WP_Widget('ODw_Blocks', 'O.D.w Tekst Blokke', $widget_ops, $control_ops);
  18.  
  19.         // Load Jquery & redactor!
  20.         $redactorCSS = plugins_url('/odw-sections/css/redactor.css');
  21.         $redactorJS = plugins_url('/odw-sections/js/redactor.min.js');
  22.         $redactorInit = plugins_url('/odw-sections/js/init.js');
  23.         wp_enqueue_style('redactorcss', $redactorCSS);
  24.         wp_enqueue_script('redactorjs', $redactorJS);
  25.         wp_enqueue_script('redactorInit', $redactorInit);
  26.     }
  27.  
  28.     function update($new_instance, $old_instance)
  29.     {
  30.         $instance = $old_instance;
  31.         $instance['box1'] = $new_instance['box1'];
  32.         $instance['box2'] = $new_instance['box2'];
  33.         $instance['box3'] = $new_instance['box3'];
  34.         $instance['box4'] = $new_instance['box4'];
  35.  
  36.         if ( current_user_can('unfiltered_html') )
  37.         $instance['text'] =  $new_instance['box1'];
  38.         else
  39.         $instance['box1'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['box1']) ) ); // wp_filter_post_kses() expects slashed
  40.  
  41.         if($instance['boxqty'] > 4)
  42.         {
  43.             $instance['boxqty'] = 4;
  44.         }
  45.         else if($instance['boxqty'] < 1)
  46.         {
  47.             $instance['boxqty'] = 1;
  48.         }
  49.         else {
  50.             $instance['boxqty'] = $new_instance['boxqty'];
  51.         }
  52.  
  53.         return $instance;
  54.     }
  55.  
  56.     function form($instance)
  57.     {
  58.         $instance = wp_parse_args((array) $instance, array( 'box1' => '', 'box2' => '', 'box3' => '', 'box4' => '' ));
  59.         $box1 = $instance['box1'];
  60.         $box2 = $instance['box2'];
  61.         $box3 = $instance['box3'];
  62.         $box4 = $instance['box4'];
  63.         $boxqty = $instance['boxqty'];
  64.  
  65.  
  66.         $uniqueID = rand();
  67.         echo "Unique ID: ".$uniqueID;
  68.  
  69.         ?>        
  70.         <p>
  71.             <label for="<?php echo $this->get_field_id('boxqty'); ?>">Number of blocks: (1-4)
  72.                 <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); ?>" />
  73.             </label>
  74.         </p>  
  75.         <p>
  76.             <label for="<?php echo $this->get_field_id('box1'); ?>">Box 1:
  77.                 <textarea class="widefat redactor_content" id="box1" name="<?php echo $this->get_field_name('box1'); ?>" style="width: 600px;"><?php echo $box1; ?></textarea>
  78.             </label>
  79.         </p>
  80.         <p>
  81.             <label for="<?php echo $this->get_field_id('box2'); ?>">Box 2:
  82.                 <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>
  83.             </label>
  84.         </p>
  85.         <p>
  86.             <label for="<?php echo $this->get_field_id('box3'); ?>">Box 3:
  87.                 <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>
  88.             </label>
  89.         </p>
  90.         <p>
  91.             <label for="<?php echo $this->get_field_id('box4'); ?>">Box 4:
  92.                 <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>
  93.             </label>
  94.         </p>
  95.         <!--Activate Redactor-->
  96.         <script type="text/javascript">
  97.             jQuery('.redactor_content').destroyEditor();
  98.             redactor_editor();
  99.         </script>
  100.         <?php
  101.     }
  102.  
  103.     function widget($args, $instance)
  104.     {
  105.         extract($args, EXTR_SKIP);
  106.  
  107.         $box1 = empty($instance['box1']) ? '' : apply_filters('widget_text', $instance['box1']);
  108.         $box2 = empty($instance['box2']) ? '' : apply_filters('widget_text', $instance['box2']);
  109.         $box3 = empty($instance['box3']) ? '' : apply_filters('widget_text', $instance['box3']);
  110.         $box4 = empty($instance['box4']) ? '' : apply_filters('widget_text', $instance['box4']);
  111.         $boxqty = empty($instance['boxqty']) ? '' : apply_filters('widget_title', $instance['boxqty']);
  112.  
  113.         if($boxqty > 4)
  114.         {
  115.             echo "<div class='sixteen columns'><div class='box padding'>";
  116.             echo $box1;
  117.             echo "</div></div>";  
  118.         }
  119.         if($boxqty < 1)
  120.         {
  121.             echo "<div class='sixteen columns'><div class='box padding'>";
  122.             echo $box1;
  123.             echo "</div></div>";  
  124.         }
  125.  
  126.         if($boxqty == 1)
  127.         {
  128.             echo "<div class='sixteen columns'><div class='box padding'>";
  129.             echo $box1;
  130.             echo "</div></div>";
  131.         }
  132.  
  133.         if($boxqty == 2)
  134.         {
  135.             echo "<div class='eight columns'><div class='box padding'>";
  136.             echo $box1;
  137.             echo "</div></div>";
  138.  
  139.             echo "<div class='eight columns'><div class='box padding'>";
  140.             echo $box2;
  141.             echo "</div></div>";
  142.             echo "<div class='clearfix'></div>";
  143.         }
  144.  
  145.         if($boxqty == 3)
  146.         {
  147.             echo "<div class='one-third column'><div class='box padding'>";
  148.             echo $box1;
  149.             echo "</div></div>";
  150.  
  151.             echo "<div class='one-third column'><div class='box padding'>";
  152.             echo $box2;
  153.             echo "</div></div>";
  154.  
  155.             echo "<div class='one-third column'><div class='box padding'>";
  156.             echo $box3;
  157.             echo "</div></div>";
  158.             echo "<div class='clearfix'></div>";
  159.         }
  160.  
  161.         if($boxqty == 4)
  162.         {
  163.             echo "<div class='four columns'><div class='box padding'>";
  164.             echo $box1;
  165.             echo "</div></div>";
  166.  
  167.             echo "<div class='four columns'><div class='box padding'>";
  168.             echo $box2;
  169.             echo "</div></div>";
  170.  
  171.             echo "<div class='four columns'><div class='box padding'>";
  172.             echo $box3;
  173.             echo "</div></div>";
  174.  
  175.             echo "<div class='four columns'><div class='box padding'>";
  176.             echo $box4;
  177.             echo "</div></div>";
  178.             echo "<div class='clearfix'></div>";
  179.         }
  180.     }
  181. }
  182. add_action('widgets_init', create_function('', 'return register_widget("Sample_Widget");'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement