[wp-trac] [WordPress Trac] #20249: Remove custom header and background constants

WordPress Trac wp-trac at lists.automattic.com
Fri Mar 16 21:01:09 UTC 2012


#20249: Remove custom header and background constants
--------------------------+-----------------
 Reporter:  nacin         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  3.4
Component:  Themes        |    Version:
 Severity:  normal        |   Keywords:
--------------------------+-----------------
 The custom header and custom background code are both weighed down heavily
 with constants and multiple functions for registering them.

 For example, adding a custom header requires the simple
 add_custom_image_header() call, which takes three callback arguments. But,
 it also requires up to five constants to customize things. Additionally,
 for random default headers, you need to make an add_theme_support() call.
 If you don't want uploads, you need to do remove_theme_support('custom-
 header-uploads'). If you want the new flex-header stuff, they are
 additional arguments in add_theme_support(). If you want to remove
 support, you need to call remove_custom_image_header(), not
 remove_theme_support(). And, if you need to overload certain pieces in a
 child theme, good luck.

 See, that's a lot going on. Let's simplify it.

 A single add_theme_support('custom-header', $args) that handles everything
 except for default header registration. Multiple calls to it will result
 in the existing $args being merged with the newly passed args. So, for
 example, a child theme can remove uploads by simply calling
 add_theme_support('custom-header', array('uploads' => false) ).

 Attached patch kills off the constants, removes extraneous functions, and
 causes everything to just wrap add_theme_support() and
 remove_theme_support().

 It does some very particular things for backwards compatibility, like
 defining constants that aren't already defined, in case a plugin or parent
 theme references them, and to ensure that a child theme consistently
 overrides the wishes of the parent.

 custom-header.php has not been ported over to rely on the new API. As a
 testament for this code's backwards compatibility (or potential thereof,
 in case of a minor bug or two), everything works.

 I am going to try to crowd-source a test of all 90-something themes in
 http://wpcom-themes.svn.automattic.com to ensure full compatibility. (Some
 of the just-in-time stuff was a result of seeing that Twenty Eleven
 defined a header constant *after* add_custom_image_header(), which threw
 me in for a loop.)

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


More information about the wp-trac mailing list