Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class My_Widget extends WP_Widget {
- public function __construct() {
- $widget_ops = array(
- 'classname' => 'my_widget',
- 'description' => __( 'Description.' ),
- 'customize_selective_refresh' => true,
- );
- $control_ops = array(
- 'width' => 400,
- 'height' => 350,
- );
- parent::__construct( 'my_widget', __( 'My Widget' ), $widget_ops, $control_ops );
- }
- public function widget( $args, $instance ) {
- extract( $args );
- $checkbox1 = ! empty( $instance['checkbox1'] ) ? $instance['checkbox1'] : false;
- $checkbox2 = ! empty( $instance['checkbox2'] ) ? $instance['checkbox2'] : false;
- $checkbox3 = ! empty( $instance['checkbox3'] ) ? $instance['checkbox3'] : false;
- echo $args['before_widget'];
- echo "Hello world, just testing this out.";
- echo $args['after_widget'];
- }
- public function form( $instance ) {
- $defaults = array(
- 'checkbox1' => false, // not checked by default
- 'checkbox2' => true, // checked by default
- 'checkbox3' => true, // checked by default
- );
- $instance = wp_parse_args( (array) $instance, $defaults );
- ?>
- <p>
- <input
- class="checkbox"
- id="<?php echo esc_attr( $this->get_field_id( 'checkbox1' ) ); ?>"
- name="<?php echo esc_attr( $this->get_field_name( 'checkbox1' ) ); ?>"
- type="checkbox"
- <?php checked( '1', $instance['checkbox1'] ); ?>
- value="1">
- <label for="<?php echo esc_attr( $this->get_field_id( 'checkbox1' ) ); ?>">
- <?php _e( 'Checkbox #1', 'test' ); ?>
- </label>
- </p>
- <p>
- <input
- class="checkbox"
- id="<?php echo esc_attr( $this->get_field_id( 'checkbox2' ) ); ?>"
- name="<?php echo esc_attr( $this->get_field_name( 'checkbox2' ) ); ?>"
- type="checkbox"
- <?php checked( '1', $instance['checkbox2'] ); ?>
- value="1">
- <label for="<?php echo esc_attr( $this->get_field_id( 'checkbox2' ) ); ?>">
- <?php _e( 'Checkbox #2', 'test' ); ?>
- </label>
- </p>
- <p>
- <input
- class="checkbox"
- id="<?php echo esc_attr( $this->get_field_id( 'checkbox3' ) ); ?>"
- name="<?php echo esc_attr( $this->get_field_name( 'checkbox3' ) ); ?>"
- type="checkbox"
- <?php checked( '1', $instance['checkbox3'] ); ?>
- value="1">
- <label for="<?php echo esc_attr( $this->get_field_id( 'checkbox3' ) ); ?>">
- <?php _e( 'Checkbox #2', 'test' ); ?>
- </label>
- </p>
- <?php
- }
- public function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['checkbox1'] = isset( $new_instance['checkbox1'] ) ? 1 : false;
- $instance['checkbox2'] = isset( $new_instance['checkbox2'] ) ? 1 : false;
- $instance['checkbox3'] = isset( $new_instance['checkbox3'] ) ? 1 : false;
- return $instance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement