[wp-trac] [WordPress Trac] #33123: Filter on theme mod default value
WordPress Trac
noreply at wordpress.org
Sat Jul 25 15:56:29 UTC 2015
#33123: Filter on theme mod default value
--------------------------+-----------------------------
Reporter: greenshady | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
For those of us using theme mods for storing theme settings, we often need
a method for modifying the default theme mod when building child themes.
For example, I might build a Christmas-styled child theme and modify the
parent theme's default "primary" color to green. The only way this is
possible is if the parent theme does something like this:
{{{
$primary = get_theme_mod( 'color_primary', '' );
add_filter( 'theme_mod_color_primary', 'parent_color_primary', 99 );
function parent_color_primary( $hex ) {
return $hex ? $hex : '#00000';
}
}}}
Then, the Christmas child theme can hook in earlier and modify this if
needing to change the default like so:
{{{
add_filter( 'theme_mod_color_primary', 'child_color_primary', 10 );
function child_color_primary( $hex ) {
return $hex ? $hex : '#cc0000';
}
}}}
That's kind of a janky way to do things. It'd be far easier to have a
filter on the default passed into `get_theme_mod( $mod, $default )`.
Something like:
{{{
$default = apply_filters( "theme_mod_{$mod}_default", $default );
}}}
In this scenario, the parent theme merely needs to do this:
{{{
$primary = get_theme_mod( 'color_primary', '#000000' );
}}}
And, the child theme:
{{{
add_filter( 'theme_mod_color_primary_default', 'child_color_primary' );
function child_color_primary() {
return '#cc0000';
}
}}}
I'm attaching a patch that will provide this filter hook.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33123>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list