change redux default values on child theme
mbtocalli opened this issue · 4 comments
I have a Wordpress install with Redux Framework plugin v.4.4.10. Redux sections and options are set on a redux config file on parent theme.
I also use a child theme, and i would like this child theme sets new defaults for redux options field values. This default values should be set when "Reset All" button from redux panel is clicked.
I'm setting redux with sections and options in parent theme. Each option has a defined "default" value according to the redux sintax:
Redux::set_section( $opt_name, array(
'title' => esc_html__( 'Layout', 'text-domain' ),
'id' => 'global-layout',
'fields' => array(
array(
'id' => 'global-container',
'type' => 'select',
'title' => esc_html__( 'Container', 'text-domain' ),
'subtitle' => esc_html__( 'Choose the container width', 'text-domain' ),
'options' => array(
'container' => esc_html__( 'Boxed', 'text-domain' ),
'container-fluid' => esc_html__( 'Full Width', 'text-domain' ),
),
'default' => 'container',
),
)
)
);
The child theme should have defined different default values. According to Redux documentation, this can be done using Redux API: Updating an Option Manually
In addition, if I want the child theme redux default values get set after clicking on "Reset All" button of Redux theme options panel, I can use the redux hook redux/options/{opt_name}/reset as described in Redux Action Hooks
So, my final code in the functions.php file of my child theme will be:
function child_update_redux_option_manually() {
$opt_name = 'redux_mytheme';
Redux::set_option($opt_name, 'global-container', 'container-fluid');
}
add_action('redux/options/' . $opt_name . '/reset', 'child_update_redux_option_manually');
It is not working. After clicking on "Reset All" button, default values defined in redux config file of parent theme are setted instead of the one defined in the child theme function.
I really appreciate any kind of help on this topic. I couldn't find any updated solution for this on stackoverflow or redux github
Don't use redux/options/{opt_name}/reset
For 'Reset All', use redux/validate/{opt_name}/defaults
For 'Reset Section', use redux/validate/{opt_name}/defaults_section
Those are the two I used with Social Profiles when needed to manipulate data via the reset buttons.
Hi Kevin, thanks a lot for you reply
I used this code on functions.php of my child theme, using the filter hooks you suggested:
function child_update_redux_option_manually() {
$opt_name = 'redux_mytheme';
Redux::set_option($opt_name, 'global-container', 'container-fluid');
}
add_filter('redux/validate/redux_mytheme/defaults', 'child_update_redux_option_manually');
When i click on "Reset All", the 'global-container' field keeps showing the value defined in the parent theme instead of the one defined by Redux::set_option
I'm doing something wrong?
I used the exact same hook in my theme's child theme, and it worked fine.
I couldn't speculate why it's not working in your case, as I do not have access to the parent theme, nor do I know how the original author used Redux. Such a thing does not fall under free support, debugging someone else's code. Sorry.
Kevin, is good to know the code should be working.
I'm on a Wordpress Multisite install, maybe that is affecting somehow. I will try it on a single install environment and will let you know. Thanks for you support, really really appreciate it.