Advertisement
Guest User

WordPress Widget Confusion

a guest
Dec 28th, 2010
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. <?php
  2.  
  3.     class signup_Widget extends WP_Widget {
  4.         function signup_Widget() {
  5.            
  6.             $widget_ops = array(
  7.                 'classname' => 'widget',
  8.                 'description' => 'Email signup form.'
  9.             );
  10.             $this->WP_Widget( 'email-signup', 'Email Signup', $widget_ops );
  11.            
  12.         }
  13.         function widget($args, $instance) {
  14.            
  15.             extract( $args );
  16.            
  17.             $title = apply_filters( 'widget_title', $instance['title'] );
  18.             $script = $instance['script'];
  19.            
  20.             echo $before_widget;
  21.            
  22.             echo $before_title . $title . $after_title ;
  23.             htmlspecialchars( $script );
  24.            
  25.             echo $after_widget;
  26.         }
  27.        
  28.         function update( $new_instance, $old_instance ) {
  29.        
  30.             $instance = $old_instance;
  31.            
  32.             $instance['title'] = $new_instance['title'];
  33.             $instance['script'] = $new_instance['script'];
  34.            
  35.             /* Exists to test output, unfortunately they show up with no data */
  36.             file_put_contents( '/wp_results.txt', print_r( $old_instance, true ) );
  37.             file_put_contents( '/wp_results.txt', print_r( $new_instance, true ), FILE_APPEND );
  38.            
  39.             return $instance;
  40.            
  41.         }
  42.        
  43.         function form( $instance ) {
  44.             /* Defaults */
  45.             $defaults = array(
  46.                 'title' => 'Email Signup',
  47.                 'script' => 'Default Email Signup Script goes here'
  48.             );
  49.             $instance = wp_parse_args( (array) $instance, $defaults );
  50.             ?>
  51.            
  52.                 <p>
  53.                     <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
  54.                     <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_id( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:95%" />
  55.                 </p>
  56.                
  57.                 <p>
  58.                     <label for="<?php echo $this->get_field_id( 'script' ); ?>">Script:</label>
  59.                     <input id="<?php $this->get_field_id( 'script' ); ?>" name="<?php $this->get_field_id( 'script' ); ?>" value="<?php echo $instance['script']; ?>" style="width:95%" />
  60.                 </p>
  61.            
  62.             <?php
  63.         }
  64.     }
  65.     register_widget( 'signup_Widget' );
  66.  
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement