[wp-trac] [WordPress Trac] #38866: Custom CSS generates an update SQL query on every front end request

WordPress Trac noreply at wordpress.org
Sat Nov 19 08:26:54 UTC 2016


#38866: Custom CSS generates an update SQL query on every front end request
--------------------------+-----------------------------
 Reporter:  bradyvercher  |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Themes        |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The `wp_get_custom_css_post()` can generate an UPDATE query on every front
 end request in some cases.

 On sites that haven't saved the custom CSS setting in the customizer, a
 `custom_css` CPT won't exist, so that function runs `set_theme_mod(
 'custom_css_post_id', -1 );` on every request. Normally, `update_option()`
 would short circuit the update query if the new value is the same as the
 old, but when a header image is set, it saves an object in the
 `header_image_data` theme mod.

 I didn't dig too deep, but in `update_option()`, the `header_image_data`
 objects have different identifiers, so the strict equality check fails and
 the update goes through.

 Here's a reduced theme mod for the new `$value` in `update_option()`:

 {{{
 array(3) {
   ["custom_css_post_id"]=>
   int(-1)
   ["header_image"]=>
   string(85) "http://src.wordpress-develop.dev/wp-content/uploads/2016/10
 /cropped-Blurry-Lights.jpg"
   ["header_image_data"]=>
   object(stdClass)#370 (5) {
     ["attachment_id"]=>
     int(292)
     ["url"]=>
     string(85) "http://src.wordpress-develop.dev/wp-
 content/uploads/2016/10/cropped-Blurry-Lights.jpg"
     ["thumbnail_url"]=>
     string(85) "http://src.wordpress-develop.dev/wp-
 content/uploads/2016/10/cropped-Blurry-Lights.jpg"
     ["height"]=>
     int(708)
     ["width"]=>
     int(1260)
   }
 }
 }}}


 And the var dump for the `$old_value`:
 {{{
 array(3) {
   ["custom_css_post_id"]=>
   int(-1)
   ["header_image"]=>
   string(85) "http://src.wordpress-develop.dev/wp-content/uploads/2016/10
 /cropped-Blurry-Lights.jpg"
   ["header_image_data"]=>
   object(stdClass)#626 (5) {
     ["attachment_id"]=>
     int(292)
     ["url"]=>
     string(85) "http://src.wordpress-develop.dev/wp-
 content/uploads/2016/10/cropped-Blurry-Lights.jpg"
     ["thumbnail_url"]=>
     string(85) "http://src.wordpress-develop.dev/wp-
 content/uploads/2016/10/cropped-Blurry-Lights.jpg"
     ["height"]=>
     int(708)
     ["width"]=>
     int(1260)
   }
 }
 }}}

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


More information about the wp-trac mailing list