0

In our development process we have several branches of the same theme for each developer. Theme branches live in different directory names, so when doing get_theme_mod(), get_option("stylesheet") can return different values, should we for some reason (customer demo) be forced to activate another theme branch besides "master".

This makes us have to reconfigure menus, widgets, customizer mods etc etc.

In our case, it's very rare that theme mods need to be different across branches, so I would like get_theme_mod() to always access the same mods array.

The obvious solution seems to be making "pre_option_stylesheet" filter as a standard part of the theme codebase, but I am not sure if it may have any unintended side effects. Grepping around, looks like this option is almost exclusively used in a few places in wp-includes/theme.php.

Q: Is "pre_option_stylesheet" filter the way to go here? Or can you think of something else?

1 Answer 1

1

Filter "theme_mod_$name" in a separate plugin:

add_filter( 'theme_mod_very_special', function() {
    return 'forced value';
});

To replace the complete theme mods, filter pre_get_option_theme_mods_$theme_name and return an array. You have to register that filter for each theme name.

3
  • I am not sure I follow. This looks like hardcoding a single value, while I would want to re-use the whole array. Looking at get_theme_mod(), I would rather expect some filter that lets me override $mods in get_theme_mods().
    – lkraav
    Commented May 28, 2013 at 22:16
  • @lkraav See my update.
    – fuxia
    Commented May 28, 2013 at 22:20
  • Hmmm good thinking going a level higher with the pre_get_option filter, not sure why I didn't think of that (answer: past midnight!). I'll put together some example code and let's possibly edit the answer then if you like it.
    – lkraav
    Commented May 28, 2013 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.