View difference between Paste ID: UKYB13LY and
SHOW: | | - or go back to the newest paste.
1-
1+
add_action('widgets_init', 'campus_html'); 
2
function campus_html() { // function name matches name from add_action
3
  register_widget('Campus_HTML');
4
}
5
6
class Campus_HTML extends WP_Widget {
7
8
  function Campus_HTML() { // function name matches class name
9
      $widget_ops = array(
10
          'classname'=>'campus-html-widget', // class that will be added to li element in widgeted area ul
11
          'description'=>'Campus HTML Widget' // description displayed in admin
12
          );
13
      $control_ops = array(
14
          'width'=>200, 'height'=>250, // width of input widget in admin
15
          'id_base'=>'campus-html-widget' // base of id of li element ex. id="example-widget-1"
16
          );
17
      $this->WP_Widget('campus-html-widget', 'Campus HTML', $widget_ops, $control_ops); // "Example Widget" will be name in control panel
18
  }
19
20
  function widget($args, $instance) {
21
          extract($args);
22
23
          // these are our widget options
24
          $output = $before_widget;
25
26
          // how input text will be displayed
27
          $output .= '<img class="sixteen_nine" src="'.$instance['image'].'" width="300" height="169">';
28
          $output .= '<h3>'.$instance['title'].'</h3>';
29
          $output .= var_dump($instance['campus']);
30
          $output .= '<p>'.$instance['text'].' <a href="'.$instance['url'].'" title="Continue">Continue</a></p>';
31
32
          $output .= $after_widget;
33
34
          echo $output;
35
      }
36
37
  function update( $new_instance, $old_instance ) {
38
      $instance = $old_instance;
39
      $instance['campus'] = $new_instance['campus'];
40
      $instance['title'] = $new_instance['title'];
41
      $instance['image'] = $new_instance['image'];
42
      $instance['text'] = $new_instance['text'];
43
      $instance['url'] = $new_instance['url'];
44
45
      return $instance;
46
  }
47
48
  function form( $instance ) {
49
50
      $defaults = array(
51
        'campus' => 'peoria',
52
        'title' => 'Title Here',
53
        'image' => '/images/16x9_blank.png',
54
        'text' =>'default text',
55
        'url' => 'http://www.google.com');
56
      $instance = wp_parse_args( (array) $instance, $defaults );
57
58
      ?>
59
      <p>
60
        <label for="<?php echo $this->get_field_id( 'campus' ); ?>">Campus: <?php echo $instance['campus']; ?></label>
61
        <select id="<?php echo $this->get_field_id( 'campus' ); ?>" name="<?php echo $this->get_field_id( 'campus' ); ?>">
62
        <?php
63
          foreach (campus_array() as $campus) {
64
            if ($instance['campus'] == $campus) $selected = 'selected="selected"';
65
            echo '<option value="'.$campus.'" id="'.$campus.'" '.$selected.'>'.ucwords($campus).'</option>';
66
          }
67
        ?>
68
        </select>
69
      </p>
70
      <p>
71
          <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
72
          <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" style="width:100%;" value="<?php echo $instance['title']; ?>" />
73
      </p>
74
      <p>
75
          <label for="<?php echo $this->get_field_id( 'image' ); ?>">Image :</label>
76
          <input id="<?php echo $this->get_field_id( 'image' ); ?>" name="<?php echo $this->get_field_name( 'image' ); ?>" style="width:100%;" value="<?php echo $instance['image']; ?>" />
77
      </p>
78
      <p>
79
          <label for="<?php echo $this->get_field_id( 'text' ); ?>">HTML:</label>
80
          <textarea id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>" style="width:100%;min-height:100px;"><?php echo $instance['text']; ?></textarea>
81
      </p>
82
      <p>
83
          <label for="<?php echo $this->get_field_id( 'url' ); ?>">URL:</label>
84
          <input id="<?php echo $this->get_field_id( 'url' ); ?>" name="<?php echo $this->get_field_name( 'url' ); ?>" style="width:100%;" value="<?php echo $instance['url']; ?>" />
85
      </p>
86
87
  <?php }
88
} //end widget class