[wp-trac] [WordPress Trac] #17201: sanitize_title on dynamic_sidebar: performance

WordPress Trac wp-trac at lists.automattic.com
Thu Apr 21 07:48:23 UTC 2011


#17201: sanitize_title on dynamic_sidebar: performance
-------------------------+-----------------------------
 Reporter:  mrubiolvn    |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Widgets      |    Version:  3.1
 Severity:  normal       |   Keywords:
-------------------------+-----------------------------
 I've got a few dynamic sidebars (say 6 or 7) and the dynamic_sidebar
 function spends 1/4 of a second only calling sanitize_title.

 See the piece of code on wp-includes/widgets.php:

 {{{
         if ( is_int($index) ) {
                 $index = "sidebar-$index";
         } else {
                 $index = sanitize_title($index);
                 foreach ( (array) $wp_registered_sidebars as $key =>
 $value ) {
                         if ( sanitize_title($value['name']) == $index ) {
                                 $index = $key;
                                 break;
                         }
                 }
         }
 }}}

 That's occurs evenf if you provide an id, and not the sidebar name.
 We could avoid that by checking before trying to use the sidebar name if a
 sidebar exists with that id.

 Like so...
 {{{
         if ( is_int($index) ) {
                 $index = "sidebar-$index";
         } elseif ( empty($wp_registered_sidebars[$index]) ||
 !array_key_exists($index, $sidebars_widgets) ||
 !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) )
 {
                 $index = sanitize_title($index);
                 foreach ( (array) $wp_registered_sidebars as $key =>
 $value ) {
                         if ( sanitize_title($value['name']) == $index ) {
                                 $index = $key;
                                 break;
                         }
                 }
         }
 }}}

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


More information about the wp-trac mailing list