[wp-trac] [WordPress Trac] #54677: Default widgets with alternative option name causing unnecessary database queries

WordPress Trac noreply at wordpress.org
Tue Jul 5 06:16:49 UTC 2022


#54677: Default widgets with alternative option name causing unnecessary database
queries
-------------------------------------+--------------------------
 Reporter:  Chouby                   |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  6.1
Component:  Widgets                  |     Version:  5.8
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:  performance
-------------------------------------+--------------------------

Comment (by peterwilsoncc):

 It looks like [attachment:"54677.patch"] prioritizes
 `$this->alt_option_name` over the current option name
 `$this->option_name`. My reading of the code is that if both options
 exist, then `option_name` is likely to hold the correct data.

 I am still testing but I think `WP_Widget::save_settings()` should remain
 unchanged while `WP_Widget::get_settings()` should start with something
 along the lines of the following code.

 {{{#!php
 <?php
 $settings = get_option( $this->option_name );

 if ( false === $settings ) {
         $settings = array();
         if ( isset( $this->alt_option_name ) ) {
                 // Get from legacy (alternative) option name.
                 $settings = get_option( $this->alt_option_name, array() );

                 // Delete the legacy option as the new option will be
 created.
                 delete_option( $this->alt_option_name );
         }
         // Save an option so it can be autoloaded next time.
         $this->save_settings( $settings );
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54677#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list