[wp-trac] [WordPress Trac] #33292: Never-used widgets generate database queries

WordPress Trac noreply at wordpress.org
Thu Aug 6 17:21:50 UTC 2015


#33292: Never-used widgets generate database queries
--------------------------+-----------------------------
 Reporter:  dlh           |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Widgets       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When `WP_Widget::_register()` runs, it calls `WP_Widget::get_settings()`,
 which then calls `get_option( $this->option_name )`.

 By default, widget options are set to autoload, so the `get_option()` call
 can fetch the loaded value. But a widget that has never been used doesn't
 have an option, so `get_option()` runs all the way through, including the
 database query.

 This can be tested on a fresh install. Each frontend request includes
 `SELECT option_value FROM wp_options WHERE option_name = 'widget_pages'
 LIMIT 1`, but that option doesn't exist (same for `widget_tag_cloud`,
 `widget_calendar`, and `widget_nav_menu`).

 Assuming everything so far is accurate, the attached patch would have
 `get_settings()` call `WP_Widget::save_settings()` with an empty array
 when no option is found in the database and the `alt_option_name` property
 isn't set. On the next request, the widget option would be autoloaded and
 not generate another query.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/33292>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list