[wp-trac] [WordPress Trac] #24493: widget programming using the function checked inside form bug

WordPress Trac noreply at wordpress.org
Tue Jun 4 07:21:50 UTC 2013


#24493: widget programming using the function checked inside form bug
--------------------------+-----------------------------
 Reporter:  Frumph        |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Widgets       |    Version:  3.5.1
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 So what happens is if the wp_parse_args sets a value to true or 1, the
 checked box messes up the contents of the next input value if it contains
 a < or <  however, setting the value to false or 0 it doesn't modify
 the contents of the next input box

 Example code:
 {{{
 <?php

 class ceo_do_nothing_widget extends WP_Widget {

         function ceo_do_nothing_widget() {
                 $widget_ops = array('classname' => __CLASS__,
 'description' => __('Does Nothing','comiceasel') );
                 $this->WP_Widget(__CLASS__, __('Does
 Nothing','comiceasel'), $widget_ops);
         }


         function widget($args, $instance) {
                 extract($args, EXTR_SKIP);
                 var_dump($args);
         }

         function update($new_instance, $old_instance) {
                 $instance = $old_instance;
                 $instance['title'] = $new_instance['title'];
                 $instance['dosomething'] = $new_instance['dosomething'];
                 return $instance;
         }

         function form($instance) {
                 $instance = wp_parse_args( (array)$instance, array(
                                         'title' => '<&lt two',
                                         'dosomething' => true  // set this
 to false to see behavior
                                         ));
                 ?>
                 <input id="<?php echo $this->get_field_id('dosomething');
 ?>" name="<?php echo $this->get_field_name('dosomething'); ?>"
 type="checkbox" value="1" <?php checked(true, $instance['dosomething']);
 ?> /> <strong><?php _e('First','comiceasel'); ?></strong><br />
                 <input class="widefat" id="<?php echo
 $this->get_field_id('title'); ?>" name="<?php echo
 $this->get_field_name('title'); ?>" type="text" value="<?php echo
 $instance['title']; ?>" /><br />
 <?php
         }
 }

 function ceo_widget_do_nothing_register() {
         register_widget('ceo_do_nothing_widget');
 }

 add_action( 'widgets_init', 'ceo_widget_do_nothing_register');
 }}}

 Notice the default value 'dosomething' currently set to true, if you set
 it to false the behavior doesn't happen.

 This *only* happens on the first time adding the widget to the sidebar and
 then clicking update for the widget that it clears the data.   Every
 subsequent time everything's fine.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/24493>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list