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

WordPress Trac noreply at wordpress.org
Sat Jun 23 19:15:25 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 greenshady):

 Replying to [comment:2 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.

 Like I said, it is a janky way to do it.  However, it absolutely does
 work.

 > 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.

 Of course, that puts the onus on theme authors to build a custom system
 rather than having a shared system in WP that everyone can use.  It's
 better for the review team, theme authors, and DIY users to have a
 standard.

 > 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.

 If you have some use cases where there might be side effects, present
 those cases.

 Not sure what you mean by filtering the default twice in the patch.
 There's only a single filter in the patch I put forward.

 The patch works as intended (or it did when I first submitted it).  I
 thoroughly tested it with existing themes.  I've been running my own
 custom `get_theme_mod()` function for years that does the exact same thing
 the proposed patch does.  I think it'd be cool if other theme authors had
 the same feature that I have.

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


More information about the wp-trac mailing list