[wp-trac] [WordPress Trac] #33123: Filter on theme mod default value

WordPress Trac noreply at wordpress.org
Tue Apr 17 22:59:15 UTC 2018


#33123: Filter on theme mod default value
-------------------------+------------------------------
 Reporter:  greenshady   |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Themes       |     Version:  4.3
 Severity:  normal       |  Resolution:
 Keywords:               |     Focuses:
-------------------------+------------------------------

Comment (by joyously):

 The example given is not the only way to filter default values, and it
 wouldn't even work correctly, because the `theme_mod_{$name}` filter is
 applied to both the db value and the default value. That filter is what is
 used by the Customizer to make the temporary changes work for the preview.

 Another way to filter default values is for the theme to provide a single
 function that supplies defaults, and to filter the result so that child
 themes can modify or add defaults. Then the result of that function is
 passed in to the `get_theme_mod()` call. So, the default is filtered
 before the call, not during. This way there is one filter for one
 function, that modifies an array, instead of one filter function for each
 theme mod.

 There is some merit to having a filter for the default value inside the
 `get_theme_mod` function, in order to mirror the way individual options
 have the `default_option_{$option}` filter, but changing the filters in
 there could cause side effects in existing themes. The way the patch is
 filtering the default twice probably won't get the same result.

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


More information about the wp-trac mailing list